You are here

function ccl_blocks_ccl_cache_update in Custom Contextual Links 8

Same name and namespace in other branches
  1. 7 ccl_blocks/ccl_blocks.module \ccl_blocks_ccl_cache_update()

Implements hook_ccl_cache_update().

Hook function triggered by the chache update routine of the main module.

File

ccl_blocks/ccl_blocks.module, line 105
Implments support for CCL on blocks.

Code

function ccl_blocks_ccl_cache_update() {
  $blocks = db_query("SELECT * FROM {ccl} WHERE type = :type", array(
    ':type' => 'block',
  ));
  $block_cache = array(
    'global' => array(),
    'ids' => array(),
  );
  foreach ($blocks as $block) {
    $block->options = unserialize($block->options);
    $advanced = array();
    if (isset($block->options['advanced_css'])) {
      $advanced['class'] = $block->options['advanced_css'];
    }
    if (isset($block->options['advanced_query'])) {
      $advanced['query'] = $block->options['advanced_query'];
    }
    if (isset($block->options['advanced_anchor'])) {
      $advanced['anchor'] = $block->options['advanced_anchor'];
    }
    if (isset($block->options['advanced_target']) && $block->options['advanced_target'] != "default") {
      $advanced['target'] = $block->options['advanced_target'];
    }
    if (isset($block->options['advanced_destination'])) {
      $advanced['destination'] = $block->options['advanced_destination'];
    }
    if ($block->options['block_global']) {
      $block_cache['global'][] = array(
        'title' => $block->title,
        'href' => $block->link,
        'advanced' => $advanced,
      );
    }
    else {

      // Create an entry for each selected block.
      foreach ($block->options['block_select'] as $id) {
        $block_cache['ids'][$id][] = array(
          'title' => $block->title,
          'href' => $block->link,
          'advanced' => $advanced,
        );
      }
    }
  }
  \Drupal::cache()
    ->set('ccl_blocks', $block_cache);
}