You are here

function esi_block__esi_block_prepare in ESI: Edge Side Includes 7.3

Prepare an ESI block for rendering. Defined in hook_esi_component_info().

See also

esi_block_esi_component_info().

2 string references to 'esi_block__esi_block_prepare'
esi_block_esi_component_info in modules/esi_block/esi_block.module
Implements hook_esi_component().
hook_esi_component in ./esi.api.inc
Declare a handler for delivering content through ESI.

File

modules/esi_block/esi_block.esi.inc, line 13
ESI handlers for ESI Block.

Code

function esi_block__esi_block_prepare($component_key) {
  list($theme, $region, $module, $delta) = explode(':', $component_key);
  $block = block_load($module, $delta);

  // Validate that the module/delta combination is valid.
  if (empty($block->esi_enabled)) {
    return FALSE;
  }
  $block->theme = $theme;
  $block->region = $region;

  // Check for optional arguments (page, user/role cache control).
  $args = array_slice(func_get_args(), 1);
  if (count($args)) {

    // Check for user/role contexts.
    if (preg_match('/CACHE=(USER|ROLE)/', $args[count($args) - 1], $matches)) {
      $block->esi_cache_context = $matches[1];
      array_pop($args);
    }

    // Check for a page context.
    if (count($args) && ($page = base64_decode($args[0]))) {
      $block->esi_page_context = $page;
    }
  }

  // Allow other modules to alter the context information here.
  // @see hook_esi_block_context_alter().
  drupal_alter('esi_block_context', $block);

  // Restore the original context.
  esi_block__restore_context($block);
  return $block;
}