You are here

function _authcache_p13n_resource_preproc_partial 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_partial'
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 850
Provides methods for serving personalized content fragments.

Code

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

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

  // Derive collection.
  if (isset($resource['#member_of'])) {
    $collection_id = $resource['#member_of'];
  }
  else {
    $collection_id = 'default partial ' . $partial_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' => 'partials',
      '#key' => $partial_id,
      '#processors' => array(
        'renderer' => 'require_instance(AuthcacheP13nFragmentInterface)',
        'validator' => 'accept_instance(AuthcacheP13nFragmentValidatorInterface)',
        'loader' => 'accept_instance(AuthcacheP13nFragmentLoaderInterface)',
        'access' => 'accept_instance(AuthcacheP13nFragmentAccessInterface)',
      ),
    ),
    $collection_id . ' renderer' => $resource + array(
      '#member_of' => $collection_id,
      '#key' => 'renderer',
    ),
    $collection_id . ' validator' => $resource + array(
      '#member_of' => $collection_id,
      '#key' => 'validator',
    ),
    $collection_id . ' loader' => $resource + array(
      '#member_of' => $collection_id,
      '#key' => 'loader',
    ),
    $collection_id . ' access' => $resource + array(
      '#member_of' => $collection_id,
      '#key' => 'access',
    ),
  ), $priority - 1);
  return $resource + array(
    '#member_of' => $collection_id,
    '#key' => 'renderer',
  );
}