You are here

public function AdminController::displayListing in Search API sorts 8

Overview of search api displays to choose to manage sort fields for.

1 string reference to 'AdminController::displayListing'
search_api_sorts.routing.yml in ./search_api_sorts.routing.yml
search_api_sorts.routing.yml

File

src/Controller/AdminController.php, line 63

Class

AdminController
Class AdminController.

Namespace

Drupal\search_api_sorts\Controller

Code

public function displayListing(IndexInterface $search_api_index) {
  $rows = [];
  foreach ($this->searchApiDisplayManager
    ->getInstances() as $display) {
    if ($display
      ->getIndex() instanceof IndexInterface && $search_api_index
      ->id() === $display
      ->getIndex()
      ->id()) {
      $row = [];
      $row['display'] = $display
        ->label();
      $row['description'] = $display
        ->getDescription();
      $search_api_display = $display
        ->getPluginId();
      $escaped_search_api_display = $this
        ->getEscapedConfigId($search_api_display);
      $links['configure'] = [
        'title' => $this
          ->t('Manage sort fields'),
        'url' => Url::fromRoute('search_api_sorts.search_api_display.sorts', [
          'search_api_index' => $search_api_index
            ->id(),
          'search_api_display' => $escaped_search_api_display,
        ]),
      ];
      $row['operations']['data'] = [
        '#type' => 'operations',
        '#links' => $links,
      ];
      $rows[] = $row;
    }
  }
  $build['table'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Display'),
      $this
        ->t('Description'),
      $this
        ->t('Operations'),
    ],
    '#title' => $this
      ->t('Sorts configuration.'),
    '#rows' => $rows,
    '#empty' => $this
      ->t('You have no search displays defined yet. An example of a display is a views page using this index, or a search api pages page.'),
  ];
  return $build;
}