function page_manager_render_operations in Chaos Tool Suite (ctools) 6
Same name and namespace in other branches
- 7 page_manager/page_manager.admin.inc \page_manager_render_operations()
Render an operations array.
This renders an array of operations into a series of nested UL statements, with ajax automatically on unless specified otherwise. Operations will automatically have the URLs generated nested.
Each operation should have a 'type', which tells the renderer how to deal with it:
- 'operation': An AJAX link to render. This is the default and is assumed if a type is not specified. Other fields for the operation:
- - 'title': The text to display. Can be an image. Must be pre-sanitized.
- - 'description': Text to place in the hover box over the link using the title attribute.
- - 'arguments': Anything optional to put at the end of the URL.
- - 'path': If set, overrides the default path.
- - 'no operations': If set, the path will not have operations appended.
- - 'no task': If set, the path will not have the task id.
- - 'no link': If set, this item will just be text, not a link.
- - 'ajax': If set to TRUE, ajax will be used. The default is TRUE.
- - 'class': An optional class to specify for the link.
- - 'form': The form to display for this operation, if using a single form.
- - 'forms': An array of forms that must be paired with 'order' of this operation uses multiple forms. See wizard tool for details.
- - 'order': The form order to use for multiple forms. See wizard tool for details.
- - 'form info': Form info overrides for the wizard. See the wizard tool for available settings
- 'group':
- - 'title': The title of the link. May be HTML.
- - 'title class': A class to apply to the title.
- - 'children': An array of more operations that this group represents. All operations within this group will have this group's ID as part of the AJAX url to make it easier to find.
- - 'class': A class to apply to the UL of the children.
- - 'collapsible': If TRUE the collapsible tool will be used.
3 calls to page_manager_render_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 1084 - Administrative functions for the page manager.
Code
function page_manager_render_operations(&$page, $operations, $active_trail, $attributes, $location, $parents = array()) {
if (!isset($output[$location])) {
$output[$location] = '';
}
$keys = array_keys($operations);
$first = array_shift($keys);
$last = array_pop($keys);
// Make sure the 'first' and 'last' operations are part of THIS nav tree:
while ($keys && isset($operations[$first]['location']) && $operations[$first]['location'] != $location) {
$first = array_shift($keys);
}
while ($keys && isset($operations[$last]['location']) && $operations[$last]['location'] != $location) {
$last = array_pop($keys);
}
$active = reset($active_trail);
foreach ($operations as $id => $operation) {
$current_path = '';
if ($parents) {
$current_path .= implode('/', $parents) . '/';
}
$current_path .= $id;
if (empty($operation['type'])) {
$operation['type'] = 'operation';
}
// We only render an li for things in the same nav tree.
if (empty($operation['location']) || $operation['location'] == $location) {
$class = $attributes['class'];
if ($id == $first) {
$class .= ' operation-first';
}
else {
if ($id == $last) {
$class .= ' operation-last';
}
}
if (empty($operation['silent']) && !empty($page->changes[$current_path])) {
$class .= $operation['type'] == 'group' ? ' changed-group' : ' changed';
}
else {
$class .= ' not-changed';
}
if ($active == $id) {
$class .= $operation['type'] == 'group' ? ' active-group' : ' active';
}
else {
$class .= ' not-active';
}
$output[$location] .= '<li class="' . $class . '">';
}
switch ($operation['type']) {
case 'text':
$output[$location] .= $operation['title'];
break;
case 'operation':
$path = isset($operation['path']) ? $operation['path'] : 'admin/build/pages/nojs/operation';
if (!isset($operation['no task'])) {
$path .= '/' . $page->task_name;
}
if (!isset($operation['no operations'])) {
$path .= '/' . $current_path;
if (isset($operation['arguments'])) {
$path .= '/' . $arguments;
}
}
$class = 'page-manager-operation';
if (!isset($operation['ajax']) || !empty($operation['ajax'])) {
$class .= ' ctools-use-ajax';
}
if (!empty($operation['class'])) {
$class .= ' ' . $operation['class'];
}
$description = isset($operation['description']) ? $operation['description'] : '';
if (empty($operation['silent']) && !empty($page->changes[$current_path])) {
$description .= ' ' . t('This setting contains unsaved changes.');
}
$output[$location] .= l($operation['title'], $path, array(
'attributes' => array(
'id' => 'page-manager-operation-' . $id,
'class' => $class,
'title' => $description,
),
'html' => TRUE,
));
break;
case 'group':
if ($active == $id) {
$trail = $active_trail;
array_shift($trail);
}
else {
$trail = array();
}
$group_location = isset($operation['location']) ? $operation['location'] : $location;
$temp = page_manager_render_operations($page, $operation['children'], $trail, $operation, $group_location, array_merge($parents, array(
$id,
)));
if ($temp) {
foreach ($temp as $id => $text) {
if (empty($output[$id])) {
$output[$id] = '';
}
$output[$id] .= $text;
}
}
break;
}
if (empty($operation['location']) || $operation['location'] == $location) {
$output[$location] .= '</li>';
}
}
if ($output[$location]) {
$output[$location] = '<ul class="page-manager-operations ' . $attributes['class'] . '">' . $output[$location] . '</ul>';
if (!empty($attributes['title'])) {
$class = '';
if (isset($attributes['title class'])) {
$class = $attributes['title class'];
}
$title = '<div class="page-manager-group-title' . $class . '">' . $attributes['title'] . '</div>';
if (!empty($attributes['collapsible'])) {
$output[$location] = theme('ctools_collapsible', $title, $output[$location], empty($active_trail));
}
else {
$output[$location] = $title . $output[$location];
}
}
return $output;
}
}