You are here

public function SimpleSitemapViews::getIndexableViews in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 4.x modules/simple_sitemap_views/src/SimpleSitemapViews.php \Drupal\simple_sitemap_views\SimpleSitemapViews::getIndexableViews()

Returns an array of executable views whose current display is indexable.

Return value

\Drupal\views\ViewExecutable[] An array of ViewExecutable instances.

File

modules/simple_sitemap_views/src/SimpleSitemapViews.php, line 469

Class

SimpleSitemapViews
Class to manage sitemap data for views.

Namespace

Drupal\simple_sitemap_views

Code

public function getIndexableViews() {

  // Check that views support is enabled.
  if (!$this
    ->isEnabled()) {
    return [];
  }

  // Load views with display plugins that use the route.
  $query = $this->viewStorage
    ->getQuery();
  $query
    ->condition('status', TRUE);
  $query
    ->condition("display.*.display_plugin", $this
    ->getRouterDisplayPluginIds(), 'IN');
  $view_ids = $query
    ->execute();

  // If there are no such views, then return an empty array.
  if (empty($view_ids)) {
    return [];
  }
  $indexable_views = [];

  /** @var \Drupal\views\ViewEntityInterface $view_entity */
  foreach ($this->viewStorage
    ->loadMultiple($view_ids) as $view_entity) {
    foreach ($this
      ->getRouterDisplayIds($view_entity) as $display_id) {
      $view = Views::executableFactory()
        ->get($view_entity);

      // Ensure the display was correctly set.
      if (!$view
        ->setDisplay($display_id)) {
        $view
          ->destroy();
        continue;
      }

      // Check that the display is enabled and indexed.
      if ($view->display_handler
        ->isEnabled() && $this
        ->getIndexableVariants($view)) {
        $indexable_views[] = $view;
      }
    }
  }
  return $indexable_views;
}