You are here

function views_access_callback_access_callback in Views Access Callback 8

Same name and namespace in other branches
  1. 6 views_access_callback.module \views_access_callback_access_callback()
  2. 7 views_access_callback.module \views_access_callback_access_callback()

Intermediary access callback function getting view arguments and calling real function specified in view definition.

2 calls to views_access_callback_access_callback()
ViewsAccessCallback::access in src/Plugin/views/access/ViewsAccessCallback.php
Determine if the current user has access or not.
ViewsAccessCallback::alterRouteDefinition in src/Plugin/views/access/ViewsAccessCallback.php
Allows access plugins to alter the route definition of a view.

File

./views_access_callback.module, line 12

Code

function views_access_callback_access_callback($view_name, $display_id, $access_callback) {

  // Init view.
  $view = Views::getView($view_name);
  $view
    ->setDisplay($display_id);
  $view
    ->initHandlers();

  // Find the values for any arguments embedded in the path via '%'.
  $i = 0;
  foreach (explode('/', $view->display_handler
    ->getOption('path')) as $element) {
    if ($element == '%') {
      $view->args[] = arg($i);
    }
    $i++;
  }

  // Now handle any implicit arguments from the end of the path.
  $num_arguments = count($view->argument);
  while (count($view->args) < $num_arguments) {
    $view->args[] = arg($i);
    $i++;
  }
  $result = FALSE;
  if (function_exists($access_callback)) {
    $result = call_user_func_array($access_callback, $view->args);
  }
  return $result;
}