You are here

function webform_views_applicable_views in Webform Views Integration 8.5

Return a list of all views applicable for routing manipulation.

[
  [
    $view,
    $display_id,
    $path,
  ],
  [
    $view,
    $display_id,
    $path,
  ],
];

Return value

array A list of arrays containing the $view and $display_id and $path (path where this view is available as a page)

3 calls to webform_views_applicable_views()
RouteSubscriber::alterRoutes in src/Routing/RouteSubscriber.php
Alters existing routes for a specific collection.
ViewsLocalTask::alterLocalTasks in src/Plugin/Derivative/ViewsLocalTask.php
Alters the webform views local tasks.
ViewsLocalTask::getDerivativeDefinitions in src/Plugin/Derivative/ViewsLocalTask.php
Gets the definition of all derivatives of a base plugin.

File

./webform_views.module, line 193
Webform integration with views.

Code

function webform_views_applicable_views() {
  $return = [];
  foreach (Views::getApplicableViews('uses_menu_links') as $pair) {
    list($view_id, $display_id) = $pair;

    /** @var $executable \Drupal\views\ViewExecutable */
    $executable = \Drupal::entityTypeManager()
      ->getStorage('view')
      ->load($view_id)
      ->getExecutable();
    $executable
      ->setDisplay($display_id);
    $menu = $executable->display_handler
      ->getOption('menu');
    $contains_webform_id_in_path = explode('/', $executable
      ->getPath());
    $contains_webform_id_in_path = (bool) \Drupal::entityQuery('webform')
      ->condition(\Drupal::entityTypeManager()
      ->getDefinition('webform')
      ->getKey('id'), $contains_webform_id_in_path, 'IN')
      ->count()
      ->execute();

    // TODO: in theory we should do a more intensive analysis than just
    // comparing the base entity type of the view. For example, what if
    // relationships are used and thus webform submission is introduced into the
    // view while the base entity type may be different. Though hardly we will
    // see such use cases in real world practice.
    if ($executable
      ->getBaseEntityType() && $executable
      ->getBaseEntityType()
      ->id() == 'webform_submission' && in_array($menu['type'], [
      'tab',
      'default tab',
    ]) && $contains_webform_id_in_path) {
      $return[] = [
        $view_id,
        $display_id,
        $executable->display_handler
          ->getPath(),
      ];
    }
  }
  return $return;
}