3 namespace Drupal\config_translation\Controller;
5 use Drupal\config_translation\ConfigMapperInterface;
6 use Drupal\Core\Controller\ControllerBase;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
10 * Defines the configuration translation mapper list.
12 * Groups all defined configuration mapper instances by weight.
14 class ConfigTranslationMapperList extends ControllerBase {
17 * A array of configuration mapper instances.
19 * @var \Drupal\config_translation\ConfigMapperInterface[]
24 * Constructs a new ConfigTranslationMapperList object.
26 * @param \Drupal\config_translation\ConfigMapperInterface[] $mappers
27 * The configuration mapper manager.
29 public function __construct(array $mappers) {
30 $this->mappers = $mappers;
36 public static function create(ContainerInterface $container) {
38 $container->get('plugin.manager.config_translation.mapper')->getMappers()
43 * Builds the mappers as a renderable array for table.html.twig.
46 * Renderable array with config translation mappers.
48 public function render() {
51 '#header' => $this->buildHeader(),
57 foreach ($this->mappers as $mapper) {
58 if ($row = $this->buildRow($mapper)) {
59 $mappers[$mapper->getWeight()][] = $row;
63 // Group by mapper weight and sort by label.
65 foreach ($mappers as $weight => $mapper) {
66 usort($mapper, function ($a, $b) {
67 $a_title = (isset($a['label'])) ? $a['label'] : '';
68 $b_title = (isset($b['label'])) ? $b['label'] : '';
69 return strnatcasecmp($a_title, $b_title);
71 $mappers[$weight] = $mapper;
74 foreach ($mappers as $mapper) {
75 $build['#rows'] = array_merge($build['#rows'], $mapper);
82 * Builds a row for a mapper in the mapper listing.
84 * @param \Drupal\config_translation\ConfigMapperInterface $mapper
88 * A render array structure of fields for this mapper.
90 public function buildRow(ConfigMapperInterface $mapper) {
91 $row['label'] = $mapper->getTypeLabel();
92 $row['operations']['data'] = $this->buildOperations($mapper);
97 * Builds the header row for the mapper listing.
100 * A render array structure of header strings.
102 public function buildHeader() {
103 $row['Label'] = $this->t('Label');
104 $row['operations'] = $this->t('Operations');
109 * Builds a renderable list of operation links for the entity.
111 * @param \Drupal\config_translation\ConfigMapperInterface $mapper
115 * A renderable array of operation links.
117 * @see \Drupal\Core\Entity\EntityList::buildOperations()
119 protected function buildOperations(ConfigMapperInterface $mapper) {
120 // Retrieve and sort operations.
121 $operations = $mapper->getOperations();
122 uasort($operations, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
124 '#type' => 'operations',
125 '#links' => $operations,