3870131414a1aa9968127b7ee4bf2838f948b263
[yaffs-website] / web / core / modules / config_translation / src / Controller / ConfigTranslationListController.php
1 <?php
2
3 namespace Drupal\config_translation\Controller;
4
5 use Drupal\config_translation\ConfigMapperManagerInterface;
6 use Drupal\Core\Controller\ControllerBase;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
10 /**
11  * Defines the configuration translation list controller.
12  */
13 class ConfigTranslationListController extends ControllerBase {
14
15   /**
16    * The mapper manager.
17    *
18    * @var \Drupal\config_translation\ConfigMapperManagerInterface
19    */
20   protected $mapperManager;
21
22   /**
23    * Constructs a new ConfigTranslationListController object.
24    *
25    * @param \Drupal\config_translation\ConfigMapperManagerInterface $mapper_manager
26    *   The config mapper manager.
27    */
28   public function __construct(ConfigMapperManagerInterface $mapper_manager) {
29     $this->mapperManager = $mapper_manager;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public static function create(ContainerInterface $container) {
36     return new static(
37       $container->get('plugin.manager.config_translation.mapper')
38     );
39   }
40
41   /**
42    * Provides the listing page for any entity type.
43    *
44    * @param string $mapper_id
45    *   The name of the mapper.
46    *
47    * @return array
48    *   A render array as expected by
49    *   \Drupal\Core\Render\RendererInterface::render().
50    *
51    * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
52    *   Throws an exception if a mapper plugin could not be instantiated from the
53    *   mapper definition in the constructor.
54    */
55   public function listing($mapper_id) {
56     $mapper_definition = $this->mapperManager->getDefinition($mapper_id);
57     $mapper = $this->mapperManager->createInstance($mapper_id, $mapper_definition);
58     if (!$mapper) {
59       throw new NotFoundHttpException();
60     }
61     $entity_type = $mapper->getType();
62     // If the mapper, for example the mapper for fields, has a custom list
63     // controller defined, use it. Other mappers, for examples the ones for
64     // node_type and block, fallback to the generic configuration translation
65     // list controller.
66     $build = $this->entityManager()
67       ->getHandler($entity_type, 'config_translation_list')
68       ->setMapperDefinition($mapper_definition)
69       ->render();
70     $build['#title'] = $mapper->getTypeLabel();
71     return $build;
72   }
73
74 }