1 views.module views_arg_load($value, $name, $display_id, $index)

Helper function for menu loading. This will automatically be called in order to 'load' a views argument; primarily it will be used to perform validation.

Parameters

string $value: The actual value passed.

string $name: The name of the view. This needs to be specified in the 'load function' of the menu entry.

string|array $display_id: The display id or an array of display ids that will be loaded for this menu item.

int $index: The menu argument index. This counts from 1.

Return value

string|int|FALSE: The argument value, whether a string or ID. FALSE if the given value is invalid.

File

core/modules/views/views.module, line 495
Primarily Backdrop hooks and global API functions to manipulate views.

Code

function views_arg_load($value, $name, $display_id, $index) {
  static $views = array();

  $display_ids = is_array($display_id) ? $display_id : array($display_id);
  $display_id = reset($display_ids);

  foreach ($display_ids as $id) {
    // Make sure we haven't already loaded this views argument for a similar
    // menu item elsewhere. Since access is always checked for the current user,
    // we are sure that the static cache contains valid entries.
    $key = $name . ':' . $id . ':' . $value . ':' . $index;
    if (isset($views[$key])) {
      return $views[$key];
    }
    // Lazy load the view object to avoid unnecessary work.
    if (!isset($view)) {
      $view = views_get_view($name);
    }
    // Pick the first display we have access to.
    if ($view && count($display_ids) > 1 && $view->access($id)) {
      $display_id = $id;
      break;
    }
  }

  if ($view) {
    $view->set_display($display_id);
    $view->init_handlers();

    $ids = array_keys($view->argument);

    $indexes = array();
    $path = explode('/', $view->get_path());

    foreach ($path as $id => $piece) {
      if ($piece == '%' && !empty($ids)) {
        $indexes[$id] = array_shift($ids);
      }
    }

    if (isset($indexes[$index])) {
      if (isset($view->argument[$indexes[$index]])) {
        $arg = $view->argument[$indexes[$index]]->validate_argument($value) ? $value : FALSE;
        $view->destroy();

        // Store the output in case we load this same menu item again.
        $views[$key] = $arg;
        return $arg;
      }
    }
    $view->destroy();
  }
}