You are here

public function SynonymConfigController::overview in Synonyms 2.0.x

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

Routing callback: show the 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 71

Class

SynonymConfigController
Controller for admin UI of the module.

Namespace

Drupal\synonyms\Controller

Code

public function overview() {
  $render = [];

  // The include entity label item.
  if (\Drupal::moduleHandler()
    ->moduleExists('synonyms_list_field')) {
    $include_entity_label = \Drupal::config('synonyms_list_field.settings')
      ->get('include_entity_label') ? $this
      ->t('Yes') : $this
      ->t('No');
    $render['include_entity_label'] = [
      '#type' => 'item',
      '#name' => 'include_entity_label',
      '#title' => $this
        ->t('Include entity label'),
      '#markup' => $include_entity_label,
      '#wrapper_attributes' => [
        'class' => [
          'container-inline',
        ],
      ],
    ];
  }

  // Wording type item.
  $render['wording_type'] = [
    '#type' => 'item',
    '#name' => 'wording_type',
    '#title' => $this
      ->t('Wording type'),
    '#markup' => \Drupal::config('synonyms.settings')
      ->get('wording_type_label'),
    '#wrapper_attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
  ];

  // Default wordings item.
  if (\Drupal::config('synonyms.settings')
    ->get('wording_type') != 'none') {
    if ($widget_services = $this->behaviorService
      ->getWidgetServices()) {
      $default_wordings = [];
      foreach ($widget_services as $service_id => $service) {
        $widget_wording = \Drupal::config('synonyms_' . $service_id . '.settings')
          ->get('default_wording');
        if (empty($widget_wording)) {
          $widget_wording = $this
            ->t('Notice: Wording for this widget is empty. Please, edit settings and add wording here if you need it.');
        }
        $default_wordings[] = $this
          ->t('@widget_title widget: @widget_wording', [
          '@widget_title' => $service
            ->getWidgetTitle(),
          '@widget_wording' => $widget_wording,
        ]);
      }
      $wordings_markup = '<ul>';
      foreach ($default_wordings as $default_wording) {
        $wordings_markup .= '<li>' . $default_wording . '</li>';
      }
      $wordings_markup .= '</ul>';
      $render['default_wordings'] = [
        '#type' => 'item',
        '#title' => $this
          ->t('Default wordings:'),
        '#name' => 'default_wordings',
        '#markup' => $wordings_markup,
      ];
    }
  }

  // The overview table.
  $render['table'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Entity type'),
      $this
        ->t('Bundle'),
      $this
        ->t('Providers'),
      $this
        ->t('Behaviors'),
      $this
        ->t('Actions'),
    ],
  ];
  foreach ($this
    ->entityTypeManager()
    ->getDefinitions() as $entity_type) {
    if ($entity_type instanceof ContentEntityTypeInterface) {
      foreach ($this->entityTypeBundleInfo
        ->getBundleInfo($entity_type
        ->id()) as $bundle => $bundle_info) {
        $providers_list = [];
        foreach ($this->providerService
          ->getSynonymConfigEntities($entity_type
          ->id(), $bundle) as $synonym_config) {
          $providers_list[] = $synonym_config
            ->label();
        }
        $providers_list = implode(', ', $providers_list);
        $behaviors_list = [];
        foreach ($this->behaviorService
          ->getBehaviorServices() as $service_id => $service) {
          if ($this->providerService
            ->serviceIsEnabled($entity_type
            ->id(), $bundle, $service_id)) {
            $behaviors_list[] = $service
              ->getTitle();
          }
        }
        $behaviors_list = implode(', ', $behaviors_list);
        $links = [];
        $links['manage_providers'] = [
          'title' => $this
            ->t('Manage providers'),
          'url' => Url::fromRoute('synonym.entity_type.bundle', [
            'synonyms_entity_type' => $entity_type
              ->id(),
            'bundle' => $bundle,
          ]),
        ];
        $links['manage_behaviors'] = [
          'title' => $this
            ->t('Manage behaviors'),
          'url' => Url::fromRoute('behavior.entity_type.bundle', [
            'synonyms_entity_type' => $entity_type
              ->id(),
            'bundle' => $bundle,
          ]),
        ];
        $render['table'][] = [
          [
            '#markup' => Html::escape($entity_type
              ->getLabel()),
          ],
          [
            '#markup' => $bundle == $entity_type
              ->id() ? '' : Html::escape($bundle_info['label']),
          ],
          [
            '#markup' => Html::escape($providers_list),
          ],
          [
            '#markup' => Html::escape($behaviors_list),
          ],
          [
            '#type' => 'operations',
            '#links' => $links,
          ],
        ];
      }
    }
  }
  return $render;
}