Issue #2933924 by lucienchalom, elber, smustgrave, tim.plunkett, larowlan, lauriii: Move \Drupal\field_ui\Form\EntityViewDisplayEditForm::getFieldLabelOptions() to a trait
parent
79c7666a86
commit
4aa426d9cc
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\field;
|
||||
|
||||
/**
|
||||
* Provides a trait for the valid field label options.
|
||||
*/
|
||||
trait FieldLabelOptionsTrait {
|
||||
|
||||
/**
|
||||
* Returns an array of visibility options for field labels.
|
||||
*
|
||||
* @return array
|
||||
* An array of visibility options.
|
||||
*/
|
||||
protected function getFieldLabelOptions(): array {
|
||||
return [
|
||||
'above' => $this->t('Above'),
|
||||
'inline' => $this->t('Inline'),
|
||||
'hidden' => '- ' . $this->t('Hidden') . ' -',
|
||||
'visually_hidden' => '- ' . $this->t('Visually Hidden') . ' -',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\Core\Url;
|
||||
use Drupal\field_ui\FieldUI;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\field\FieldLabelOptionsTrait;
|
||||
|
||||
/**
|
||||
* Edit form for the EntityViewDisplay entity type.
|
||||
|
@ -15,7 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* @internal
|
||||
*/
|
||||
class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
||||
|
||||
use FieldLabelOptionsTrait;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -147,21 +148,6 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of visibility options for field labels.
|
||||
*
|
||||
* @return array
|
||||
* An array of visibility options.
|
||||
*/
|
||||
protected function getFieldLabelOptions() {
|
||||
return [
|
||||
'above' => $this->t('Above'),
|
||||
'inline' => $this->t('Inline'),
|
||||
'hidden' => '- ' . $this->t('Hidden') . ' -',
|
||||
'visually_hidden' => '- ' . $this->t('Visually Hidden') . ' -',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,7 @@ use Drupal\Core\Session\AccountInterface;
|
|||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\field\FieldLabelOptionsTrait;
|
||||
|
||||
/**
|
||||
* Provides a block that renders a field from an entity.
|
||||
|
@ -37,6 +38,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*/
|
||||
class FieldBlock extends BlockBase implements ContextAwarePluginInterface, ContainerFactoryPluginInterface {
|
||||
|
||||
use FieldLabelOptionsTrait;
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
|
@ -251,15 +253,7 @@ class FieldBlock extends BlockBase implements ContextAwarePluginInterface, Conta
|
|||
$form['formatter']['label'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Label'),
|
||||
// @todo This is directly copied from
|
||||
// \Drupal\field_ui\Form\EntityViewDisplayEditForm::getFieldLabelOptions(),
|
||||
// resolve this in https://www.drupal.org/project/drupal/issues/2933924.
|
||||
'#options' => [
|
||||
'above' => $this->t('Above'),
|
||||
'inline' => $this->t('Inline'),
|
||||
'hidden' => '- ' . $this->t('Hidden') . ' -',
|
||||
'visually_hidden' => '- ' . $this->t('Visually Hidden') . ' -',
|
||||
],
|
||||
'#options' => $this->getFieldLabelOptions(),
|
||||
'#default_value' => $config['formatter']['label'],
|
||||
];
|
||||
|
||||
|
|
Loading…
Reference in New Issue