You are here

function ccl_views_ccl_cache_update in Custom Contextual Links 8

Same name and namespace in other branches
  1. 7 ccl_views/ccl_views.module \ccl_views_ccl_cache_update()

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

File

ccl_views/ccl_views.module, line 129
Implements support of views in CCL.

Code

function ccl_views_ccl_cache_update() {
  $views = db_query("SELECT * FROM {ccl} WHERE type = :type", array(
    ':type' => 'view',
  ));
  $view_cache = array(
    'global' => array(),
    'displays' => array(),
    'views' => array(),
  );
  foreach ($views as $view) {
    $view->options = unserialize($view->options);
    $advanced = array();
    if (isset($view->options['advanced_css'])) {
      $advanced['class'] = $view->options['advanced_css'];
    }
    if (isset($view->options['advanced_query'])) {
      $advanced['query'] = $view->options['advanced_query'];
    }
    if (isset($view->options['advanced_anchor'])) {
      $advanced['anchor'] = $view->options['advanced_anchor'];
    }
    if (isset($view->options['advanced_target']) && $view->options['advanced_target'] != "default") {
      $advanced['target'] = $view->options['advanced_target'];
    }
    if (isset($view->options['advanced_destination'])) {
      $advanced['destination'] = $view->options['advanced_destination'];
    }
    if ($view->options['view_options'] == 0) {
      $view_cache['global'][] = array(
        'title' => $view->title,
        'href' => $view->link,
        'advanced' => $advanced,
      );
    }
    elseif ($view->options['view_options'] == 2) {
      $view_cache['displays'][$view->options['view_display']][] = array(
        'title' => $view->title,
        'href' => $view->link,
        'advanced' => $advanced,
      );
    }
    elseif ($view->options['view_options'] == 1) {
      $view_cache['views'][$view->options['view_view']][] = array(
        'title' => $view->title,
        'href' => $view->link,
        'advanced' => $advanced,
      );
    }
  }
  \Drupal::cache()
    ->set('ccl_view', $view_cache);
}