diff --git a/core/modules/field_ui/src/ConfigTranslation/EntityDisplaySubscriber.php b/core/modules/field_ui/src/ConfigTranslation/EntityDisplaySubscriber.php new file mode 100644 index 0000000..1b4c737 --- /dev/null +++ b/core/modules/field_ui/src/ConfigTranslation/EntityDisplaySubscriber.php @@ -0,0 +1,94 @@ +configFactory = $config_factory; + } + + /** + * Reacts to the population of a configuration mapper. + * + * @param \Drupal\config_translation\Event\ConfigMapperPopulateEvent $event + * The configuration mapper event. + * + * @see \Drupal\field_ui\Routing\RouteSubscriber::alterRoutes() + */ + public function onMapperPopulate(ConfigMapperPopulateEvent $event) { + $mapper = $event->getMapper(); + $base_route = $mapper->getBaseRoute(); + + if ( + !($mapper instanceof ConfigEntityMapper) || + !($entity_type_id = $base_route->getOption('_field_ui_base_route_for')) + ) { + return; + } + $entity = $mapper->getEntity(); + + // Determine the bundle (if any) of the route. + $bundle = NULL; + if ($entity_type_id === $entity->getEntityType()->getBundleOf()) { + // Here, $entity is an extension of + // \Drupal\Core\Config\Entity\ConfigEntityBundleBase, + // so the entity's ID is a bundle name. + $bundle = $entity->id(); + } + elseif ($base_route->getDefault('bundle')) { + $bundle = $base_route->getDefault('bundle'); + } + + // Add all form and view displays of the respective entity type and bundle + // (if any) to the mapper. + foreach (['entity_form_display', 'entity_view_display'] as $display_type) { + $prefix = "core.$display_type.$entity_type_id."; + if ($bundle) { + $prefix .= "$bundle."; + } + + $config_names = $this->configFactory->listAll($prefix); + foreach ($config_names as $config_name) { + $mapper->addConfigName($config_name); + } + } + + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + return [ConfigTranslationEvents::POPULATE_MAPPER => 'onMapperPopulate']; + } + +} diff --git a/core/modules/field_ui/src/FieldUiServiceProvider.php b/core/modules/field_ui/src/FieldUiServiceProvider.php new file mode 100644 index 0000000..361b8da --- /dev/null +++ b/core/modules/field_ui/src/FieldUiServiceProvider.php @@ -0,0 +1,33 @@ +getParameter('container.modules'); + + // Subscribe to config_translation's event if it's enabled. + if (isset($modules['config_translation']) ) { + $container->register('field_ui.config_translation_subscriber', '\Drupal\field_ui\ConfigTranslation\EntityDisplaySubscriber') + ->addArgument(new Reference('config.factory')) + ->addTag('event_subscriber'); + } + } + +} diff --git a/core/modules/field_ui/src/Routing/RouteSubscriber.php b/core/modules/field_ui/src/Routing/RouteSubscriber.php index 8f1b8f1..8fce3ba 100644 --- a/core/modules/field_ui/src/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/src/Routing/RouteSubscriber.php @@ -48,12 +48,23 @@ protected function alterRoutes(RouteCollection $collection) { $path = $entity_route->getPath(); $options = $entity_route->getOptions(); + + // Set a route option to easily identify all Field UI base routes and to + // determine the entity type the route is for. + $entity_route->setOption('_field_ui_base_route_for', $entity_type_id); + // RouteCollection::add() overwrites exiting routes with the same name. + $collection->add($route_name, $entity_route); + if ($bundle_entity_type = $entity_type->getBundleEntityType()) { $options['parameters'][$bundle_entity_type] = array( 'type' => 'entity:' . $bundle_entity_type, ); } - // Special parameter used to easily recognize all Field UI routes. + // Set a route option to easily identify all Field UI routes and to + // determine the entity type the routes are for. + $options['_field_ui_route_for'] = $entity_type_id; + // This is retained for backwards-compatibility. + // @todo Remove in Drupal 9 $options['_field_ui'] = TRUE; $defaults = array(