You are here

public function ConfigTranslationMapperList::render in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/config_translation/src/Controller/ConfigTranslationMapperList.php \Drupal\config_translation\Controller\ConfigTranslationMapperList::render()

Builds the mappers as a renderable array for table.html.twig.

Return value

array Renderable array with config translation mappers.

1 string reference to 'ConfigTranslationMapperList::render'
config_translation.routing.yml in core/modules/config_translation/config_translation.routing.yml
core/modules/config_translation/config_translation.routing.yml

File

core/modules/config_translation/src/Controller/ConfigTranslationMapperList.php, line 48

Class

ConfigTranslationMapperList
Defines the configuration translation mapper list.

Namespace

Drupal\config_translation\Controller

Code

public function render() {
  $build = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#rows' => [],
  ];
  $mappers = [];
  foreach ($this->mappers as $mapper) {
    if ($row = $this
      ->buildRow($mapper)) {
      $mappers[$mapper
        ->getWeight()][] = $row;
    }
  }

  // Group by mapper weight and sort by label.
  ksort($mappers);
  foreach ($mappers as $weight => $mapper) {
    usort($mapper, function ($a, $b) {
      $a_title = isset($a['label']) ? $a['label'] : '';
      $b_title = isset($b['label']) ? $b['label'] : '';
      return strnatcasecmp($a_title, $b_title);
    });
    $mappers[$weight] = $mapper;
  }
  foreach ($mappers as $mapper) {
    $build['#rows'] = array_merge($build['#rows'], $mapper);
  }
  return $build;
}