You are here

function _authcache_p13n_resource_preproc_setting in Authenticated User Page Caching (Authcache) 7.2

Derive collection-id and add #member_of and #key entries if necessary.

Related topics

1 string reference to '_authcache_p13n_resource_preproc_setting'
authcache_p13n_authcache_p13n_resource_preprocessors in modules/authcache_p13n/authcache_p13n.module
Implements hook_authcache_p13n_resource_preprocessors().

File

modules/authcache_p13n/authcache_p13n.module, line 910
Provides methods for serving personalized content fragments.

Code

function _authcache_p13n_resource_preproc_setting($resource, $priority, $rname, $enqueue) {

  // Find setting-id.
  if (!is_array($resource) || !isset($resource['#setting'])) {
    return;
  }
  $setting_id = $resource['#setting'];
  unset($resource['#setting']);

  // Derive collection.
  if (isset($resource['#member_of'])) {
    $collection_id = $resource['#member_of'];
  }
  else {
    $collection_id = 'default setting ' . $setting_id . ' ' . drupal_random_key();
  }

  // Create a set of default resources: One collection entry and one renderer,
  // validator, loader and access checker. Use negative priority in order to
  // avoid overriding resources defined elsewhere.
  $enqueue(array(
    $collection_id => array(
      '#collection' => $collection_id,
      '#member_of' => 'settings',
      '#key' => $setting_id,
      '#processors' => array(
        'renderer' => 'require_instance(AuthcacheP13nSettingInterface)',
        'validator' => 'accept_instance(AuthcacheP13nSettingValidatorInterface)',
        'access' => 'accept_instance(AuthcacheP13nSettingAccessInterface)',
      ),
    ),
    $collection_id . ' renderer' => $resource + array(
      '#member_of' => $collection_id,
      '#key' => 'renderer',
    ),
    $collection_id . ' target' => array(
      '#value' => $setting_id,
      '#member_of' => $collection_id,
      '#key' => 'target',
    ),
    $collection_id . ' validator' => $resource + array(
      '#member_of' => $collection_id,
      '#key' => 'validator',
    ),
    $collection_id . ' access' => $resource + array(
      '#member_of' => $collection_id,
      '#key' => 'access',
    ),
  ), $priority - 1);

  // If a target key is specified, add a target resource with the same priority.
  if (isset($resource['#target'])) {
    $enqueue(array(
      $collection_id . ' target' => array(
        '#value' => $resource['#target'],
        '#member_of' => $collection_id,
        '#key' => 'target',
      ),
    ), $priority);
  }
  return $resource + array(
    '#member_of' => $collection_id,
    '#key' => 'renderer',
  );
}