You are here

function views_access in Views (for Drupal 7) 8.3

Same name and namespace in other branches
  1. 5 views.module \views_access()
  2. 6.3 views.module \views_access()
  3. 6.2 views.module \views_access()
  4. 7.3 views.module \views_access()

Determine if the logged in user has access to a view.

This function should only be called from a menu hook or some other embedded source. Each argument is the result of a call to views_plugin_access::get_access_callback() which is then used to determine if that display is accessible. If *any* argument is accessible, then the view is accessible.

2 calls to views_access()
AccessTest::testDynamicAccessPlugin in lib/Drupal/views/Tests/Plugin/AccessTest.php
Tests dynamic access plugin.
AccessTest::testStaticAccessPlugin in lib/Drupal/views/Tests/Plugin/AccessTest.php
Tests static access check.
1 string reference to 'views_access'
Page::executeHookMenu in lib/Drupal/views/Plugin/views/display/Page.php
Add this display's path information to Drupal's menu system.

File

./views.module, line 1067
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_access() {
  $args = func_get_args();
  foreach ($args as $arg) {
    if ($arg === TRUE) {
      return TRUE;
    }
    if (!is_array($arg)) {
      continue;
    }
    list($callback, $arguments) = $arg;
    $arguments = $arguments ? $arguments : array();

    // Bring dynamic arguments to the access callback.
    foreach ($arguments as $key => $value) {
      if (is_int($value) && isset($args[$value])) {
        $arguments[$key] = $args[$value];
      }
    }
    if (function_exists($callback) && call_user_func_array($callback, $arguments)) {
      return TRUE;
    }
  }
  return FALSE;
}