You are here

function views_crumbs_plugins in Crumbs, the Breadcrumbs suite 7.2

Implements hook_crumbs_plugins().

Parameters

crumbs_InjectedAPI_hookCrumbsPlugins $api:

File

plugins/crumbs.views.inc, line 9

Code

function views_crumbs_plugins($api) {

  // We try to get all views pages but avoid views_get_all_view() for performance.
  $q = db_select('menu_router', 'mr');
  $q
    ->condition('page_callback', 'views_page');
  $q
    ->fields('mr', array(
    'path',
    'page_arguments',
    'title',
    'title_callback',
  ));
  $viewDisplays = array();
  foreach ($q
    ->execute() as $row) {
    if (0 || !empty($row->title) || !empty($row->title_callback) && 't' !== $row->title_callback) {
      continue;
    }
    $args = unserialize($row->page_arguments);
    if (2 > count($args)) {

      // Not really a views display, too few arguments.
      continue;
    }
    list($view_name, $view_display_ids) = $args;
    if (!is_string($view_name)) {

      // Not really a views display, wrong type of arguments.
      continue;
    }

    // The second argument is usually just a string identifying the display id.
    // However, it can also be an array of display ids.
    // @see view::choose_display()
    // Unfortunately, it can also be complete junk.
    // @see https://www.drupal.org/node/2316873#comment-9037925
    if (!is_array($view_display_ids)) {
      $view_display_ids = array(
        $view_display_ids,
      );
    }
    foreach ($view_display_ids as $view_display_id) {
      if (!is_string($view_display_id)) {
        continue;
      }
      $viewDisplays[$view_name][$view_display_id][] = $row->path;
    }
  }
  foreach ($viewDisplays as $view_name => $displays) {
    foreach ($displays as $view_display_id => $routes) {
      if (count($routes) > 1) {

        // More than one route for the same views display.
        // This would typically happen with the "Default menu tab" menu setting.
        // However, since these cases are filtered out above, this is rather an
        // edge case, which does not really happen.
        // As an easy solution, we simply pick the shortest or lexigraphically
        // first of the router paths.
        sort($routes);
      }
      $api
        ->routeMonoPlugin($routes[0], "pageTitle.{$view_name}.{$view_display_id}", new views_CrumbsMonoPlugin_PageTitle($view_name, $view_display_id));
    }
  }
}