class FieldConfigListBuilder in Drupal 8
Same name and namespace in other branches
- 9 core/modules/field_ui/src/FieldConfigListBuilder.php \Drupal\field_ui\FieldConfigListBuilder
 
Provides lists of field config entities.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
- class \Drupal\Core\Config\Entity\ConfigEntityListBuilder
- class \Drupal\field_ui\FieldConfigListBuilder uses DeprecatedServicePropertyTrait
 
 
 - class \Drupal\Core\Config\Entity\ConfigEntityListBuilder
 
 - class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
 
Expanded class hierarchy of FieldConfigListBuilder
File
- core/
modules/ field_ui/ src/ FieldConfigListBuilder.php, line 20  
Namespace
Drupal\field_uiView source
class FieldConfigListBuilder extends ConfigEntityListBuilder {
  use DeprecatedServicePropertyTrait;
  /**
   * {@inheritdoc}
   */
  protected $deprecatedProperties = [
    'entityManager' => 'entity.manager',
  ];
  /**
   * The name of the entity type the listed fields are attached to.
   *
   * @var string
   */
  protected $targetEntityTypeId;
  /**
   * The name of the bundle the listed fields are attached to.
   *
   * @var string
   */
  protected $targetBundle;
  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;
  /**
   * The field type plugin manager.
   *
   * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
   */
  protected $fieldTypeManager;
  /**
   * The entity field manager.
   *
   * @var \Drupal\Core\Entity\EntityFieldManagerInterface
   */
  protected $entityFieldManager;
  /**
   * Constructs a new class instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
   *   The field type manager.
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface|null $entity_field_manager
   *   The entity field manager.
   */
  public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, FieldTypePluginManagerInterface $field_type_manager, EntityFieldManagerInterface $entity_field_manager = NULL) {
    parent::__construct($entity_type, $entity_type_manager
      ->getStorage($entity_type
      ->id()));
    $this->entityTypeManager = $entity_type_manager;
    $this->fieldTypeManager = $field_type_manager;
    if (!$entity_field_manager) {
      @trigger_error('Calling FieldConfigListBuilder::__construct() with the $entity_field_manager argument is supported in Drupal 8.7.0 and will be required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
      $entity_field_manager = \Drupal::service('entity_field.manager');
    }
    $this->entityFieldManager = $entity_field_manager;
  }
  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    return new static($entity_type, $container
      ->get('entity_type.manager'), $container
      ->get('plugin.manager.field.field_type'), $container
      ->get('entity_field.manager'));
  }
  /**
   * {@inheritdoc}
   */
  public function render($target_entity_type_id = NULL, $target_bundle = NULL) {
    $this->targetEntityTypeId = $target_entity_type_id;
    $this->targetBundle = $target_bundle;
    $build = parent::render();
    $build['table']['#attributes']['id'] = 'field-overview';
    $build['table']['#empty'] = $this
      ->t('No fields are present yet.');
    return $build;
  }
  /**
   * {@inheritdoc}
   */
  public function load() {
    $entities = array_filter($this->entityFieldManager
      ->getFieldDefinitions($this->targetEntityTypeId, $this->targetBundle), function ($field_definition) {
      return $field_definition instanceof FieldConfigInterface;
    });
    // Sort the entities using the entity class's sort() method.
    // See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
    uasort($entities, [
      $this->entityType
        ->getClass(),
      'sort',
    ]);
    return $entities;
  }
  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header = [
      'label' => $this
        ->t('Label'),
      'field_name' => [
        'data' => $this
          ->t('Machine name'),
        'class' => [
          RESPONSIVE_PRIORITY_MEDIUM,
        ],
      ],
      'field_type' => $this
        ->t('Field type'),
    ];
    return $header + parent::buildHeader();
  }
  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $field_config) {
    /** @var \Drupal\field\FieldConfigInterface $field_config */
    $field_storage = $field_config
      ->getFieldStorageDefinition();
    $route_parameters = [
      'field_config' => $field_config
        ->id(),
    ] + FieldUI::getRouteBundleParameter($this->entityTypeManager
      ->getDefinition($this->targetEntityTypeId), $this->targetBundle);
    $row = [
      'id' => Html::getClass($field_config
        ->getName()),
      'data' => [
        'label' => $field_config
          ->getLabel(),
        'field_name' => $field_config
          ->getName(),
        'field_type' => [
          'data' => [
            '#type' => 'link',
            '#title' => $this->fieldTypeManager
              ->getDefinitions()[$field_storage
              ->getType()]['label'],
            '#url' => Url::fromRoute("entity.field_config.{$this->targetEntityTypeId}_storage_edit_form", $route_parameters),
            '#options' => [
              'attributes' => [
                'title' => $this
                  ->t('Edit field settings.'),
              ],
            ],
          ],
        ],
      ],
    ];
    // Add the operations.
    $row['data'] = $row['data'] + parent::buildRow($field_config);
    if ($field_storage
      ->isLocked()) {
      $row['data']['operations'] = [
        'data' => [
          '#markup' => $this
            ->t('Locked'),
        ],
      ];
      $row['class'][] = 'menu-disabled';
    }
    return $row;
  }
  /**
   * {@inheritdoc}
   */
  public function getDefaultOperations(EntityInterface $entity) {
    /** @var \Drupal\field\FieldConfigInterface $entity */
    $operations = parent::getDefaultOperations($entity);
    if ($entity
      ->access('update') && $entity
      ->hasLinkTemplate("{$entity->getTargetEntityTypeId()}-field-edit-form")) {
      $operations['edit'] = [
        'title' => $this
          ->t('Edit'),
        'weight' => 10,
        'url' => $entity
          ->toUrl("{$entity->getTargetEntityTypeId()}-field-edit-form"),
        'attributes' => [
          'title' => $this
            ->t('Edit field settings.'),
        ],
      ];
    }
    if ($entity
      ->access('delete') && $entity
      ->hasLinkTemplate("{$entity->getTargetEntityTypeId()}-field-delete-form")) {
      $operations['delete'] = [
        'title' => $this
          ->t('Delete'),
        'weight' => 100,
        'url' => $entity
          ->toUrl("{$entity->getTargetEntityTypeId()}-field-delete-form"),
        'attributes' => [
          'title' => $this
            ->t('Delete field.'),
        ],
      ];
    }
    $operations['storage-settings'] = [
      'title' => $this
        ->t('Storage settings'),
      'weight' => 20,
      'attributes' => [
        'title' => $this
          ->t('Edit storage settings.'),
      ],
      'url' => $entity
        ->toUrl("{$entity->getTargetEntityTypeId()}-storage-edit-form"),
    ];
    return $operations;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of entity type IDs keyed by the property name of their storages. | |
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of service IDs keyed by property name used for serialization. | |
| 
            DependencySerializationTrait:: | 
                  public | function | 1 | |
| 
            DependencySerializationTrait:: | 
                  public | function | 2 | |
| 
            DeprecatedServicePropertyTrait:: | 
                  public | function | Allows to access deprecated/removed properties. | |
| 
            EntityHandlerBase:: | 
                  protected | property | The module handler to invoke hooks on. | 2 | 
| 
            EntityHandlerBase:: | 
                  protected | function | Gets the module handler. | 2 | 
| 
            EntityHandlerBase:: | 
                  public | function | Sets the module handler for this handler. | |
| 
            EntityListBuilder:: | 
                  protected | property | Information about the entity type. | |
| 
            EntityListBuilder:: | 
                  protected | property | The entity type ID. | |
| 
            EntityListBuilder:: | 
                  protected | property | The number of entities to list per page, or FALSE to list all entities. | 3 | 
| 
            EntityListBuilder:: | 
                  protected | property | The entity storage class. | 1 | 
| 
            EntityListBuilder:: | 
                  public | function | Builds a renderable list of operation links for the entity. | 2 | 
| 
            EntityListBuilder:: | 
                  protected | function | Ensures that a destination is present on the given URL. | |
| 
            EntityListBuilder:: | 
                  protected | function | Loads entity IDs using a pager sorted by the entity id. | 4 | 
| 
            EntityListBuilder:: | 
                  protected | function | Gets the label of an entity. | |
| 
            EntityListBuilder:: | 
                  public | function | 
            Provides an array of information to build a list of operation links. Overrides EntityListBuilderInterface:: | 
                  2 | 
| 
            EntityListBuilder:: | 
                  public | function | 
            Gets the entity storage. Overrides EntityListBuilderInterface:: | 
                  |
| 
            EntityListBuilder:: | 
                  protected | function | Gets the title of the page. | 1 | 
| 
            FieldConfigListBuilder:: | 
                  protected | property | ||
| 
            FieldConfigListBuilder:: | 
                  protected | property | The entity field manager. | |
| 
            FieldConfigListBuilder:: | 
                  protected | property | The entity type manager. | |
| 
            FieldConfigListBuilder:: | 
                  protected | property | The field type plugin manager. | |
| 
            FieldConfigListBuilder:: | 
                  protected | property | The name of the bundle the listed fields are attached to. | |
| 
            FieldConfigListBuilder:: | 
                  protected | property | The name of the entity type the listed fields are attached to. | |
| 
            FieldConfigListBuilder:: | 
                  public | function | 
            Builds the header row for the entity listing. Overrides EntityListBuilder:: | 
                  |
| 
            FieldConfigListBuilder:: | 
                  public | function | 
            Builds a row for an entity in the entity listing. Overrides EntityListBuilder:: | 
                  |
| 
            FieldConfigListBuilder:: | 
                  public static | function | 
            Instantiates a new instance of this entity handler. Overrides EntityListBuilder:: | 
                  |
| 
            FieldConfigListBuilder:: | 
                  public | function | 
            Gets this list's default operations. Overrides ConfigEntityListBuilder:: | 
                  |
| 
            FieldConfigListBuilder:: | 
                  public | function | 
            Loads entities of this type from storage for listing. Overrides ConfigEntityListBuilder:: | 
                  |
| 
            FieldConfigListBuilder:: | 
                  public | function | 
            Builds the entity listing as renderable array for table.html.twig. Overrides EntityListBuilder:: | 
                  |
| 
            FieldConfigListBuilder:: | 
                  public | function | 
            Constructs a new class instance. Overrides EntityListBuilder:: | 
                  |
| 
            MessengerTrait:: | 
                  protected | property | The messenger. | 29 | 
| 
            MessengerTrait:: | 
                  public | function | Gets the messenger. | 29 | 
| 
            MessengerTrait:: | 
                  public | function | Sets the messenger. | |
| 
            RedirectDestinationTrait:: | 
                  protected | property | The redirect destination service. | 1 | 
| 
            RedirectDestinationTrait:: | 
                  protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
| 
            RedirectDestinationTrait:: | 
                  protected | function | Returns the redirect destination service. | |
| 
            RedirectDestinationTrait:: | 
                  public | function | Sets the redirect destination service. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. |