Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

views_arg_load

Definition

views_arg_load($value, $name, $display_id, $index)
contributions/views/views.module, line 243

Description

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

$value The actual value passed.

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

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

Code

<?php
function views_arg_load($value, $name, $display_id, $index) {
  if ($view = views_get_view($name)) {
    $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();
        return $arg;
      }
    }
    $view->destroy();
  }
}
?>