You are here

function _cache_actions_get_panels_handlers in Cache Actions 7

Same name and namespace in other branches
  1. 6.2 cache_actions.rules.inc \_cache_actions_get_panels_handlers()
  2. 7.2 cache_actions.rules.inc \_cache_actions_get_panels_handlers()

Get all existing handlers from page manager. This is the ugliest function in the whole module =)

Parameters

bool $panes set this to true if you want the function to return: an array consisting of the panels and the panes.

Return value

the handlers.

2 calls to _cache_actions_get_panels_handlers()
_cache_actions_get_page_variants in ./cache_actions.rules.inc
_cache_actions_get_panes in ./cache_actions.rules.inc
Get Panel Panes.
1 string reference to '_cache_actions_get_panels_handlers'
cache_actions_rules_action_info in ./cache_actions.rules.inc
Implementation of hook_rules_action_info().

File

./cache_actions.rules.inc, line 207
This file provides the rules integration for this module.

Code

function _cache_actions_get_panels_handlers($panes = FALSE) {
  $available_handlers = array();
  $available_panes = array();
  $js_structure = array();

  // First, get all tasks. This corresponds to all types of page manager pages
  // that can be used, for for instance pages, node view, node edit...
  $tasks = page_manager_get_tasks();
  foreach ($tasks as $task) {

    // Subtasks are tasks that are created under the primary tasks, for instance
    // a custom page the user has created.
    $subtasks = page_manager_get_task_subtasks($task);

    // If we have subtasks, then that's what we're after.
    if (count($subtasks)) {
      foreach ($subtasks as $subtask) {

        // Subtasks have handlers. These can for instance correspond to a panel variant.
        $handlers = page_manager_load_task_handlers($task, $subtask['name']);
        foreach ($handlers as $handler) {

          // handlers have plugins, in this case we need to get the plugin for
          // this handler.
          $plugin = page_manager_get_task_handler($handler->handler);
          $title = page_manager_get_handler_title($plugin, $handler, $task, $subtask['name']);
          $available_handlers[$subtask['admin title']][$handler->name . ':' . $handler->task . ':' . $handler->subtask] = $title;

          // If we want to fetch the panes as well, then go ahead.
          if ($panes) {
            list($handler_panes, $pane_js) = _cache_actions_load_panes($handler, $title, TRUE);
            $available_panes += $handler_panes;
            $js_structure += $pane_js;
          }
        }
      }
    }
    else {
      $handlers = page_manager_load_task_handlers($task);
      if (count($handlers)) {
        foreach ($handlers as $handler) {
          $plugin = page_manager_get_task_handler($handler->handler);
          $title = page_manager_get_handler_title($plugin, $handler, $task, $subtask['name']);

          // If not, then we have an in-code display. Save off the name, so we can get it.
          $available_handlers[$task['admin title']][$handler->name . ':' . $handler->task] = $title;
          if ($panes) {
            list($handler_panes, $pane_js) = _cache_actions_load_panes($handler, $title, TRUE);
            $available_panes += $handler_panes;
            $js_structure += $pane_js;
          }
        }
      }
    }
  }

  // Return an array if we want the panes.
  if ($panes) {
    return array(
      'handlers' => $available_handlers,
      'panes' => $available_panes,
      'js' => $js_structure,
    );
  }

  // Otherwise just return the handlers.
  return $available_handlers;
}