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\Core\Url;
|
||||||
use Drupal\field_ui\FieldUI;
|
use Drupal\field_ui\FieldUI;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Drupal\field\FieldLabelOptionsTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit form for the EntityViewDisplay entity type.
|
* Edit form for the EntityViewDisplay entity type.
|
||||||
|
@ -15,7 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
||||||
|
use FieldLabelOptionsTrait;
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -147,21 +148,6 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
||||||
] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle()));
|
] + 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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -23,6 +23,7 @@ use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Drupal\field\FieldLabelOptionsTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a block that renders a field from an entity.
|
* 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 {
|
class FieldBlock extends BlockBase implements ContextAwarePluginInterface, ContainerFactoryPluginInterface {
|
||||||
|
|
||||||
|
use FieldLabelOptionsTrait;
|
||||||
/**
|
/**
|
||||||
* The entity field manager.
|
* The entity field manager.
|
||||||
*
|
*
|
||||||
|
@ -251,15 +253,7 @@ class FieldBlock extends BlockBase implements ContextAwarePluginInterface, Conta
|
||||||
$form['formatter']['label'] = [
|
$form['formatter']['label'] = [
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
'#title' => $this->t('Label'),
|
'#title' => $this->t('Label'),
|
||||||
// @todo This is directly copied from
|
'#options' => $this->getFieldLabelOptions(),
|
||||||
// \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') . ' -',
|
|
||||||
],
|
|
||||||
'#default_value' => $config['formatter']['label'],
|
'#default_value' => $config['formatter']['label'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue