You are here

protected function ViewListBuilder::getDisplaysList in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views_ui/src/ViewListBuilder.php \Drupal\views_ui\ViewListBuilder::getDisplaysList()
  2. 9 core/modules/views_ui/src/ViewListBuilder.php \Drupal\views_ui\ViewListBuilder::getDisplaysList()

Gets a list of displays included in the view.

Parameters

\Drupal\Core\Entity\EntityInterface $view: The view entity instance to get a list of displays for.

Return value

array An array of display types that this view includes.

1 call to ViewListBuilder::getDisplaysList()
ViewListBuilder::buildRow in core/modules/views_ui/src/ViewListBuilder.php
Builds a row for an entity in the entity listing.

File

core/modules/views_ui/src/ViewListBuilder.php, line 251

Class

ViewListBuilder
Defines a class to build a listing of view entities.

Namespace

Drupal\views_ui

Code

protected function getDisplaysList(EntityInterface $view) {
  $displays = [];
  $executable = $view
    ->getExecutable();
  $executable
    ->initDisplay();
  foreach ($executable->displayHandlers as $display) {
    $rendered_path = FALSE;
    $definition = $display
      ->getPluginDefinition();
    if (!empty($definition['admin'])) {
      if ($display
        ->hasPath()) {
        $path = $display
          ->getPath();
        if ($view
          ->status() && strpos($path, '%') === FALSE) {

          // Wrap this in a try/catch as trying to generate links to some
          // routes may throw a NotAcceptableHttpException if they do not
          // respond to HTML, such as RESTExports.
          try {

            // @todo Views should expect and store a leading /. See:
            //   https://www.drupal.org/node/2423913
            $rendered_path = Link::fromTextAndUrl('/' . $path, Url::fromUserInput('/' . $path))
              ->toString();
          } catch (NotAcceptableHttpException $e) {
            $rendered_path = '/' . $path;
          }
        }
        else {
          $rendered_path = '/' . $path;
        }
      }
      $displays[] = [
        'display' => $definition['admin'],
        'path' => $rendered_path,
      ];
    }
  }
  sort($displays);
  return $displays;
}