class ConfigTranslationFieldListBuilder in Drupal 8
Same name and namespace in other branches
- 9 core/modules/config_translation/src/Controller/ConfigTranslationFieldListBuilder.php \Drupal\config_translation\Controller\ConfigTranslationFieldListBuilder
Defines the config translation list builder for field 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\config_translation\Controller\ConfigTranslationEntityListBuilder implements ConfigTranslationEntityListBuilderInterface
- class \Drupal\config_translation\Controller\ConfigTranslationFieldListBuilder uses DeprecatedServicePropertyTrait
- class \Drupal\config_translation\Controller\ConfigTranslationEntityListBuilder implements ConfigTranslationEntityListBuilderInterface
- class \Drupal\Core\Config\Entity\ConfigEntityListBuilder
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
Expanded class hierarchy of ConfigTranslationFieldListBuilder
File
- core/
modules/ config_translation/ src/ Controller/ ConfigTranslationFieldListBuilder.php, line 16
Namespace
Drupal\config_translation\ControllerView source
class ConfigTranslationFieldListBuilder extends ConfigTranslationEntityListBuilder {
use DeprecatedServicePropertyTrait;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
/**
* The name of the entity type the fields are attached to.
*
* @var string
*/
protected $baseEntityType = '';
/**
* An array containing the base entity type's definition.
*
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $baseEntityInfo;
/**
* The bundle info for the base entity type.
*
* @var array
*/
protected $baseEntityBundles = [];
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
$entity_type_manager = $container
->get('entity_type.manager');
$entity_type_bundle_info = $container
->get('entity_type.bundle.info');
return new static($entity_type, $entity_type_manager
->getStorage($entity_type
->id()), $entity_type_manager, $entity_type_bundle_info);
}
/**
* Constructs a new ConfigTranslationFieldListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL) {
parent::__construct($entity_type, $storage);
$this->entityTypeManager = $entity_type_manager;
if (!$entity_type_bundle_info) {
@trigger_error('Calling ConfigTranslationFieldListBuilder::__construct() with the $entity_type_bundle_info 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_type_bundle_info = \Drupal::service('entity_type.bundle.info');
}
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
* {@inheritdoc}
*/
public function setMapperDefinition($mapper_definition) {
$this->baseEntityType = $mapper_definition['base_entity_type'];
$this->baseEntityInfo = $this->entityTypeManager
->getDefinition($this->baseEntityType);
$this->baseEntityBundles = $this->entityTypeBundleInfo
->getBundleInfo($this->baseEntityType);
return $this;
}
/**
* {@inheritdoc}
*/
public function load() {
// It is not possible to use the standard load method, because this needs
// all field entities only for the given baseEntityType.
$ids = \Drupal::entityQuery('field_config')
->condition('id', $this->baseEntityType . '.', 'STARTS_WITH')
->execute();
return $this->storage
->loadMultiple($ids);
}
/**
* {@inheritdoc}
*/
public function getFilterLabels() {
$info = parent::getFilterLabels();
$bundle = $this->baseEntityInfo
->getBundleLabel() ?: $this
->t('Bundle');
$bundle = mb_strtolower($bundle);
$info['placeholder'] = $this
->t('Enter field or @bundle', [
'@bundle' => $bundle,
]);
$info['description'] = $this
->t('Enter a part of the field or @bundle to filter by.', [
'@bundle' => $bundle,
]);
return $info;
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = [
'data' => $entity
->label(),
'class' => 'table-filter-text-source',
];
if ($this
->displayBundle()) {
$bundle = $entity
->get('bundle');
$row['bundle'] = [
'data' => $this->baseEntityBundles[$bundle]['label'],
'class' => 'table-filter-text-source',
];
}
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this
->t('Field');
if ($this
->displayBundle()) {
$header['bundle'] = $this->baseEntityInfo
->getBundleLabel() ?: $this
->t('Bundle');
}
return $header + parent::buildHeader();
}
/**
* Controls the visibility of the bundle column on field list pages.
*
* @return bool
* Whenever the bundle is displayed or not.
*/
public function displayBundle() {
// The bundle key is explicitly defined in the entity definition.
if ($this->baseEntityInfo
->getKey('bundle')) {
return TRUE;
}
// There is more than one bundle defined.
if (count($this->baseEntityBundles) > 1) {
return TRUE;
}
// The defined bundle ones not match the entity type name.
if (!empty($this->baseEntityBundles) && !isset($this->baseEntityBundles[$this->baseEntityType])) {
return TRUE;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function sortRows($a, $b) {
return $this
->sortRowsMultiple($a, $b, [
'bundle',
'label',
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEntityListBuilder:: |
public | function |
Gets this list's default operations. Overrides EntityListBuilder:: |
15 |
ConfigTranslationEntityListBuilder:: |
public | function |
Provides an array of information to build a list of operation links. Overrides EntityListBuilder:: |
|
ConfigTranslationEntityListBuilder:: |
public | function |
Builds a listing of entities for the given entity type. Overrides EntityListBuilder:: |
|
ConfigTranslationEntityListBuilder:: |
protected | function | Sorts an array by multiple criteria. | |
ConfigTranslationFieldListBuilder:: |
protected | property | The bundle info for the base entity type. | |
ConfigTranslationFieldListBuilder:: |
protected | property | An array containing the base entity type's definition. | |
ConfigTranslationFieldListBuilder:: |
protected | property | The name of the entity type the fields are attached to. | |
ConfigTranslationFieldListBuilder:: |
protected | property | ||
ConfigTranslationFieldListBuilder:: |
protected | property | The entity bundle info. | |
ConfigTranslationFieldListBuilder:: |
protected | property | The entity type manager. | |
ConfigTranslationFieldListBuilder:: |
public | function |
Builds the header row for the entity listing. Overrides ConfigTranslationEntityListBuilder:: |
|
ConfigTranslationFieldListBuilder:: |
public | function |
Builds a row for an entity in the entity listing. Overrides ConfigTranslationEntityListBuilder:: |
|
ConfigTranslationFieldListBuilder:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityListBuilder:: |
|
ConfigTranslationFieldListBuilder:: |
public | function | Controls the visibility of the bundle column on field list pages. | |
ConfigTranslationFieldListBuilder:: |
public | function |
Provides user facing strings for the filter element. Overrides ConfigTranslationEntityListBuilder:: |
|
ConfigTranslationFieldListBuilder:: |
public | function |
Loads entities of this type from storage for listing. Overrides ConfigEntityListBuilder:: |
|
ConfigTranslationFieldListBuilder:: |
public | function |
Sets the config translation mapper definition. Overrides ConfigTranslationEntityListBuilder:: |
|
ConfigTranslationFieldListBuilder:: |
public | function |
Sorts an array by value. Overrides ConfigTranslationEntityListBuilder:: |
|
ConfigTranslationFieldListBuilder:: |
public | function |
Constructs a new ConfigTranslationFieldListBuilder object. Overrides EntityListBuilder:: |
|
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 |
Gets the entity storage. Overrides EntityListBuilderInterface:: |
|
EntityListBuilder:: |
protected | function | Gets the title of the page. | 1 |
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. |