You are here

public function SynonymConfigController::overview in Synonyms 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/SynonymConfigController.php \Drupal\synonyms\Controller\SynonymConfigController::overview()

Routing callback: show overview table of synonyms configuration.

1 string reference to 'SynonymConfigController::overview'
synonyms.routing.yml in ./synonyms.routing.yml
synonyms.routing.yml

File

src/Controller/SynonymConfigController.php, line 55

Class

SynonymConfigController
Controller for admin UI of the module.

Namespace

Drupal\synonyms\Controller

Code

public function overview() {
  $render = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Entity type'),
      $this
        ->t('Bundle'),
      $this
        ->t('Manage'),
    ],
  ];
  foreach ($this
    ->entityTypeManager()
    ->getDefinitions() as $entity_type) {
    if ($entity_type instanceof ContentEntityTypeInterface) {
      foreach ($this->entityTypeBundleInfo
        ->getBundleInfo($entity_type
        ->id()) as $bundle => $bundle_info) {
        $links = [];
        foreach ($this->behaviorService
          ->getBehaviorServices() as $service_id => $service) {
          $count = count($this->behaviorService
            ->getSynonymConfigEntities($service_id, $entity_type
            ->id(), $bundle));
          if ($count > 0) {
            $title = $this
              ->t('@behavior (@count)', [
              '@behavior' => $service['service']
                ->getTitle(),
              '@count' => $count,
            ]);
          }
          else {
            $title = $service['service']
              ->getTitle();
          }
          $links[$service_id] = [
            'title' => $title,
            'url' => Url::fromRoute('entity.synonym.overview.entity_type.bundle.behavior', [
              'synonyms_entity_type' => $entity_type
                ->id(),
              'bundle' => $bundle,
              'synonyms_behavior_service' => $service_id,
            ]),
          ];
        }
        $render[] = [
          [
            '#markup' => Html::escape($entity_type
              ->getLabel()),
          ],
          [
            '#markup' => $bundle == $entity_type
              ->id() ? '' : Html::escape($bundle_info['label']),
          ],
          [
            '#type' => 'operations',
            '#links' => $links,
          ],
        ];
      }
    }
  }
  return $render;
}