You are here

function noderelationships_get_views in Node Relationships 6

Get the list of views in the system.

2 calls to noderelationships_get_views()
noderelationships_admin_settings_backref in ./noderelationships.admin.inc
Back reference settings form.
noderelationships_admin_settings_noderef in ./noderelationships.admin.inc
Node reference extras form.

File

./noderelationships.inc, line 714
Common functions for the noderelationships module.

Code

function noderelationships_get_views($relation_type) {
  $views = array();
  if ($relation_type == 'backref') {
    $views[''] = '[' . t('Default view') . ']';
  }
  foreach (views_get_all_views() as $view) {

    // Ignore disabled views.
    if ($view->disabled) {
      continue;
    }

    // Ignore views that are not based on node table.
    if ($view->base_table != 'node') {
      continue;
    }

    // Filter views depending on relation type.
    if ($relation_type == 'backref' && ($view->tag != NODERELATIONSHIPS_BACKREF_VIEW_TAG || $view->name == NODERELATIONSHIPS_BACKREF_VIEW_NAME)) {
      continue;
    }
    elseif ($relation_type == 'noderef' && $view->tag != NODERELATIONSHIPS_NODEREF_VIEW_TAG) {
      continue;
    }

    // Let's look at all displays defined for the view.
    $view_displays = array();
    foreach ($view->display as $display_id => $display_info) {
      if ($relation_type == 'backref') {

        // For backref views we are interested only in default display.
        if ($display_info->display_plugin != 'default') {
          continue;
        }
      }
      elseif ($relation_type == 'noderef') {

        // For noderef views we are interested only in page displays.
        if ($display_info->display_plugin != 'page') {
          continue;
        }

        // For the moment, we can only guarantee support for the following
        // style pulgins:
        $supported_style_plugins = array(
          'table',
          'grid',
          'fluid_grid',
        );
        $view
          ->set_display($display_id);
        if (!in_array($view->display_handler
          ->get_option('style_plugin'), $supported_style_plugins)) {
          continue;
        }
      }
      $view_displays[$display_id] = $display_info->display_title;
    }
    if (!empty($view_displays)) {
      $view_displays_count = count($view_displays);
      foreach ($view_displays as $display_id => $display_title) {
        $view_label = $view_name = $view->name == NODERELATIONSHIPS_NODEREF_VIEW_NAME ? t('Default view') : $view->name;
        if ($view_displays_count > 1) {
          $view_label .= ' (' . $display_title . ')';
        }
        if ($view->name == NODERELATIONSHIPS_NODEREF_VIEW_NAME) {
          $view_label = '[' . $view_label . ']';
        }
        if ($view_displays_count > 1) {
          if (!isset($views[$view_name])) {
            $views[$view_name] = array();
          }
          $views[$view_name][$view->name . ':' . $display_id] = $display_title;
        }
        else {
          $views[$view->name . ':' . $display_id] = $view_label;
        }
      }
    }
  }

  // Sort views alphabetically.
  uksort($views, '_noderelationships_sort_strncmp');
  return $views;
}