comparison core/modules/config_translation/src/ConfigFieldMapper.php @ 0:4c8ae668cc8c

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