function views_get_views_as_options

cis7 views.module views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE)
cle7 views.module views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE)
elmsmedia7 views.module views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE)
icor7 views.module views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE)
meedjum_blog7 views.module views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE)
mooc7 views.module views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE)

Return an array of view as options array, that can be used by select, checkboxes and radios as #options.

Parameters

bool $views_only: If TRUE, only return views, not displays.

string $filter: Filters the views on status. Can either be 'all' (default), 'enabled' or 'disabled'

mixed $exclude_view: view or current display to exclude either a

  • views object (containing $exclude_view->name and $exclude_view->current_display)
  • views name as string: e.g. my_view
  • views name and display id (separated by ':'): e.g. my_view:default

bool $optgroup: If TRUE, returns an array with optgroups for each view (will be ignored for $views_only = TRUE). Can be used by select

bool $sort: If TRUE, the list of views is sorted ascending.

Return value

array an associative array for use in select.

  • key: view name and display id separated by ':', or the view name only
2 calls to views_get_views_as_options()
og_ui_admin_settings in sites/all/modules/ulmus/og/og_ui/og_ui.admin.inc
Menu callback; Admin settings form.
views_handler_area_view::options_form in sites/all/modules/ulmus/views/handlers/views_handler_area_view.inc
Default options form that provides the label widget that all fields should have.

File

sites/all/modules/ulmus/views/views.module, line 1478
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE) {

  // Filter the big views array.
  switch ($filter) {
    case 'all':
    case 'disabled':
    case 'enabled':
      $func = "views_get_{$filter}_views";
      $views = $func();
      break;
    default:
      return array();
  }

  // Prepare exclude view strings for comparison.
  if (empty($exclude_view)) {
    $exclude_view_name = '';
    $exclude_view_display = '';
  }
  elseif (is_object($exclude_view)) {
    $exclude_view_name = $exclude_view->name;
    $exclude_view_display = $exclude_view->current_display;
  }
  else {
    list($exclude_view_name, $exclude_view_display) = explode(':', $exclude_view);
  }

  $options = array();
  foreach ($views as $view) {
    // Return only views.
    if ($views_only && $view->name != $exclude_view_name) {
      $options[$view->name] = $view->get_human_name();
    }
    // Return views with display ids.
    else {
      foreach ($view->display as $display_id => $display) {
        if (!($view->name == $exclude_view_name && $display_id == $exclude_view_display)) {
          if ($optgroup) {
            $options[$view->name][$view->name . ':' . $display->id] = t('@view : @display', array('@view' => $view->name, '@display' => $display->id));
          }
          else {
            $options[$view->name . ':' . $display->id] = t('View: @view - Display: @display', array('@view' => $view->name, '@display' => $display->id));
          }
        }
      }
    }
  }
  if ($sort) {
    ksort($options);
  }
  return $options;
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.