annotate core/modules/config_translation/src/ConfigFieldMapper.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\config_translation;
Chris@0 4
Chris@0 5 use Drupal\Core\Config\Entity\ConfigEntityInterface;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Configuration mapper for fields.
Chris@0 9 *
Chris@0 10 * On top of plugin definition values on ConfigEntityMapper, the plugin
Chris@0 11 * definition for field mappers are required to contain the following
Chris@0 12 * additional keys:
Chris@0 13 * - base_entity_type: The name of the entity type the fields are attached to.
Chris@0 14 */
Chris@0 15 class ConfigFieldMapper extends ConfigEntityMapper {
Chris@0 16
Chris@0 17 /**
Chris@0 18 * Loaded entity instance to help produce the translation interface.
Chris@0 19 *
Chris@0 20 * @var \Drupal\field\FieldConfigInterface
Chris@0 21 */
Chris@0 22 protected $entity;
Chris@0 23
Chris@0 24 /**
Chris@0 25 * {@inheritdoc}
Chris@0 26 */
Chris@0 27 public function getBaseRouteParameters() {
Chris@0 28 $parameters = parent::getBaseRouteParameters();
Chris@18 29 $base_entity_info = $this->entityTypeManager->getDefinition($this->pluginDefinition['base_entity_type']);
Chris@0 30 $bundle_parameter_key = $base_entity_info->getBundleEntityType() ?: 'bundle';
Chris@0 31 $parameters[$bundle_parameter_key] = $this->entity->getTargetBundle();
Chris@0 32 return $parameters;
Chris@0 33 }
Chris@0 34
Chris@0 35 /**
Chris@0 36 * {@inheritdoc}
Chris@0 37 */
Chris@0 38 public function getOverviewRouteName() {
Chris@0 39 return 'entity.field_config.config_translation_overview.' . $this->pluginDefinition['base_entity_type'];
Chris@0 40 }
Chris@0 41
Chris@0 42 /**
Chris@0 43 * {@inheritdoc}
Chris@0 44 */
Chris@0 45 public function getTypeLabel() {
Chris@18 46 $base_entity_info = $this->entityTypeManager->getDefinition($this->pluginDefinition['base_entity_type']);
Chris@0 47 return $this->t('@label fields', ['@label' => $base_entity_info->getLabel()]);
Chris@0 48 }
Chris@0 49
Chris@0 50 /**
Chris@0 51 * {@inheritdoc}
Chris@0 52 */
Chris@0 53 public function setEntity(ConfigEntityInterface $entity) {
Chris@0 54 if (parent::setEntity($entity)) {
Chris@0 55
Chris@0 56 // Field storage config can also contain translatable values. Add the name
Chris@0 57 // of the config as well to the list of configs for this entity.
Chris@0 58 /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
Chris@0 59 $field_storage = $this->entity->getFieldStorageDefinition();
Chris@0 60 /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type_info */
Chris@18 61 $entity_type_info = $this->entityTypeManager->getDefinition($field_storage->getEntityTypeId());
Chris@0 62 $this->addConfigName($entity_type_info->getConfigPrefix() . '.' . $field_storage->id());
Chris@0 63 return TRUE;
Chris@0 64 }
Chris@0 65 return FALSE;
Chris@0 66 }
Chris@0 67
Chris@0 68 }