You are here

function _viewreference_extract_views_displays in View reference 7.3

Get an array of views.

Parameters

array $settings: The settings of the field.

views_display[] $views_displays:

bool $append_id: Whether to append the id to the returned display names.

bool $full: If TRUE will return all the data, rather than just the title.

string $string: String to match against the title to filter results by.

bool $exact_string: If TRUE the $string parameter must match exactly.

bool $long_key: If TRUE will key array by the title and ID, not just the ID.

Return value

mixed[] The array of views.

1 call to _viewreference_extract_views_displays()
viewreference_get_views in ./viewreference.module
Get an array of views.

File

./viewreference.module, line 744
Defines a field type for referencing a view from a node.

Code

function _viewreference_extract_views_displays($settings, $views_displays, $append_id = FALSE, $full = FALSE, $string = '', $exact_string = FALSE, $long_key = FALSE) {
  $views = array();
  foreach ($views_displays as $view_name => $view_and_displays) {
    list($view, $view_displays) = $view_and_displays;

    /** @var views_display $display */
    foreach ($view_displays as $display_key => $display) {
      $id = $view_name . ':' . $display_key;

      // Get display title.
      $theme_vars = array(
        'view' => $view,
        'view_name' => $view_name,
        'display_key' => $display_key,
        'append_id' => $append_id,
      );
      $display_title = theme('viewreference_display_form_title', $theme_vars);

      // Determine whether and what to return.
      $key = $long_key ? $display_title . ($append_id ? '' : ' [' . $id . ']') : $id;
      if ($string) {
        if (!$exact_string && (stripos($display_title, $string) !== FALSE || stripos($key, $string) !== FALSE)) {
          $views[$key] = $full ? $display : $display_title;
        }
        elseif ($display_title == $string) {
          $views[$key] = $full ? $display : $display_title;
        }
      }
      else {
        $views[$key] = $full ? $display : $display_title;
      }
    }
  }
  if (!empty($settings['sort_views'])) {
    asort($views);
  }
  return $views;
}