You are here

function ctools_access_add_restrictions in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 includes/context.inc \ctools_access_add_restrictions()

Apply restrictions to contexts based upon the access control configured.

These restrictions allow the UI to not show content that may not be relevant to all types of a particular context.

2 calls to ctools_access_add_restrictions()
ctools_context_handler_set_access_restrictions in includes/context-task-handler.inc
Set any access restrictions on the contexts for a handler.
page_manager_page_access_restrictions in page_manager/plugins/tasks/page.inc
Return a list of arguments used by this task.

File

includes/context.inc, line 1514
Contains code related to the ctools system of 'context'.

Code

function ctools_access_add_restrictions($settings, $contexts) {
  if (empty($settings['plugins'])) {
    return;
  }
  if (!isset($settings['logic'])) {
    $settings['logic'] = 'and';
  }

  // We're not going to try to figure out restrictions on the or.
  if ($settings['logic'] == 'or' && count($settings['plugins']) > 1) {
    return;
  }
  foreach ($settings['plugins'] as $test) {
    $plugin = ctools_get_access_plugin($test['name']);
    if ($plugin && ($function = ctools_plugin_get_function($plugin, 'restrictions'))) {
      $required_context = isset($plugin['required context']) ? $plugin['required context'] : array();
      $context = isset($test['context']) ? $test['context'] : array();
      $contexts = ctools_context_select($contexts, $required_context, $context);
      $function($test['settings'], $contexts);
    }
  }
}