You are here

function esi_context_page_alter in ESI: Edge Side Includes 7.3

Implements hook_page_alter().

File

modules/esi_context/esi_context.module, line 25
ESI integration for the context module.

Code

function esi_context_page_alter(&$page) {

  // Look for blocks exposed by the context module; add ESI information.
  foreach (element_children($page) as $region_key) {
    foreach (element_children($page[$region_key]) as $block_key) {
      if (isset($page[$region_key][$block_key]['context'])) {
        $element = $page[$region_key][$block_key];

        // Look for the module/delta.
        if (!empty($element['#block']) && is_object($element['#block'])) {
          $module = $element['#block']->module;
          if ($module == 'esi_block') {
            list($module, $delta) = esi_block__new_delta($element['#block']->delta);
          }
          else {
            $delta = $element['#block']->delta;
          }

          // Get the full block data from the DB.
          $block = block_load($module, $delta);
          $page[$region_key][$block_key]['#block']->esi_enabled = $block->esi_enabled;
          $page[$region_key][$block_key]['#block']->esi_ttl = $block->esi_ttl;
        }
      }
    }
  }
}