function page_manager_get_operations in Chaos Tool Suite (ctools) 6
Same name and namespace in other branches
- 7 page_manager/page_manager.admin.inc \page_manager_get_operations()
Take the operations array from a task and expand it.
This allows some of the operations to be dynamic, based upon settings on the task or the task's handlers. Each operation should have a type. In addition to all the types allowed in page_manager_render_operations, these types will be dynamically replaced with something else:
- 'handlers': An automatically created group that contains all the task's handlers and appropriate links.
- 'function': A callback (which will be placed in the 'function' parameter that should return an array of operations. This can be used to provide additional, dynamic links if needed.
3 calls to page_manager_get_operations()
- page_manager_edit_page in page_manager/
page_manager.admin.inc - Render the edit page for a a page, custom or system.
- page_manager_edit_page_operation in page_manager/
page_manager.admin.inc - Entry point to edit a single operation for a page.
- page_manager_http_response_admin_summary in page_manager/
plugins/ task_handlers/ http_response.inc
File
- page_manager/
page_manager.admin.inc, line 469 - Administrative functions for the page manager.
Code
function page_manager_get_operations($page, $operations = NULL) {
if (!isset($operations)) {
// All tasks have at least these 2 ops:
$operations = array(
'summary' => array(
'title' => t('Summary'),
'description' => t('Get a summary of the information about this page.'),
'path' => 'admin/build/pages/edit',
'ajax' => FALSE,
'no operations' => TRUE,
'form info' => array(
'no buttons' => TRUE,
),
'form' => 'page_manager_page_summary',
),
'actions' => array(
'type' => 'group',
'title' => '',
'class' => 'operations-actions',
'location' => 'primary',
'children' => array(),
),
);
if (isset($page->subtask['operations'])) {
$operations += $page->subtask['operations'];
// add actions separately.
if (!empty($page->subtask['operations']['actions'])) {
$operations['actions']['children'] += $page->subtask['operations']['actions']['children'];
}
}
$operations['handlers'] = array(
'type' => 'handlers',
);
}
$result = array();
foreach ($operations as $id => $operation) {
if (empty($operation['type'])) {
$operation['type'] = 'operation';
}
switch ($operation['type']) {
case 'handlers':
$result[$id] = page_manager_get_handler_operations($page);
break;
case 'function':
if (function_exists($operation['function'])) {
$retval = $function($page, $operation);
if (is_array($retval)) {
$result[$id] = $retval;
}
}
break;
default:
$result[$id] = $operation;
}
}
if (!empty($page->subtask['enable callback']) && !empty($page->subtask['disabled']) && empty($result['actions']['children']['enable'])) {
$result['actions']['children']['enable'] = array(
'title' => t('Enable'),
'description' => t('Activate this page so that it will be in use in your system.'),
'form' => 'page_manager_enable_form',
'ajax' => FALSE,
'silent' => TRUE,
'no update and save' => TRUE,
'form info' => array(
'finish text' => t('Enable'),
),
);
}
if (!empty($page->subtask['enable callback']) && empty($page->subtask['disabled']) && empty($result['actions']['children']['disable'])) {
$result['actions']['children']['disable'] = array(
'title' => t('Disable'),
'description' => t('De-activate this page. The data will remain but the page will not be in use on your system.'),
'form' => 'page_manager_disable_form',
'ajax' => FALSE,
'silent' => TRUE,
'no update and save' => TRUE,
'form info' => array(
'finish text' => t('Disable'),
),
);
}
$result['actions']['children']['add'] = array(
'title' => t('Add variant'),
'description' => t('Add a new variant to this page.'),
'form' => 'page_manager_handler_add',
'ajax' => FALSE,
'silent' => TRUE,
// prevents a message about updating and prevents this item from showing as changed.
'no update and save' => TRUE,
// get rid of update and save button which is bad here.
'form info' => array(
'finish text' => t('Create variant'),
),
);
// Restrict variant import to users who can already execute arbitrary PHP
if (user_access('use PHP for block visibility')) {
$result['actions']['children']['import'] = array(
'title' => t('Import variant'),
'description' => t('Add a new variant to this page from code exported from another page.'),
'form' => 'page_manager_handler_import',
);
}
if (count($page->handlers) > 1) {
$result['actions']['children']['rearrange'] = array(
'title' => t('Reorder variants'),
'ajax' => FALSE,
'description' => t('Change the priority of the variants to ensure that the right one gets selected.'),
'form' => 'page_manager_handler_rearrange',
);
}
// This is a special operation used to configure a new task handler before
// it is added.
if (isset($page->new_handler)) {
$plugin = page_manager_get_task_handler($page->new_handler->handler);
$result['actions']['children']['configure'] = array(
'title' => t('Configure'),
'description' => t('Configure a newly created variant prior to actually adding it to the page.'),
'ajax' => FALSE,
'no update and save' => TRUE,
// get rid of update and save button which is bad here.
'form info' => array(
// We use our own cancel and finish callback to handle the fun stuff.
'finish callback' => 'page_manager_handler_add_finish',
'cancel callback' => 'page_manager_handler_add_cancel',
'show trail' => TRUE,
'show back' => TRUE,
'finish text' => t('Create variant'),
),
'form' => array(
'forms' => $plugin['forms'],
),
);
foreach ($page->forms as $id) {
if (isset($plugin['add features'][$id])) {
$result['actions']['children']['configure']['form']['order'][$id] = $plugin['add features'][$id];
}
else {
if (isset($plugin['required forms'][$id])) {
$result['actions']['children']['configure']['form']['order'][$id] = $plugin['required forms'][$id];
}
}
}
}
if ($page->locked) {
$result['actions']['children']['break-lock'] = array(
'title' => t('Break lock'),
'description' => t('Break the lock on this page so that you can edit it.'),
'form' => 'page_manager_break_lock',
'ajax' => FALSE,
'no update and save' => TRUE,
// get rid of update and save button which is bad here.
'form info' => array(
'finish text' => t('Break lock'),
),
'even locked' => TRUE,
// show button even if locked
'silent' => TRUE,
);
}
drupal_alter('page_manager_operations', $result, $page);
return $result;
}