You are here

function esi_block_url in ESI: Edge Side Includes 7.3

Build the URL to use for this ESI component. The URL must contain all the relevant information required to restore the original context of this block.

Parameters

Object $block.: A populated block object (as made available in hook_block_view_alter()) containing as a minimum the keys:

  • cache
  • module
  • delta
  • region
  • theme

Return value

String The internal URL. Generate a fully-qualified path by running through url().

1 call to esi_block_url()
esi_block_block_view_alter in modules/esi_block/esi_block.module
Implements hook_block_view_alter().

File

modules/esi_block/esi_block.module, line 241
ESI handler for blocks.

Code

function esi_block_url($block) {

  // ESI 6.x-1.x and 6.x-2.x used the URL patterns:
  // Default:                esi/block/theme:region:module:delta
  // Cache-per-page:         esi/block/theme:region:module:delta/[base64($_GET['q'])]
  // Cache-per-role:         esi/block/theme:region:module:delta/CACHE=ROLE
  // Cache-per-role DI:      esi/block/theme:region:module:delta/CACHE=[rolehash]
  // Cache-per-page-role:    esi/block/theme:region:module:delta/[base64($_GET['q'])]/CACHE=ROLE
  // Cache-per-page-role DI: esi/block/theme:region:module:delta/[base64($_GET['q'])]/CACHE=[rolehash]
  // Cache-per-user:         esi/block/theme:region:module:delta/CACHE=USER
  // Cache-per-user DI:      esi/block/theme:region:module:delta/CACHE=[userhash]
  // Cache-per-user-page:    esi/block/theme:region:module:delta/[base64($_GET['q'])]/CACHE=USER
  // Cache-per-user-page DI: esi/block/theme:region:module:delta/[base64($_GET['q'])]/CACHE=[userhash]
  // Get the original module/delta.
  list($module, $delta) = esi_block__new_delta($block->delta);

  // Build the "theme:region:module:delta" key.
  $component_key = implode(':', array(
    $block->theme,
    $block->region,
    $module,
    $delta,
  ));
  $url = "esi/block/{$component_key}";

  // Use the $block->cache parameter (as defined in the database) to determine
  // the caching rules for this block (per-user, per-role, etc).
  // The cache configuration is defined in hook_block_info(), and may be
  // altered through hook_block_info_alter().  The alter hook is the correct
  // method to specify a custom cache configuration which is different from
  // that defined in the original hook_block_info().
  // If the block changes per page, encode the page URL in the ESI URL.
  if ($block->cache & DRUPAL_CACHE_PER_PAGE) {
    $url .= '/' . base64_encode($_GET['q']);
  }
  if ($block->cache != DRUPAL_NO_CACHE) {

    // DRUPAL_CACHE_PER_ROLE and DRUPAL_CACHE_PER_USER are mutually exclusive.
    // DRUPAL_CACHE_PER_USER takes precedence.
    // Do not inject the actual roles or user data here; this string must not
    // contain any personalisation, if the current page is to be cacheable.
    if ($block->cache & DRUPAL_CACHE_PER_USER) {
      $url .= '/CACHE=USER';
    }
    elseif ($block->cache & DRUPAL_CACHE_PER_ROLE) {
      $url .= '/CACHE=ROLE';
    }
  }

  // Allow other modules to alter the ESI URL (or respond to it).
  // @see hook_esi_block_url_alter().
  drupal_alter('esi_block_url', $url);
  return $url;
}