You are here

function page_manager_load_task_handlers in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 page_manager/page_manager.module \page_manager_load_task_handlers()

Load all task handlers for a given task/subtask.

4 calls to page_manager_load_task_handlers()
page_manager_load_sorted_handlers in page_manager/page_manager.module
Load all task handlers for a given task and subtask and sort them.
page_manager_page_delete in page_manager/plugins/tasks/page.inc
Remove a page subtask.
page_manager_page_export in page_manager/plugins/tasks/page.inc
Export a page subtask.
page_manager_page_save in page_manager/plugins/tasks/page.inc
Write a page subtask to the database.

File

page_manager/page_manager.module, line 525
The page manager module provides a UI and API to manage pages.

Code

function page_manager_load_task_handlers($task, $subtask_id = NULL, $default_handlers = NULL) {
  ctools_include('export');
  $conditions = array(
    'task' => $task['name'],
  );
  if (isset($subtask_id)) {
    $conditions['subtask'] = $subtask_id;
  }
  $handlers = ctools_export_load_object('page_manager_handlers', 'conditions', $conditions);
  $defaults = isset($default_handlers) ? $default_handlers : page_manager_get_default_task_handlers($task, $subtask_id);
  foreach ($defaults as $name => $default) {
    $result = page_manager_compare_task_handlers($handlers, $defaults, $name);
    if ($result) {
      $handlers[$name] = $result;

      // Ensure task and subtask are correct, because it's easy to change task
      // names when editing a default and fail to do it on the associated handlers.
      $result->task = $task['name'];
      $result->subtask = $subtask_id;
    }
  }

  // Override weights from the weight table.
  if ($handlers) {
    $names = array();
    $placeholders = array();
    foreach ($handlers as $handler) {
      $names[] = $handler->name;
      $placeholders[] = "'%s'";
    }
    $result = db_query('SELECT name, weight FROM {page_manager_weights} WHERE name IN (:names)', array(
      ':names' => $names,
    ));
    foreach ($result as $weight) {
      $handlers[$weight->name]->weight = $weight->weight;
    }
  }
  return $handlers;
}