Views::getApplicableViews

public static Views::getApplicableViews($type)

Return a list of all view IDs and display IDs that have a particular setting in their display's plugin settings.

array(
  array($view_id, $display_id),
  array($view_id, $display_id),
);

Parameters

string $type: A flag from the display plugin definitions (e.g, 'uses_menu_links').

Return value

array A list of arrays containing the $view_id and $display_id.

File

core/modules/views/src/Views.php, line 205

Class

Views
Static service container wrapper for views.

Namespace

Drupal\views

Code

public static function getApplicableViews($type) {
  // Get all display plugins which provides the type.
  $display_plugins = static::pluginManager('display')->getDefinitions();

  $plugin_ids = [];
  foreach ($display_plugins as $id => $definition) {
    if (!empty($definition[$type])) {
      $plugin_ids[$id] = $id;
    }
  }

  $entity_ids = \Drupal::service('entity.query')->get('view')
    ->condition('status', TRUE)
    ->condition("display.*.display_plugin", $plugin_ids, 'IN')
    ->execute();

  $result = array();
  foreach (\Drupal::entityManager()->getStorage('view')->loadMultiple($entity_ids) as $view) {
    // Check each display to see if it meets the criteria and is enabled.

    foreach ($view->get('display') as $id => $display) {
      // If the key doesn't exist, enabled is assumed.
      $enabled = !empty($display['display_options']['enabled']) || !array_key_exists('enabled', $display['display_options']);

      if ($enabled && in_array($display['display_plugin'], $plugin_ids)) {
        $result[] = [$view->id(), $id];
      }
    }
  }

  return $result;
}
doc_Drupal
2016-10-29 09:54:48
Comments
Leave a Comment

Please login to continue.