You are here

context_layouts.module in Context 6.3

File

context_layouts/context_layouts.module
View source
<?php

/**
 * Implementation of hook_help().
 */
function context_layouts_help($path, $arg) {
  switch ($path) {
    case 'admin/help#context_layouts':
      $output = file_get_contents(drupal_get_path('module', 'context_layouts') . '/README.txt');
      return module_exists('markdown') ? filter_xss_admin(module_invoke('markdown', 'filter', 'process', 0, -1, $output)) : '<pre>' . check_plain($output) . '</pre>';
  }
}

/**
 * Implementation of hook_context_plugins().
 * This is a ctools plugins hook.
 */
function context_layouts_context_plugins() {
  return array(
    'context_layouts_reaction_block' => array(
      'handler' => array(
        'path' => drupal_get_path('module', 'context_layouts') . '/plugins',
        'file' => 'context_layouts_reaction_block.inc',
        'class' => 'context_layouts_reaction_block',
        'parent' => 'context_reaction_block',
      ),
    ),
  );
}

/**
 * Implementation of hook_context_registry_alter().
 */
function context_layouts_context_registry_alter(&$registry) {
  if (isset($registry['reactions']['block'])) {
    $registry['reactions']['block']['plugin'] = 'context_layouts_reaction_block';
  }
}

/**
 * Implementation of hook_context_page_reaction().
 */
function context_layouts_context_page_reaction() {
  $plugin = context_get_plugin('reaction', 'block');
  if ($plugin && method_exists($plugin, 'add_layout_stylesheet')) {
    $plugin
      ->add_layout_stylesheet();
  }
}

/**
 * Preprocessor for theme('page').
 */
function context_layouts_preprocess_page(&$vars) {
  $plugin = context_get_plugin('reaction', 'block');
  if ($plugin && method_exists($plugin, 'add_layout_template')) {
    $plugin
      ->add_layout_template($vars);
  }
}

/**
 * Retrieve layouts for the specified theme.
 */
function context_layouts_get_layouts($theme = NULL, $reset = FALSE) {
  static $layouts = array();
  $layouts = $reset ? array() : $layouts;
  global $theme_key;
  $theme = isset($theme) ? $theme : $theme_key;
  if (!isset($layouts[$theme])) {
    $info = context_get_info('theme', $theme);
    $themes = array();

    // Find all our ancestor themes that use layouts.
    if (isset($info['base theme'])) {
      while (!empty($info['base theme'])) {
        $base_theme = $info['base theme'];
        $info = context_get_info('theme', $base_theme);
        $themes[$base_theme] = $info;
      }
    }

    // Assemble in inheritance order and add the theme on.
    $themes = array_reverse($themes);
    $themes[$theme] = context_get_info('theme', $theme);

    // Merge layout info into a single array.
    foreach ($themes as $key => $info) {
      if (!empty($info['layouts'])) {
        foreach ($info['layouts'] as $layout => $layout_info) {
          $layout_info['theme'] = $key;
          $layouts[$theme][$layout] = $layout_info;
        }
      }
    }
  }
  return isset($layouts[$theme]) ? $layouts[$theme] : FALSE;
}

/**
 * Get the active layout for the current page.
 */
function context_layouts_get_active_layout($info = TRUE) {
  $plugin = context_get_plugin('reaction', 'block');
  if ($plugin && method_exists($plugin, 'get_active_layout')) {
    return $plugin
      ->get_active_layout($info);
  }
}

Functions

Namesort descending Description
context_layouts_context_page_reaction Implementation of hook_context_page_reaction().
context_layouts_context_plugins Implementation of hook_context_plugins(). This is a ctools plugins hook.
context_layouts_context_registry_alter Implementation of hook_context_registry_alter().
context_layouts_get_active_layout Get the active layout for the current page.
context_layouts_get_layouts Retrieve layouts for the specified theme.
context_layouts_help Implementation of hook_help().
context_layouts_preprocess_page Preprocessor for theme('page').