You are here

function _ccl_update_cache in Custom Contextual Links 8

Same name and namespace in other branches
  1. 7 ccl.module \_ccl_update_cache()

Helper function to write ccl settings into the cache.

5 calls to _ccl_update_cache()
CclAddForm::submitForm in src/Form/CclAddForm.php
Form submission handler.
CclDeleteConfirm::submitForm in src/Form/CclDeleteConfirm.php
Form submission handler.
ccl_add_form_submit in ./ccl.admin.inc
Submit handler for ccl_add_form().
ccl_cache_get in ./ccl.module
Helper function to get ccl settings out of the cache.
ccl_delete_confirm_submit in ./ccl.admin.inc
Submit handler for link deletion page.

File

./ccl.module, line 208
Main CCL module file.

Code

function _ccl_update_cache() {

  // Create entry for nodes.
  $nodes = db_query("SELECT * FROM {ccl} WHERE type = :type", array(
    ':type' => 'node',
  ));
  $node_cache = array(
    'global' => array(),
    'ct' => array(),
    'ids' => array(),
  );
  foreach ($nodes as $node) {
    $node->options = unserialize($node->options);
    $advanced = array();
    if (isset($node->options['advanced_css'])) {
      $advanced['class'] = $node->options['advanced_css'];
    }
    if (isset($node->options['advanced_anchor'])) {
      $advanced['anchor'] = $node->options['advanced_anchor'];
    }
    if (isset($node->options['advanced_query'])) {
      $advanced['query'] = $node->options['advanced_query'];
    }
    if (isset($node->options['advanced_target']) && $node->options['advanced_target'] != "default") {
      $advanced['target'] = $node->options['advanced_target'];
    }
    if (isset($node->options['advanced_destination'])) {
      $advanced['destination'] = $node->options['advanced_destination'];
    }
    if ($node->options['node_options'] == 'global') {
      $node_cache['global'][] = array(
        'title' => $node->title,
        'href' => $node->link,
        'advanced' => $advanced,
      );
    }
    elseif ($node->options['node_options'] == 'node') {
      $node_cache['ids'][$node->options['node_id']][] = array(
        'title' => $node->title,
        'href' => $node->link,
        'advanced' => $advanced,
      );
    }
    else {
      $node_cache['ct'][$node->options['node_type']][] = array(
        'title' => $node->title,
        'href' => $node->link,
        'advanced' => $advanced,
      );
    }
  }
  \Drupal::cache()
    ->set('ccl_nodes', $node_cache);

  // Invoke cache_update hook for submodules.
  foreach (\Drupal::moduleHandler()
    ->getImplementations('ccl_cache_update') as $module) {
    \Drupal::moduleHandler()
      ->invoke($module, 'ccl_cache_update');
  }
}