View source
<?php
function page_manager_node_edit_page_manager_tasks() {
return array(
'task type' => 'page',
'title' => t('Node add/edit form'),
'admin title' => t('Node add/edit form'),
'admin description' => t('When enabled, this overrides the default Drupal behavior for adding or edit nodes at <em>node/%node/edit</em> and <em>node/add/%node_type</em>. If you add variants, you may use selection criteria such as node type or language or user access to provide different edit forms for nodes. If no variant is selected, the default Drupal node edit will be used.'),
'admin path' => 'node/%node/edit',
'hook menu' => 'page_manager_node_edit_menu',
'hook menu alter' => 'page_manager_node_edit_menu_alter',
'handler type' => 'context',
'get arguments' => 'page_manager_node_edit_get_arguments',
'get context placeholders' => 'page_manager_node_edit_get_contexts',
'disabled' => variable_get('page_manager_node_edit_disabled', TRUE),
'enable callback' => 'page_manager_node_edit_enable',
);
}
function page_manager_node_edit_menu_alter(&$items, $task) {
if (variable_get('page_manager_node_edit_disabled', TRUE)) {
return;
}
$callback = $items['node/%node/edit']['page callback'];
if ($callback == 'node_page_edit' || variable_get('page_manager_override_anyway', FALSE)) {
$items['node/%node/edit']['page callback'] = 'page_manager_node_edit';
$items['node/%node/edit']['file path'] = $task['path'];
$items['node/%node/edit']['file'] = $task['file'];
}
else {
variable_set('page_manager_node_edit_disabled', TRUE);
if (!empty($GLOBALS['page_manager_enabling_node_edit'])) {
drupal_set_message(t('Page manager module is unable to enable node/%node/edit because some other module already has overridden with %callback.', array(
'%callback' => $callback,
)), 'warning');
}
return;
}
foreach (node_get_types('types', NULL, TRUE) as $type) {
$path = 'node/add/' . str_replace('_', '-', $type->type);
if ($items[$path]['page callback'] != 'node_add') {
if (!empty($GLOBALS['page_manager_enabling_node_edit'])) {
drupal_set_message(t('Page manager module is unable to override @path because some other module already has overridden with %callback. Node edit will be enabled but that edit path will not be overridden.', array(
'@path' => $path,
'%callback' => $items[$path]['page callback'],
)), 'warning');
}
continue;
}
$items[$path]['page callback'] = 'page_manager_node_add';
$items[$path]['file path'] = $task['path'];
$items[$path]['file'] = $task['file'];
$items[$path]['page arguments'] = array(
$type->type,
);
}
}
function page_manager_node_edit($node) {
$task = page_manager_get_task('node_edit');
ctools_include('context');
ctools_include('context-task-handler');
$contexts = ctools_context_handler_get_task_contexts($task, '', array(
$node,
));
$arg = array(
isset($node->nid) ? $node->nid : $node->type,
);
$output = ctools_context_handler_render($task, '', $contexts, $arg);
if ($output === FALSE) {
$context = current($contexts);
$output = drupal_render_form($context->form_id, $context->form);
}
return $output;
}
function page_manager_node_add($type) {
global $user;
$types = node_get_types();
$node = (object) array(
'uid' => $user->uid,
'name' => isset($user->name) ? $user->name : '',
'type' => $type,
'language' => '',
);
drupal_set_title(t('Create @name', array(
'@name' => $types[$type]->name,
)));
return page_manager_node_edit($node);
}
function page_manager_node_edit_get_arguments($task, $subtask_id) {
return array(
array(
'keyword' => 'node',
'identifier' => t('Node being edited'),
'id' => 1,
'name' => 'node_edit',
'settings' => array(),
),
);
}
function page_manager_node_edit_get_contexts($task, $subtask_id) {
return ctools_context_get_placeholders_from_argument(page_manager_node_edit_get_arguments($task, $subtask_id));
}
function page_manager_node_edit_enable($cache, $status) {
variable_set('page_manager_node_edit_disabled', $status);
if (!$status) {
$GLOBALS['page_manager_enabling_node_edit'] = TRUE;
}
}