first import
This commit is contained in:
70
sites/all/modules/ctools/page_manager/plugins/cache/page_manager_context.inc
vendored
Normal file
70
sites/all/modules/ctools/page_manager/plugins/cache/page_manager_context.inc
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* A page_manager cache indirection mechanism that just attaches context
|
||||
* caching to the larger page cache.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
// cache plugins are the rare plugin types that have no real UI but
|
||||
// we're providing a title just in case.
|
||||
'title' => t('Page manager context'),
|
||||
'cache get' => 'page_manager_cache_page_manager_context_cache_get',
|
||||
'cache set' => 'page_manager_cache_page_manager_context_cache_set',
|
||||
'cache finalize' => 'page_manager_cache_page_manager_context_cache_finalize',
|
||||
|
||||
// We don't support a clear because the general uses of clear have no effect
|
||||
// on us.
|
||||
);
|
||||
|
||||
function page_manager_cache_page_manager_context_cache_get($data, $key) {
|
||||
$page = page_manager_get_page_cache($data);
|
||||
if ($page) {
|
||||
if (!empty($page->context_cache[$key])) {
|
||||
return $page->context_cache[$key];
|
||||
}
|
||||
else {
|
||||
ctools_include('context-task-handler');
|
||||
if ($key == 'temp') {
|
||||
$handler = $page->new_handler;
|
||||
}
|
||||
else {
|
||||
$handler = $page->handlers[$key];
|
||||
}
|
||||
return ctools_context_handler_get_task_object($page->task, $page->subtask, $handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function page_manager_cache_page_manager_context_cache_set($data, $key, $object) {
|
||||
$page = page_manager_get_page_cache($data);
|
||||
if ($page) {
|
||||
$page->context_cache[$key] = $object;
|
||||
return page_manager_set_page_cache($page);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy temporary data from the page manager cache
|
||||
*/
|
||||
function page_manager_cache_page_manager_context_cache_finalize($data, $key, $object) {
|
||||
// Statically cached so there shouldn't be any worries. It's an object so
|
||||
// referencing ensures that we'll get the right one.
|
||||
$page = page_manager_get_page_cache($data);
|
||||
if ($page) {
|
||||
if ($key == 'temp') {
|
||||
$handler = $page->new_handler;
|
||||
}
|
||||
else {
|
||||
$handler = $page->handlers[$key];
|
||||
}
|
||||
$handler->conf['contexts'] = $object->contexts;
|
||||
$handler->conf['relationships'] = $object->relationships;
|
||||
|
||||
if (isset($page->context_cache[$key])) {
|
||||
unset($page->context_cache[$key]);
|
||||
}
|
||||
return page_manager_set_page_cache($page);
|
||||
}
|
||||
}
|
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* This is the task handler plugin to handle generating 403, 404 and 301 response codes.
|
||||
*/
|
||||
|
||||
// Plugin definition
|
||||
$plugin = array(
|
||||
// is a 'context' handler type, meaning it supports the API of the
|
||||
// context handlers provided by ctools context plugins.
|
||||
'handler type' => 'context',
|
||||
'visible' => TRUE, // may be added up front.
|
||||
|
||||
// Administrative fields.
|
||||
'title' => t('HTTP response code'),
|
||||
'admin summary' => 'page_manager_http_response_admin_summary',
|
||||
'admin title' => 'page_manager_http_response_title',
|
||||
'operations' => array(
|
||||
'settings' => array(
|
||||
'title' => t('General'),
|
||||
'description' => t('Change general settings for this variant.'),
|
||||
'form' => 'page_manager_http_response_edit_settings',
|
||||
),
|
||||
'criteria' => array(
|
||||
'title' => t('Selection rules'),
|
||||
'description' => t('Control the criteria used to decide whether or not this variant is used.'),
|
||||
'ajax' => FALSE,
|
||||
'form' => array(
|
||||
'order' => array(
|
||||
'form' => t('Selection rules'),
|
||||
),
|
||||
'forms' => array(
|
||||
'form' => array(
|
||||
'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
|
||||
'form id' => 'ctools_context_handler_edit_criteria',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'context' => array(
|
||||
'title' => t('Contexts'),
|
||||
'ajax' => FALSE,
|
||||
'description' => t('Add additional context objects to this variant that can be used by the content.'),
|
||||
'form' => array(
|
||||
'order' => array(
|
||||
'form' => t('Context'),
|
||||
),
|
||||
'forms' => array(
|
||||
'form' => array(
|
||||
'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
|
||||
'form id' => 'ctools_context_handler_edit_context',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Callback to render the data.
|
||||
'render' => 'page_manager_http_response_render',
|
||||
|
||||
'add features' => array(
|
||||
'criteria' => t('Selection rules'),
|
||||
'context' => t('Contexts'),
|
||||
),
|
||||
// Where to go when finished.
|
||||
'add finish' => 'settings',
|
||||
|
||||
'required forms' => array(
|
||||
'settings' => t('Panel settings'),
|
||||
),
|
||||
|
||||
'edit forms' => array(
|
||||
'criteria' => t('Selection rules'),
|
||||
'settings' => t('General'),
|
||||
'context' => t('Contexts'),
|
||||
),
|
||||
'forms' => array(
|
||||
'settings' => array(
|
||||
'form id' => 'page_manager_http_response_edit_settings',
|
||||
),
|
||||
'context' => array(
|
||||
'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
|
||||
'form id' => 'ctools_context_handler_edit_context',
|
||||
),
|
||||
'criteria' => array(
|
||||
'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
|
||||
'form id' => 'ctools_context_handler_edit_criteria',
|
||||
),
|
||||
),
|
||||
'default conf' => array(
|
||||
'title' => t('HTTP response code'),
|
||||
'contexts' => array(),
|
||||
'relationships' => array(),
|
||||
'code' => '404',
|
||||
'destination' => '',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Provide a list of the response codes we support.
|
||||
*
|
||||
* Abstracted so it can be more readily used both on input and output.
|
||||
*/
|
||||
function page_manager_http_response_codes() {
|
||||
return array(
|
||||
404 => t('404 Page not found'),
|
||||
403 => t('403 Access denied'),
|
||||
301 => t('301 Redirect'),
|
||||
);
|
||||
}
|
||||
|
||||
function page_manager_http_response_admin_summary($handler, $task, $subtask, $page, $show_title = TRUE) {
|
||||
$task_name = page_manager_make_task_name($task['name'], $subtask['name']);
|
||||
$output = '';
|
||||
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
|
||||
// Get the operations
|
||||
$operations = page_manager_get_operations($page);
|
||||
|
||||
// Get operations for just this handler.
|
||||
$operations = $operations['handlers']['children'][$handler->name]['children']['actions']['children'];
|
||||
$args = array('handlers', $handler->name, 'actions');
|
||||
$rendered_operations = page_manager_render_operations($page, $operations, array(), array('class' => array('actions')), 'actions', $args);
|
||||
|
||||
$plugin = page_manager_get_task_handler($handler->handler);
|
||||
|
||||
$object = ctools_context_handler_get_task_object($task, $subtask, $handler);
|
||||
$context = ctools_context_load_contexts($object, TRUE);
|
||||
|
||||
$access = ctools_access_group_summary(!empty($handler->conf['access']) ? $handler->conf['access'] : array(), $context);
|
||||
if ($access) {
|
||||
$access = t('This panel will be selected if @conditions.', array('@conditions' => $access));
|
||||
}
|
||||
else {
|
||||
$access = t('This panel will always be selected.');
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
|
||||
$type = $handler->type == t('Default') ? t('In code') : $handler->type;
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Storage')),
|
||||
array('class' => array('page-summary-data'), 'data' => $type),
|
||||
array('class' => array('page-summary-operation'), 'data' => ''),
|
||||
);
|
||||
|
||||
if (!empty($handler->disabled)) {
|
||||
$link = l(t('Enable'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'actions', 'enable')));
|
||||
$text = t('Disabled');
|
||||
}
|
||||
else {
|
||||
$link = l(t('Disable'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'actions', 'disable')));
|
||||
$text = t('Enabled');
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Status')),
|
||||
array('class' => array('page-summary-data'), 'data' => $text),
|
||||
array('class' => array('page-summary-operation'), 'data' => $link),
|
||||
);
|
||||
|
||||
$link = l(t('Edit'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'criteria')));
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Selection rule')),
|
||||
array('class' => array('page-summary-data'), 'data' => $access),
|
||||
array('class' => array('page-summary-operation'), 'data' => $link),
|
||||
);
|
||||
|
||||
$link = l(t('Edit'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'settings')));
|
||||
$codes = page_manager_http_response_codes();
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Response code')),
|
||||
array('class' => array('page-summary-data'), 'data' => $codes[$handler->conf['code']]),
|
||||
array('class' => array('page-summary-operation'), 'data' => $link),
|
||||
);
|
||||
|
||||
$info = theme('table', array('header' => array(), 'rows' => $rows, 'attributes' => array('class' => array('page-manager-handler-summary'))));
|
||||
|
||||
$title = $handler->conf['title'];
|
||||
if ($title != t('Panel')) {
|
||||
$title = t('Panel: @title', array('@title' => $title));
|
||||
}
|
||||
|
||||
$output .= '<div class="clearfix">';
|
||||
if ($show_title) {
|
||||
$output .= '<div class="handler-title clearfix">';
|
||||
$output .= '<div class="actions handler-actions">' . $rendered_operations['actions'] . '</div>';
|
||||
$output .= '<span class="title-label">' . $title . '</span>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
$output .= $info;
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up a title for the panel based upon the selection rules.
|
||||
*/
|
||||
function page_manager_http_response_title($handler, $task, $subtask) {
|
||||
if (isset($handler->conf['title'])) {
|
||||
return check_plain($handler->conf['title']);
|
||||
}
|
||||
else {
|
||||
return t('HTTP response code');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* General settings for the panel
|
||||
*/
|
||||
function page_manager_http_response_edit_settings($form, &$form_state) {
|
||||
$conf = $form_state['handler']->conf;
|
||||
$form['title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $conf['title'],
|
||||
'#title' => t('Administrative title'),
|
||||
'#description' => t('Administrative title of this variant.'),
|
||||
);
|
||||
|
||||
$form['code'] = array(
|
||||
'#title' => t('Response code'),
|
||||
'#type' => 'select',
|
||||
'#options' => page_manager_http_response_codes(),
|
||||
'#default_value' => $conf['code'],
|
||||
);
|
||||
|
||||
ctools_include('dependent');
|
||||
$form['destination'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Redirect destination'),
|
||||
'#default_value' => $conf['destination'],
|
||||
'#dependency' => array('edit-code' => array(301)),
|
||||
'#description' => t('Enter the path to redirect to. You may use keyword substitutions from contexts. You can use external urls (http://www.example.com/foo) or internal urls (node/1).'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function page_manager_http_response_edit_settings_submit($form, &$form_state) {
|
||||
$form_state['handler']->conf['title'] = $form_state['values']['title'];
|
||||
$form_state['handler']->conf['code'] = $form_state['values']['code'];
|
||||
$form_state['handler']->conf['destination'] = $form_state['values']['destination'];
|
||||
}
|
||||
|
||||
function page_manager_http_response_render($handler, $base_contexts, $args, $test = TRUE) {
|
||||
// Go through arguments and see if they match.
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
|
||||
// Add my contexts
|
||||
$contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler);
|
||||
|
||||
// Test.
|
||||
if ($test && !ctools_context_handler_select($handler, $contexts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($handler->handler)) {
|
||||
ctools_context_handler_pre_render($handler, $contexts, $args);
|
||||
}
|
||||
|
||||
$info['response code'] = $handler->conf['code'];
|
||||
if ($info['response code'] == 301) {
|
||||
$path = ctools_context_keyword_substitute($handler->conf['destination'], array(), $contexts);
|
||||
$url = parse_url($path);
|
||||
if (isset($url['query'])) {
|
||||
$path = strtr($path, array('?' . $url['query'] => ''));
|
||||
$info['query'] = drupal_get_query_array($url['query']);
|
||||
}
|
||||
if (isset($url['fragment'])) {
|
||||
$path = strtr($path, array('#' . $url['fragment'] => ''));
|
||||
$info['fragment'] = $url['fragment'];
|
||||
}
|
||||
|
||||
$info['destination'] = rtrim($path, '?');
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
121
sites/all/modules/ctools/page_manager/plugins/tasks/blog.inc
Normal file
121
sites/all/modules/ctools/page_manager/plugins/tasks/blog.inc
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_blog_page_manager_tasks() {
|
||||
if (!module_exists('blog')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
|
||||
'title' => t('All blogs'),
|
||||
'admin title' => t('All blogs'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for the all blogs at <em>/blog</em>. If no variant is selected, the default Drupal most recent blog posts will be shown.'),
|
||||
'admin path' => 'blog',
|
||||
|
||||
// Menu hooks so that we can alter the node/%node menu entry to point to us.
|
||||
'hook menu alter' => 'page_manager_blog_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_blog_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_blog_enable',
|
||||
'access callback' => 'page_manager_blog_access_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_blog_page_manager_tasks().
|
||||
*
|
||||
* Alter the node edit input so that node edit comes to us rather than the
|
||||
* normal node edit process.
|
||||
*/
|
||||
function page_manager_blog_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_blog_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$callback = $items['blog']['page callback'];
|
||||
// Override the node edit handler for our purpose.
|
||||
if ($callback == 'blog_page_last' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['blog']['page callback'] = 'page_manager_blog';
|
||||
$items['blog']['file path'] = $task['path'];
|
||||
$items['blog']['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
variable_set('page_manager_blog_disabled', TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_blog'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable blog because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden node edit.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* node edit, which is node_page_edit().
|
||||
*/
|
||||
function page_manager_blog() {
|
||||
// Load my task plugin
|
||||
$task = page_manager_get_task('blog');
|
||||
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
$output = ctools_context_handler_render($task, '', array(), array());
|
||||
if ($output !== FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
module_load_include('inc', 'blog', 'blog.pages');
|
||||
$function = 'blog_page_last';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('blog')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back.
|
||||
return $function();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_blog_enable($cache, $status) {
|
||||
variable_set('page_manager_blog_disabled', $status);
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_blog'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_blog_access_check($task, $subtask_id, $contexts) {
|
||||
return user_access('access content');
|
||||
}
|
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_blog_user_page_manager_tasks() {
|
||||
if (!module_exists('blog')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
'title' => t('User blog'),
|
||||
'admin title' => t('User blog'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying user blogs at <em>blog/%user</em>. If no variant is selected, the default Drupal user blog will be used.'),
|
||||
'admin path' => 'blog/%user',
|
||||
|
||||
// Callback to add items to the page managertask administration form:
|
||||
'task admin' => 'page_manager_blog_user_task_admin',
|
||||
|
||||
'hook menu alter' => 'page_manager_blog_user_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context', // handler type -- misnamed
|
||||
'get arguments' => 'page_manager_blog_user_get_arguments',
|
||||
'get context placeholders' => 'page_manager_blog_user_get_contexts',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_blog_user_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_blog_user_enable',
|
||||
'access callback' => 'page_manager_blog_user_access_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_blog_user_page_manager_tasks().
|
||||
*
|
||||
* Alter the user view input so that user view comes to us rather than the
|
||||
* normal user view process.
|
||||
*/
|
||||
function page_manager_blog_user_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_blog_user_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Override the user view handler for our purpose.
|
||||
if ($items['blog/%user_uid_optional']['page callback'] == 'blog_page_user' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['blog/%user_uid_optional']['page callback'] = 'page_manager_blog_user';
|
||||
$items['blog/%user_uid_optional']['file path'] = $task['path'];
|
||||
$items['blog/%user_uid_optional']['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
// automatically disable this task if it cannot be enabled.
|
||||
variable_set('page_manager_blog_user_disabled', TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_blog_user'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable blog/%user because some other module already has overridden with %callback.', array('%callback' => $items['blog/%user']['page callback'])), 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden user view.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* user view, which is user_page_view().
|
||||
*/
|
||||
function page_manager_blog_user($account) {
|
||||
// Load my task plugin:
|
||||
$task = page_manager_get_task('blog_user');
|
||||
|
||||
// Load the account into a context.
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
$contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
|
||||
|
||||
$output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
|
||||
if ($output !== FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
module_load_include('inc', 'blog', 'blog.pages');
|
||||
$function = 'blog_page_user';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('blog_user')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back.
|
||||
return $function($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get arguments provided by this task handler.
|
||||
*
|
||||
* Since this is the node view and there is no UI on the arguments, we
|
||||
* create dummy arguments that contain the needed data.
|
||||
*/
|
||||
function page_manager_blog_user_get_arguments($task, $subtask_id) {
|
||||
return array(
|
||||
array(
|
||||
'keyword' => 'user',
|
||||
'identifier' => t('User being viewed'),
|
||||
'id' => 1,
|
||||
'name' => 'uid',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get context placeholders provided by this handler.
|
||||
*/
|
||||
function page_manager_blog_user_get_contexts($task, $subtask_id) {
|
||||
return ctools_context_get_placeholders_from_argument(page_manager_blog_user_get_arguments($task, $subtask_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_blog_user_enable($cache, $status) {
|
||||
variable_set('page_manager_blog_user_disabled', $status);
|
||||
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_blog_user'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_blog_user_access_check($task, $subtask_id, $contexts) {
|
||||
$context = reset($contexts);
|
||||
return blog_page_user_access($context->data);
|
||||
}
|
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_comment_reply_page_manager_tasks() {
|
||||
if (!module_exists('comment')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
|
||||
'title' => t('Comment Reply page'),
|
||||
'admin title' => t('Comment Reply page'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for the site contact page at <em>/contact</em>. If no variant is selected, the default Drupal contact form will be used.'),
|
||||
'admin path' => 'comment/reply/%node',
|
||||
|
||||
// Menu hooks so that we can alter the node/%node menu entry to point to us.
|
||||
'hook menu alter' => 'page_manager_comment_reply_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context',
|
||||
'get arguments' => 'page_manager_comment_reply_get_arguments',
|
||||
'get context placeholders' => 'page_manager_comment_reply_get_contexts',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_comment_reply_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_comment_reply_enable',
|
||||
'access callback' => 'page_manager_comment_reply_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_comment_reply_enable($cache, $status) {
|
||||
variable_set('page_manager_comment_reply_disabled', $status);
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_comment_reply'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Entry point for our overridden comment.
|
||||
*
|
||||
*/
|
||||
function page_manager_comment_reply_page($node, $pid = NULL){
|
||||
// Load my task plugin
|
||||
$task = page_manager_get_task('comment_reply');
|
||||
|
||||
// Load the node into a context.
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
|
||||
$contexts = ctools_context_handler_get_task_contexts($task, '', array($node, $pid));
|
||||
|
||||
if (array_key_exists('argument_cid_3', $contexts) && $contexts['argument_cid_3']->data->nid != $node->nid) {
|
||||
// Attempting to reply to a comment not belonging to the current nid.
|
||||
drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
|
||||
drupal_goto("node/$node->nid");
|
||||
}
|
||||
|
||||
$output = ctools_context_handler_render($task, '', $contexts, array($node, $pid));
|
||||
if ($output != FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$function = 'comment_reply';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('comment_reply')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
module_load_include('inc', 'comment', 'comment.pages');
|
||||
return $function($node, $pid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get arguments provided by this task handler.
|
||||
*
|
||||
* Since this is the node view and there is no UI on the arguments, we
|
||||
* create dummy arguments that contain the needed data.
|
||||
*/
|
||||
function page_manager_comment_reply_get_arguments($task, $subtask_id) {
|
||||
return array(
|
||||
array(
|
||||
'keyword' => 'node',
|
||||
'identifier' => t('Node being commented on'),
|
||||
'id' => 2,
|
||||
'name' => 'entity_id:node',
|
||||
'settings' => array(),
|
||||
),
|
||||
array(
|
||||
'keyword' => 'comment',
|
||||
'identifier' => t('Comment being replied to'),
|
||||
'id' => 3,
|
||||
'name' => 'entity_id:comment',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get context placeholders provided by this handler.
|
||||
*/
|
||||
function page_manager_comment_reply_get_contexts($task, $subtask_id) {
|
||||
return ctools_context_get_placeholders_from_argument(page_manager_comment_reply_get_arguments($task, $subtask_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_node_view_page_manager_tasks().
|
||||
*
|
||||
* Alter the node view input so that node view comes to us rather than the
|
||||
* normal node view process.
|
||||
*/
|
||||
function page_manager_comment_reply_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_comment_reply_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
// Override the node view handler for our purpose.
|
||||
$callback = $items['comment/reply/%node']['page callback'];
|
||||
if ($callback == 'comment_reply' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['comment/reply/%node']['page callback'] = 'page_manager_comment_reply_page';
|
||||
$items['comment/reply/%node']['file path'] = $task['path'];
|
||||
$items['comment/reply/%node']['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
// automatically disable this task if it cannot be enabled.
|
||||
variable_set('page_manager_comment_reply_disabled', TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_comment_reply'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable comment/reply/%node because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// @todo override node revision handler as well?
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_comment_reply_access_check($task, $subtask_id, $contexts) {
|
||||
$context = reset($contexts);
|
||||
return TRUE;
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_contact_site_page_manager_tasks() {
|
||||
if (!module_exists('contact')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
|
||||
'title' => t('Site contact page'),
|
||||
'admin title' => t('Site contact page'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for the site contact page at <em>/contact</em>. If no variant is selected, the default Drupal contact form will be used.'),
|
||||
'admin path' => 'contact',
|
||||
|
||||
// Menu hooks so that we can alter the node/%node menu entry to point to us.
|
||||
'hook menu alter' => 'page_manager_contact_site_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_contact_site_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_contact_site_enable',
|
||||
'access callback' => 'page_manager_contact_access_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_contact_site_page_manager_tasks().
|
||||
*
|
||||
* Alter the node edit input so that node edit comes to us rather than the
|
||||
* normal node edit process.
|
||||
*/
|
||||
function page_manager_contact_site_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_contact_site_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$callback = $items['contact']['page callback'];
|
||||
if ($callback == 'drupal_get_form') {
|
||||
$callback = $items['contact']['page arguments'][0];
|
||||
}
|
||||
|
||||
// Override the node edit handler for our purpose.
|
||||
if ($callback == 'contact_site_form' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['contact']['page callback'] = 'page_manager_contact_site';
|
||||
$items['contact']['file path'] = $task['path'];
|
||||
$items['contact']['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
variable_set('page_manager_contact_site_disabled', TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_contact_site'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable contact because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden site contact.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* node edit, which is node_page_edit().
|
||||
*/
|
||||
function page_manager_contact_site() {
|
||||
// Load my task plugin
|
||||
$task = page_manager_get_task('contact_site');
|
||||
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
$output = ctools_context_handler_render($task, '', array(), array());
|
||||
if ($output !== FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
module_load_include('inc', 'contact', 'contact.pages');
|
||||
$function = 'contact_site_form';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('contact_site')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back.
|
||||
if ($function == 'contact_site_form') {
|
||||
return drupal_get_form($function);
|
||||
}
|
||||
|
||||
return $function();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_contact_site_enable($cache, $status) {
|
||||
variable_set('page_manager_contact_site_disabled', $status);
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_contact_site'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_contact_access_check($task, $subtask_id, $contexts) {
|
||||
return user_access('access site-wide contact form');
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_contact_user_page_manager_tasks() {
|
||||
if (!module_exists('contact')) {
|
||||
return;
|
||||
}
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
'title' => t('User contact'),
|
||||
'admin title' => t('User contact'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying the user contact form at <em>user/%user/contact</em>. If no variant is selected, the default Drupal user contact form will be used.'),
|
||||
'admin path' => 'user/%user/contact',
|
||||
|
||||
// Callback to add items to the page managertask administration form:
|
||||
'task admin' => 'page_manager_contact_user_task_admin',
|
||||
|
||||
'hook menu alter' => 'page_manager_contact_user_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context', // handler type -- misnamed
|
||||
'get arguments' => 'page_manager_contact_user_get_arguments',
|
||||
'get context placeholders' => 'page_manager_contact_user_get_contexts',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_contact_user_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_contact_user_enable',
|
||||
'access callback' => 'page_manager_contact_user_access_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_contact_user_page_manager_tasks().
|
||||
*
|
||||
* Alter the user view input so that user view comes to us rather than the
|
||||
* normal user view process.
|
||||
*/
|
||||
function page_manager_contact_user_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_contact_user_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
$callback = $items['user/%user/contact']['page callback'];
|
||||
if ($callback == 'drupal_get_form') {
|
||||
$callback = $items['user/%user/contact']['page arguments'][0];
|
||||
}
|
||||
|
||||
// Override the user view handler for our purpose.
|
||||
if ($callback == 'contact_personal_form' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['user/%user/contact']['page callback'] = 'page_manager_contact_user';
|
||||
$items['user/%user/contact']['file path'] = $task['path'];
|
||||
$items['user/%user/contact']['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
// automatically disable this task if it cannot be enabled.
|
||||
variable_set('page_manager_contact_user_disabled', TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_contact_user'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable user/%user/contact because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden user view.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* user view, which is user_page_view().
|
||||
*/
|
||||
function page_manager_contact_user($form_id, $account) {
|
||||
// Load my task plugin:
|
||||
$task = page_manager_get_task('contact_user');
|
||||
|
||||
// Load the account into a context.
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
$contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
|
||||
|
||||
$output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
|
||||
if ($output !== FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
module_load_include('inc', 'contact', 'contact.pages');
|
||||
$function = 'contact_personal_form';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('contact_user')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back.
|
||||
return drupal_get_form($function, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get arguments provided by this task handler.
|
||||
*
|
||||
* Since this is the node view and there is no UI on the arguments, we
|
||||
* create dummy arguments that contain the needed data.
|
||||
*/
|
||||
function page_manager_contact_user_get_arguments($task, $subtask_id) {
|
||||
return array(
|
||||
array(
|
||||
'keyword' => 'user',
|
||||
'identifier' => t('User being viewed'),
|
||||
'id' => 1,
|
||||
'name' => 'uid',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get context placeholders provided by this handler.
|
||||
*/
|
||||
function page_manager_contact_user_get_contexts($task, $subtask_id) {
|
||||
return ctools_context_get_placeholders_from_argument(page_manager_contact_user_get_arguments($task, $subtask_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_contact_user_enable($cache, $status) {
|
||||
variable_set('page_manager_contact_user_disabled', $status);
|
||||
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_contact_user'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_blog_contact_user_access_check($task, $subtask_id, $contexts) {
|
||||
$context = reset($contexts);
|
||||
return _contact_personal_tab_access($context->data);
|
||||
}
|
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_node_edit_page_manager_tasks() {
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'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',
|
||||
|
||||
// Menu hooks so that we can alter the node/%node menu entry to point to us.
|
||||
'hook menu' => 'page_manager_node_edit_menu',
|
||||
'hook menu alter' => 'page_manager_node_edit_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context',
|
||||
'get arguments' => 'page_manager_node_edit_get_arguments',
|
||||
'get context placeholders' => 'page_manager_node_edit_get_contexts',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_node_edit_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_node_edit_enable',
|
||||
'access callback' => 'page_manager_node_edit_access_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_node_edit_page_manager_tasks().
|
||||
*
|
||||
* Alter the node edit input so that node edit comes to us rather than the
|
||||
* normal node edit process.
|
||||
*/
|
||||
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'];
|
||||
// Override the node edit handler for our purpose.
|
||||
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;
|
||||
}
|
||||
|
||||
// Also catch node/add handling:
|
||||
foreach (node_type_get_types() 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'];
|
||||
// Why str_replace things back?
|
||||
$items[$path]['page arguments'] = array($type->type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden node edit.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* node edit, which is node_page_edit().
|
||||
*/
|
||||
function page_manager_node_edit($node) {
|
||||
// Load my task plugin
|
||||
$task = page_manager_get_task('node_edit');
|
||||
|
||||
// Load the node into a context.
|
||||
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) {
|
||||
// Fall back!
|
||||
// We've already built the form with the context, so we can't build it again, or
|
||||
// form_clean_id will mess up our ids. But we don't really need to, either:
|
||||
$context = reset($contexts);
|
||||
$output = $context->form;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to handle the process of adding a node.
|
||||
*
|
||||
* This creates a basic $node and passes that off to page_manager_node_edit().
|
||||
* It is modeled after Drupal's node_add() function.
|
||||
*
|
||||
* Unlike node_add() we do not need to check node_access because that was
|
||||
* already checked by the menu system.
|
||||
*/
|
||||
function page_manager_node_add($type) {
|
||||
global $user;
|
||||
|
||||
$types = node_type_get_types();
|
||||
|
||||
// Initialize settings:
|
||||
$node = (object) array(
|
||||
'uid' => $user->uid,
|
||||
'name' => (isset($user->name) ? $user->name : ''),
|
||||
'type' => $type,
|
||||
'language' => LANGUAGE_NONE,
|
||||
);
|
||||
|
||||
drupal_set_title(t('Create @name', array('@name' => $types[$type]->name)));
|
||||
return page_manager_node_edit($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get arguments provided by this task handler.
|
||||
*
|
||||
* Since this is the node edit and there is no UI on the arguments, we
|
||||
* create dummy arguments that contain the needed data.
|
||||
*/
|
||||
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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get context placeholders provided by this handler.
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_node_edit_enable($cache, $status) {
|
||||
variable_set('page_manager_node_edit_disabled', $status);
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_node_edit'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_node_edit_access_check($task, $subtask_id, $contexts) {
|
||||
$context = reset($contexts);
|
||||
return node_access('update', $context->data);
|
||||
}
|
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handle the 'node view' override task.
|
||||
*
|
||||
* This plugin overrides node/%node and reroutes it to the page manager, where
|
||||
* a list of tasks can be used to service this request based upon criteria
|
||||
* supplied by access plugins.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_node_view_page_manager_tasks() {
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
|
||||
'title' => t('Node template'),
|
||||
|
||||
'admin title' => t('Node template'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying nodes at <em>node/%node</em>. If you add variants, you may use selection criteria such as node type or language or user access to provide different views of nodes. If no variant is selected, the default Drupal node view will be used. This page only affects nodes viewed as pages, it will not affect nodes viewed in lists or at other locations. Also please note that if you are using pathauto, aliases may make a node to be somewhere else, but as far as Drupal is concerned, they are still at node/%node.'),
|
||||
'admin path' => 'node/%node',
|
||||
|
||||
// Menu hooks so that we can alter the node/%node menu entry to point to us.
|
||||
'hook menu' => 'page_manager_node_view_menu',
|
||||
'hook menu alter' => 'page_manager_node_view_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context',
|
||||
'get arguments' => 'page_manager_node_view_get_arguments',
|
||||
'get context placeholders' => 'page_manager_node_view_get_contexts',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_node_view_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_node_view_enable',
|
||||
'access callback' => 'page_manager_node_view_access_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_node_view_page_manager_tasks().
|
||||
*
|
||||
* Alter the node view input so that node view comes to us rather than the
|
||||
* normal node view process.
|
||||
*/
|
||||
function page_manager_node_view_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_node_view_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Override the node view handler for our purpose.
|
||||
$callback = $items['node/%node']['page callback'];
|
||||
if ($callback == 'node_page_view' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['node/%node']['page callback'] = 'page_manager_node_view_page';
|
||||
$items['node/%node']['file path'] = $task['path'];
|
||||
$items['node/%node']['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
// automatically disable this task if it cannot be enabled.
|
||||
variable_set('page_manager_node_view_disabled', TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_node_view'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable node/%node because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// @todo override node revision handler as well?
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden node view.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* node view, which is node_page_view().
|
||||
*/
|
||||
function page_manager_node_view_page($node) {
|
||||
// Load my task plugin
|
||||
$task = page_manager_get_task('node_view');
|
||||
|
||||
// Load the node into a context.
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
|
||||
// We need to mimic Drupal's behavior of setting the node title here.
|
||||
drupal_set_title($node->title);
|
||||
$uri = entity_uri('node', $node);
|
||||
// Set the node path as the canonical URL to prevent duplicate content.
|
||||
drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE);
|
||||
// Set the non-aliased path as a default shortlink.
|
||||
drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE);
|
||||
$contexts = ctools_context_handler_get_task_contexts($task, '', array($node));
|
||||
|
||||
$output = ctools_context_handler_render($task, '', $contexts, array($node->nid));
|
||||
if ($output != FALSE) {
|
||||
node_tag_new($node);
|
||||
return $output;
|
||||
}
|
||||
|
||||
$function = 'node_page_view';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('node_view')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back.
|
||||
return $function($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get arguments provided by this task handler.
|
||||
*
|
||||
* Since this is the node view and there is no UI on the arguments, we
|
||||
* create dummy arguments that contain the needed data.
|
||||
*/
|
||||
function page_manager_node_view_get_arguments($task, $subtask_id) {
|
||||
return array(
|
||||
array(
|
||||
'keyword' => 'node',
|
||||
'identifier' => t('Node being viewed'),
|
||||
'id' => 1,
|
||||
'name' => 'entity_id:node',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get context placeholders provided by this handler.
|
||||
*/
|
||||
function page_manager_node_view_get_contexts($task, $subtask_id) {
|
||||
return ctools_context_get_placeholders_from_argument(page_manager_node_view_get_arguments($task, $subtask_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_node_view_enable($cache, $status) {
|
||||
variable_set('page_manager_node_view_disabled', $status);
|
||||
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_node_view'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_node_view_access_check($task, $subtask_id, $contexts) {
|
||||
$context = reset($contexts);
|
||||
return node_access('view', $context->data);
|
||||
}
|
1521
sites/all/modules/ctools/page_manager/plugins/tasks/page.admin.inc
Normal file
1521
sites/all/modules/ctools/page_manager/plugins/tasks/page.admin.inc
Normal file
File diff suppressed because it is too large
Load Diff
787
sites/all/modules/ctools/page_manager/plugins/tasks/page.inc
Normal file
787
sites/all/modules/ctools/page_manager/plugins/tasks/page.inc
Normal file
@@ -0,0 +1,787 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handle the 'page' task, which creates pages with arbitrary tasks and lets
|
||||
* handlers decide how they will be rendered.
|
||||
*
|
||||
* This creates subtasks and stores them in the page_manager_pages table. These
|
||||
* are exportable objects, too.
|
||||
*
|
||||
* The render callback for this task type has $handler, $page, $contexts as
|
||||
* parameters.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_page_page_manager_tasks() {
|
||||
return array(
|
||||
'title' => t('Custom pages'),
|
||||
'description' => t('Administrator created pages that have a URL path, access control and entries in the Drupal menu system.'),
|
||||
'non-exportable' => TRUE,
|
||||
'subtasks' => TRUE,
|
||||
'subtask callback' => 'page_manager_page_subtask',
|
||||
'subtasks callback' => 'page_manager_page_subtasks',
|
||||
'save subtask callback' => 'page_manager_page_save_subtask',
|
||||
'access callback' => 'page_manager_page_access_check',
|
||||
'hook menu' => array(
|
||||
'file' => 'page.admin.inc',
|
||||
'path' => drupal_get_path('module', 'page_manager') . '/plugins/tasks',
|
||||
'function' => 'page_manager_page_menu',
|
||||
),
|
||||
'hook theme' => 'page_manager_page_theme',
|
||||
// page only items
|
||||
'task type' => 'page',
|
||||
'page operations' => array(
|
||||
array(
|
||||
'title' => ' » ' . t('Create a new page'),
|
||||
'href' => 'admin/structure/pages/add',
|
||||
'html' => TRUE,
|
||||
),
|
||||
),
|
||||
'columns' => array(
|
||||
'storage' => array(
|
||||
'label' => t('Storage'),
|
||||
'class' => 'page-manager-page-storage',
|
||||
),
|
||||
),
|
||||
'page type' => 'custom',
|
||||
|
||||
// context only items
|
||||
'handler type' => 'context',
|
||||
'get arguments' => array(
|
||||
'file' => 'page.admin.inc',
|
||||
'path' => drupal_get_path('module', 'page_manager') . '/plugins/tasks',
|
||||
'function' => 'page_manager_page_get_arguments',
|
||||
),
|
||||
'get context placeholders' => 'page_manager_page_get_contexts',
|
||||
'access restrictions' => 'page_manager_page_access_restrictions',
|
||||
'uses handlers' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Task callback to get all subtasks.
|
||||
*
|
||||
* Return a list of all subtasks.
|
||||
*/
|
||||
function page_manager_page_subtasks($task) {
|
||||
$pages = page_manager_page_load_all($task['name']);
|
||||
$return = array();
|
||||
foreach ($pages as $name => $page) {
|
||||
$return[$name] = page_manager_page_build_subtask($task, $page);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to return a single subtask.
|
||||
*/
|
||||
function page_manager_page_subtask($task, $subtask_id) {
|
||||
$page = page_manager_page_load($subtask_id);
|
||||
if ($page) {
|
||||
return page_manager_page_build_subtask($task, $page);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call back from the administrative system to save a page.
|
||||
*
|
||||
* We get the $subtask as created by page_manager_page_build_subtask.
|
||||
*/
|
||||
function page_manager_page_save_subtask($subtask) {
|
||||
$page = &$subtask['subtask'];
|
||||
|
||||
// Ensure $page->arguments contains only real arguments:
|
||||
$arguments = page_manager_page_get_named_arguments($page->path);
|
||||
$args = array();
|
||||
foreach ($arguments as $keyword => $position) {
|
||||
if (isset($page->arguments[$keyword])) {
|
||||
$args[$keyword] = $page->arguments[$keyword];
|
||||
}
|
||||
else {
|
||||
$args[$keyword] = array(
|
||||
'id' => '',
|
||||
'identifier' => '',
|
||||
'argument' => '',
|
||||
'settings' => array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
page_manager_page_recalculate_arguments($page);
|
||||
// Create a real object from the cache
|
||||
page_manager_page_save($page);
|
||||
|
||||
// Check to see if we should make this the site frontpage.
|
||||
if (!empty($page->make_frontpage)) {
|
||||
$path = array();
|
||||
foreach (explode('/', $page->path) as $bit) {
|
||||
if ($bit[0] != '!') {
|
||||
$path[] = $bit;
|
||||
}
|
||||
}
|
||||
|
||||
$path = implode('/', $path);
|
||||
$front = variable_get('site_frontpage', 'node');
|
||||
if ($path != $front) {
|
||||
variable_set('site_frontpage', $path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a subtask array for a given page.
|
||||
*/
|
||||
function page_manager_page_build_subtask($task, $page) {
|
||||
$operations = array();
|
||||
$operations['settings'] = array(
|
||||
'type' => 'group',
|
||||
'class' => array('operations-settings'),
|
||||
'title' => t('Settings'),
|
||||
'children' => array(),
|
||||
);
|
||||
|
||||
$settings = &$operations['settings']['children'];
|
||||
|
||||
$settings['basic'] = array(
|
||||
'title' => t('Basic'),
|
||||
'description' => t('Edit name, path and other basic settings for the page.'),
|
||||
'form' => 'page_manager_page_form_basic',
|
||||
);
|
||||
|
||||
$arguments = page_manager_page_get_named_arguments($page->path);
|
||||
if ($arguments) {
|
||||
$settings['argument'] = array(
|
||||
'title' => t('Arguments'),
|
||||
'description' => t('Set up contexts for the arguments on this page.'),
|
||||
'form' => 'page_manager_page_form_argument',
|
||||
);
|
||||
}
|
||||
|
||||
$settings['access'] = array(
|
||||
'title' => t('Access'),
|
||||
'description' => t('Control what users can access this page.'),
|
||||
'admin description' => t('Access rules are used to test if the page is accessible and any menu items associated with it are visible.'),
|
||||
'form' => 'page_manager_page_form_access',
|
||||
);
|
||||
|
||||
$settings['menu'] = array(
|
||||
'title' => t('Menu'),
|
||||
'description' => t('Provide this page a visible menu or a menu tab.'),
|
||||
'form' => 'page_manager_page_form_menu',
|
||||
);
|
||||
|
||||
$operations['actions']['children']['clone'] = array(
|
||||
'title' => t('Clone'),
|
||||
'description' => t('Make a copy of this page'),
|
||||
'form' => 'page_manager_page_form_clone',
|
||||
);
|
||||
$operations['actions']['children']['export'] = array(
|
||||
'title' => t('Export'),
|
||||
'description' => t('Export this page as code that can be imported or embedded into a module.'),
|
||||
'form' => 'page_manager_page_form_export',
|
||||
);
|
||||
if ($page->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) {
|
||||
$operations['actions']['children']['delete'] = array(
|
||||
'title' => t('Revert'),
|
||||
'description' => t('Remove all changes to this page and revert to the version in code.'),
|
||||
'form' => 'page_manager_page_form_delete',
|
||||
);
|
||||
}
|
||||
else if ($page->export_type != EXPORT_IN_CODE) {
|
||||
$operations['actions']['children']['delete'] = array(
|
||||
'title' => t('Delete'),
|
||||
'description' => t('Remove this page from your system completely.'),
|
||||
'form' => 'page_manager_page_form_delete',
|
||||
);
|
||||
}
|
||||
|
||||
$subtask = array(
|
||||
'name' => $page->name,
|
||||
'admin title' => check_plain($page->admin_title),
|
||||
'admin description' => filter_xss_admin($page->admin_description),
|
||||
'admin summary' => 'page_manager_page_admin_summary',
|
||||
'admin path' => $page->path,
|
||||
'admin type' => t('Custom'),
|
||||
'subtask' => $page,
|
||||
'operations' => $operations,
|
||||
'operations include' => array(
|
||||
'file' => 'page.admin.inc',
|
||||
'path' => drupal_get_path('module', 'page_manager') . '/plugins/tasks',
|
||||
),
|
||||
'single task' => empty($page->multiple),
|
||||
'row class' => empty($page->disabled) ? 'page-manager-enabled' : 'page-manager-disabled',
|
||||
'storage' => $page->type == t('Default') ? t('In code') : $page->type,
|
||||
'disabled' => !empty($page->disabled),
|
||||
// This works for both enable AND disable
|
||||
'enable callback' => 'page_manager_page_enable',
|
||||
);
|
||||
|
||||
// default handlers may appear from a default subtask.
|
||||
if (isset($page->default_handlers)) {
|
||||
$subtask['default handlers'] = $page->default_handlers;
|
||||
}
|
||||
return $subtask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegated implementation of hook_theme().
|
||||
*/
|
||||
function page_manager_page_theme(&$items, $task) {
|
||||
$base = array(
|
||||
'file' => 'page.admin.inc',
|
||||
'path' => drupal_get_path('module', 'page_manager') . '/plugins/tasks',
|
||||
);
|
||||
$items['page_manager_page_form_argument_table'] = $base + array(
|
||||
'render element' => 'form',
|
||||
);
|
||||
$items['page_manager_page_lock'] = $base + array(
|
||||
'variables' => array('lock' => array(), 'task_name' => NULL),
|
||||
);
|
||||
$items['page_manager_page_changed'] = $base + array(
|
||||
'variables' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Page execution functions
|
||||
|
||||
/**
|
||||
* Execute a page task.
|
||||
*
|
||||
* This is the callback to entries in the Drupal menu system created by the
|
||||
* page task.
|
||||
*
|
||||
* @param $subtask_id
|
||||
* The name of the page task used.
|
||||
* @param ...
|
||||
* A number of context objects as specified by the user when
|
||||
* creating named arguments in the path.
|
||||
*/
|
||||
function page_manager_page_execute($subtask_id) {
|
||||
$page = page_manager_page_load($subtask_id);
|
||||
$task = page_manager_get_task($page->task);
|
||||
$subtask = page_manager_get_task_subtask($task, $subtask_id);
|
||||
|
||||
// Turn the contexts into a properly keyed array.
|
||||
$contexts = array();
|
||||
$args = array();
|
||||
foreach (func_get_args() as $count => $arg) {
|
||||
if (is_object($arg) && get_class($arg) == 'ctools_context') {
|
||||
$contexts[$arg->id] = $arg;
|
||||
$args[] = $arg->original_argument;
|
||||
}
|
||||
else if ($count) {
|
||||
$args[] = $arg;
|
||||
}
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$names = page_manager_page_get_named_arguments($page->path);
|
||||
$bits = explode('/', $page->path);
|
||||
|
||||
if ($page->arguments) {
|
||||
foreach ($page->arguments as $name => $argument) {
|
||||
// Optional arguments must be converted to contexts too, if they exist.
|
||||
if ($bits[$names[$name]][0] == '!') {
|
||||
ctools_include('context');
|
||||
$argument['keyword'] = $name;
|
||||
if (isset($args[$count])) {
|
||||
// Hack: use a special argument config variable to learn if we need
|
||||
// to use menu_tail style behavior:
|
||||
if (empty($argument['settings']['use_tail'])) {
|
||||
$value = $args[$count];
|
||||
}
|
||||
else {
|
||||
$value = implode('/', array_slice($args, $count));
|
||||
}
|
||||
|
||||
$context = ctools_context_get_context_from_argument($argument, $value);
|
||||
}
|
||||
else {
|
||||
// make sure there is a placeholder context for missing optional contexts.
|
||||
$context = ctools_context_get_context_from_argument($argument, NULL, TRUE);
|
||||
// Force the title to blank for replacements
|
||||
}
|
||||
if ($context) {
|
||||
$contexts[$context->id] = $context;
|
||||
}
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($function = ctools_plugin_get_function($task, 'page callback')) {
|
||||
return call_user_func_array($function, array($page, $contexts, $args));
|
||||
}
|
||||
|
||||
ctools_include('context-task-handler');
|
||||
$output = ctools_context_handler_render($task, $subtask, $contexts, $args);
|
||||
if ($output === FALSE) {
|
||||
return drupal_not_found();
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Context type callbacks
|
||||
|
||||
/**
|
||||
* Return a list of arguments used by this task.
|
||||
*/
|
||||
function page_manager_page_get_arguments($task, $subtask) {
|
||||
return _page_manager_page_get_arguments($subtask['subtask']);
|
||||
}
|
||||
|
||||
function _page_manager_page_get_arguments($page) {
|
||||
$arguments = array();
|
||||
if (!empty($page->arguments)) {
|
||||
foreach ($page->arguments as $keyword => $argument) {
|
||||
if (isset($argument['name'])) {
|
||||
$argument['keyword'] = $keyword;
|
||||
$arguments[$keyword] = $argument;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a group of context placeholders for the arguments.
|
||||
*/
|
||||
function page_manager_page_get_contexts($task, $subtask) {
|
||||
ctools_include('context');
|
||||
return ctools_context_get_placeholders_from_argument(page_manager_page_get_arguments($task, $subtask));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of arguments used by this task.
|
||||
*/
|
||||
function page_manager_page_access_restrictions($task, $subtask, $contexts) {
|
||||
$page = $subtask['subtask'];
|
||||
return ctools_access_add_restrictions($page->access, $contexts);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Page task database info.
|
||||
|
||||
/**
|
||||
* Create a new page with defaults appropriately set from schema.
|
||||
*/
|
||||
function page_manager_page_new() {
|
||||
ctools_include('export');
|
||||
return ctools_export_new_object('page_manager_pages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a single page subtask.
|
||||
*/
|
||||
function page_manager_page_load($name) {
|
||||
ctools_include('export');
|
||||
$result = ctools_export_load_object('page_manager_pages', 'names', array($name));
|
||||
if (isset($result[$name])) {
|
||||
return $result[$name];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all page subtasks.
|
||||
*/
|
||||
function page_manager_page_load_all($task = NULL) {
|
||||
ctools_include('export');
|
||||
|
||||
if (empty($task)) {
|
||||
return ctools_export_load_object('page_manager_pages');
|
||||
}
|
||||
else {
|
||||
return ctools_export_load_object('page_manager_pages', 'conditions', array('task' => $task));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a page subtask to the database.
|
||||
*/
|
||||
function page_manager_page_save(&$page) {
|
||||
$update = (isset($page->pid)) ? array('pid') : array();
|
||||
$task = page_manager_get_task($page->task);
|
||||
|
||||
if ($function = ctools_plugin_get_function($task, 'save')) {
|
||||
$function($page, $update);
|
||||
}
|
||||
drupal_write_record('page_manager_pages', $page, $update);
|
||||
|
||||
// If this was a default page we may need to write default task
|
||||
// handlers that we provided as well.
|
||||
if (!$update && isset($page->default_handlers)) {
|
||||
$handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $page->name);
|
||||
foreach ($page->default_handlers as $name => $handler) {
|
||||
if (!isset($handlers[$name]) || !($handlers[$name]->export_type & EXPORT_IN_DATABASE)) {
|
||||
// Make sure this is right, as exports can wander a bit.
|
||||
$handler->subtask = $page->name;
|
||||
page_manager_save_task_handler($handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a page subtask.
|
||||
*/
|
||||
function page_manager_page_delete($page) {
|
||||
$task = page_manager_get_task($page->task);
|
||||
if ($function = ctools_plugin_get_function($task, 'delete')) {
|
||||
$function($page);
|
||||
}
|
||||
if (!empty($task['uses handlers'])) {
|
||||
$handlers = page_manager_load_task_handlers($task, $page->name);
|
||||
foreach ($handlers as $handler) {
|
||||
page_manager_delete_task_handler($handler);
|
||||
}
|
||||
}
|
||||
db_delete('page_manager_pages')
|
||||
->condition('name', $page->name)
|
||||
->execute();
|
||||
// Make sure that the cache is reset so that the menu rebuild does not
|
||||
// rebuild this page again.
|
||||
ctools_include('export');
|
||||
ctools_export_load_object_reset('page_manager_pages');
|
||||
menu_rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Export a page subtask.
|
||||
*/
|
||||
function page_manager_page_export($page, $with_handlers = FALSE, $indent = '') {
|
||||
$task = page_manager_get_task($page->task);
|
||||
$append = '';
|
||||
|
||||
if ($function = ctools_plugin_get_function($task, 'export')) {
|
||||
$append = $function($page, $indent);
|
||||
}
|
||||
|
||||
ctools_include('export');
|
||||
$output = ctools_export_object('page_manager_pages', $page, $indent);
|
||||
$output .= $append;
|
||||
|
||||
if ($with_handlers) {
|
||||
if (is_array($with_handlers)) {
|
||||
$handlers = $with_handlers;
|
||||
}
|
||||
else {
|
||||
$handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $page->name);
|
||||
}
|
||||
$output .= $indent . '$page->default_handlers = array();' . "\n";
|
||||
foreach ($handlers as $handler) {
|
||||
$output .= page_manager_export_task_handler($handler, $indent);
|
||||
$output .= $indent . '$page->default_handlers[$handler->name] = $handler;' . "\n";
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of named arguments in a page manager path.
|
||||
*
|
||||
* @param $path
|
||||
* A normal Drupal path.
|
||||
*
|
||||
* @return
|
||||
* An array of % marked variable arguments, keyed by the argument's name.
|
||||
* The value will be the position of the argument so that it can easily
|
||||
* be found. Items with a position of -1 have multiple positions.
|
||||
*/
|
||||
function page_manager_page_get_named_arguments($path) {
|
||||
$arguments = array();
|
||||
$bits = explode('/', $path);
|
||||
foreach ($bits as $position => $bit) {
|
||||
if ($bit && ($bit[0] == '%' || $bit[0] == '!')) {
|
||||
// special handling for duplicate path items and substr to remove the %
|
||||
$arguments[substr($bit, 1)] = isset($arguments[$bit]) ? -1 : $position;
|
||||
}
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a context from an argument for a given page task.
|
||||
*
|
||||
* Helper function for pm_arg_load(), which is in page_manager.module because
|
||||
* drupal's menu system does not allow loader functions to reside in separate
|
||||
* files.
|
||||
*
|
||||
* @param $value
|
||||
* The incoming argument value.
|
||||
* @param $subtask
|
||||
* The subtask id.
|
||||
* @param $argument
|
||||
* The numeric position of the argument in the path, counting from 0.
|
||||
*
|
||||
* @return
|
||||
* A context item if one is configured, the argument if one is not, or
|
||||
* FALSE if restricted or invalid.
|
||||
*/
|
||||
function _pm_arg_load($value, $subtask, $argument) {
|
||||
$page = page_manager_page_load($subtask);
|
||||
if (!$page) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$path = explode('/', $page->path);
|
||||
if (empty($path[$argument])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$keyword = substr($path[$argument], 1);
|
||||
if (empty($page->arguments[$keyword])) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$page->arguments[$keyword]['keyword'] = $keyword;
|
||||
|
||||
ctools_include('context');
|
||||
$context = ctools_context_get_context_from_argument($page->arguments[$keyword], $value);
|
||||
|
||||
// convert false equivalents to false.
|
||||
return $context ? $context : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a nice administrative summary of the page so an admin can see at a
|
||||
* glance what this page does and how it is configured.
|
||||
*/
|
||||
function page_manager_page_admin_summary($task, $subtask) {
|
||||
$task_name = page_manager_make_task_name($task['name'], $subtask['name']);
|
||||
$page = $subtask['subtask'];
|
||||
$output = '';
|
||||
|
||||
$rows = array();
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Storage')),
|
||||
array('class' => array('page-summary-data'), 'data' => $subtask['storage']),
|
||||
array('class' => array('page-summary-operation'), 'data' => ''),
|
||||
);
|
||||
|
||||
if (!empty($page->disabled)) {
|
||||
$link = l(t('Enable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'enable')));
|
||||
$text = t('Disabled');
|
||||
}
|
||||
else {
|
||||
$link = l(t('Disable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'disable')));
|
||||
$text = t('Enabled');
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Status')),
|
||||
array('class' => array('page-summary-data'), 'data' => $text),
|
||||
array('class' => array('page-summary-operation'), 'data' => $link),
|
||||
);
|
||||
|
||||
|
||||
$path = array();
|
||||
foreach (explode('/', $page->path) as $bit) {
|
||||
if ($bit[0] != '!') {
|
||||
$path[] = $bit;
|
||||
}
|
||||
}
|
||||
|
||||
$path = implode('/', $path);
|
||||
$front = variable_get('site_frontpage', 'node');
|
||||
|
||||
$link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'basic')));
|
||||
$message = '';
|
||||
if ($path == $front) {
|
||||
$message = t('This is your site home page.');
|
||||
}
|
||||
else if (!empty($page->make_frontpage)) {
|
||||
$message = t('This page is set to become your site home page.');
|
||||
}
|
||||
|
||||
if ($message) {
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-data'), 'data' => $message, 'colspan' => 2),
|
||||
array('class' => array('page-summary-operation'), 'data' => $link),
|
||||
);
|
||||
}
|
||||
|
||||
if (strpos($path, '%') === FALSE) {
|
||||
$path = l('/' . $page->path, $path);
|
||||
}
|
||||
else {
|
||||
$path = '/' . $page->path;
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Path')),
|
||||
array('class' => array('page-summary-data'), 'data' => $path),
|
||||
array('class' => array('page-summary-operation'), 'data' => $link),
|
||||
);
|
||||
|
||||
if (empty($access['plugins'])) {
|
||||
$access['plugins'] = array();
|
||||
}
|
||||
|
||||
$contexts = page_manager_page_get_contexts($task, $subtask);
|
||||
$access = ctools_access_group_summary($page->access, $contexts);
|
||||
if ($access) {
|
||||
$access = t('Accessible only if @conditions.', array('@conditions' => $access));
|
||||
}
|
||||
else {
|
||||
$access = t('This page is publicly accessible.');
|
||||
}
|
||||
|
||||
$link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'access')));
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Access')),
|
||||
array('class' => array('page-summary-data'), 'data' => $access),
|
||||
array('class' => array('page-summary-operation'), 'data' => $link),
|
||||
);
|
||||
|
||||
$menu_options = array(
|
||||
'none' => t('No menu entry.'),
|
||||
'normal' => t('Normal menu entry.'),
|
||||
'tab' => t('Menu tab.'),
|
||||
'default tab' => t('Default menu tab.'),
|
||||
'action' => t('Local action'),
|
||||
);
|
||||
|
||||
if (!empty($page->menu)) {
|
||||
$menu = $menu_options[$page->menu['type']];
|
||||
if ($page->menu['type'] != 'none') {
|
||||
$menu .= ' ' . t('Title: %title.', array('%title' => $page->menu['title']));
|
||||
switch ($page->menu['type']) {
|
||||
case 'default tab':
|
||||
$menu .= ' ' . t('Parent title: %title.', array('%title' => $page->menu['parent']['title']));
|
||||
break;
|
||||
case 'normal':
|
||||
if (module_exists('menu')) {
|
||||
$menus = menu_get_menus();
|
||||
$menu .= ' ' . t('Menu block: %title.', array('%title' => $menus[$page->menu['name']]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$menu = t('No menu entry');
|
||||
}
|
||||
|
||||
$link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'menu')));
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Menu')),
|
||||
array('class' => array('page-summary-data'), 'data' => $menu),
|
||||
array('class' => array('page-summary-operation'), 'data' => $link),
|
||||
);
|
||||
|
||||
$output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'page-manager-page-summary')));
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_page_enable(&$cache, $status) {
|
||||
$page = &$cache->subtask['subtask'];
|
||||
ctools_include('export');
|
||||
ctools_export_set_object_status($page, $status);
|
||||
|
||||
$page->disabled = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculate the arguments when something like the path changes.
|
||||
*/
|
||||
function page_manager_page_recalculate_arguments(&$page) {
|
||||
// Ensure $page->arguments contains only real arguments:
|
||||
$arguments = page_manager_page_get_named_arguments($page->path);
|
||||
$args = array();
|
||||
foreach ($arguments as $keyword => $position) {
|
||||
if (isset($page->arguments[$keyword])) {
|
||||
$args[$keyword] = $page->arguments[$keyword];
|
||||
}
|
||||
else {
|
||||
$args[$keyword] = array(
|
||||
'id' => '',
|
||||
'identifier' => '',
|
||||
'argument' => '',
|
||||
'settings' => array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
$page->arguments = $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* When adding or cloning a new page, this creates a new page cache
|
||||
* and adds our page to it.
|
||||
*
|
||||
* This does not check to see if the existing cache is already locked.
|
||||
* This must be done beforehand.
|
||||
*
|
||||
* @param &$page
|
||||
* The page to create.
|
||||
* @param &$cache
|
||||
* The cache to use. If the cache has any existing task handlers,
|
||||
* they will be marked for deletion. This may be a blank object.
|
||||
*/
|
||||
function page_manager_page_new_page_cache(&$page, &$cache) {
|
||||
// Does a page already exist? If so, we are overwriting it so
|
||||
// take its pid.
|
||||
if (!empty($cache->subtask) && !empty($cache->subtask['subtask']) && !empty($cache->subtask['subtask']->pid)) {
|
||||
$page->pid = $cache->subtask['subtask']->pid;
|
||||
}
|
||||
else {
|
||||
$cache->new = TRUE;
|
||||
}
|
||||
|
||||
$cache->task_name = page_manager_make_task_name('page', $page->name);
|
||||
$cache->task_id = 'page';
|
||||
$cache->task = page_manager_get_task('page');
|
||||
$cache->subtask_id = $page->name;
|
||||
$page->export_type = EXPORT_IN_DATABASE;
|
||||
$page->type = t('Normal');
|
||||
$cache->subtask = page_manager_page_build_subtask($cache->task, $page);
|
||||
|
||||
if (isset($cache->handlers)) {
|
||||
foreach($cache->handlers as $id => $handler) {
|
||||
$cache->handler_info[$id]['changed'] = PAGE_MANAGER_CHANGED_DELETED;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$cache->handlers = array();
|
||||
$cache->handler_info = array();
|
||||
}
|
||||
|
||||
if (!empty($page->default_handlers)) {
|
||||
foreach ($page->default_handlers as $id => $handler) {
|
||||
page_manager_handler_add_to_page($cache, $handler);
|
||||
}
|
||||
}
|
||||
|
||||
$cache->locked = FALSE;
|
||||
$cache->changed = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_page_access_check($task, $subtask_id, $contexts) {
|
||||
$page = page_manager_page_load($subtask_id);
|
||||
return ctools_access($page->access, $contexts);
|
||||
}
|
121
sites/all/modules/ctools/page_manager/plugins/tasks/poll.inc
Normal file
121
sites/all/modules/ctools/page_manager/plugins/tasks/poll.inc
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_poll_page_manager_tasks() {
|
||||
if (!module_exists('poll')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
|
||||
'title' => t('All polls'),
|
||||
'admin title' => t('All polls'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for the polls at <em>/poll</em>. If no variant is selected, the default Drupal most recent polls will be shown.'),
|
||||
'admin path' => 'poll',
|
||||
|
||||
// Menu hooks so that we can alter the node/%node menu entry to point to us.
|
||||
'hook menu alter' => 'page_manager_poll_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_poll_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_poll_enable',
|
||||
'access callback' => 'page_manager_poll_access_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_poll_page_manager_tasks().
|
||||
*
|
||||
* Alter the node edit input so that node edit comes to us rather than the
|
||||
* normal node edit process.
|
||||
*/
|
||||
function page_manager_poll_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_poll_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$callback = $items['poll']['page callback'];
|
||||
// Override the node edit handler for our purpose.
|
||||
if ($callback == 'poll_page' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['poll']['page callback'] = 'page_manager_poll';
|
||||
$items['poll']['file path'] = $task['path'];
|
||||
$items['poll']['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
variable_set('page_manager_poll_disabled', TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_poll'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable poll because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden node edit.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* node edit, which is node_page_edit().
|
||||
*/
|
||||
function page_manager_poll() {
|
||||
// Load my task plugin
|
||||
$task = page_manager_get_task('poll');
|
||||
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
$output = ctools_context_handler_render($task, '', array(), array());
|
||||
if ($output !== FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
module_load_include('inc', 'poll', 'poll.pages');
|
||||
$function = 'poll_page';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('poll')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back.
|
||||
return $function();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_poll_enable($cache, $status) {
|
||||
variable_set('page_manager_poll_disabled', $status);
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_poll'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_poll_access_check($task, $subtask_id, $contexts) {
|
||||
return user_access('access content');
|
||||
}
|
249
sites/all/modules/ctools/page_manager/plugins/tasks/search.inc
Normal file
249
sites/all/modules/ctools/page_manager/plugins/tasks/search.inc
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handle the 'node view' override task.
|
||||
*
|
||||
* This plugin overrides node/%node and reroutes it to the page manager, where
|
||||
* a list of tasks can be used to service this request based upon criteria
|
||||
* supplied by access plugins.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_search_page_manager_tasks() {
|
||||
if (!module_exists('search')) {
|
||||
return;
|
||||
}
|
||||
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
'title' => t('Search'),
|
||||
|
||||
// There are multiple search pages, let's override each of them
|
||||
// separately.
|
||||
'subtasks' => TRUE,
|
||||
'subtask callback' => 'page_manager_search_subtask',
|
||||
'subtasks callback' => 'page_manager_search_subtasks',
|
||||
|
||||
// Menu hooks so that we can alter the node/%node menu entry to point to us.
|
||||
'hook menu alter' => 'page_manager_search_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context',
|
||||
'get arguments' => 'page_manager_search_get_arguments',
|
||||
'get context placeholders' => 'page_manager_search_get_contexts',
|
||||
'access callback' => 'page_manager_search_access_check',
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_search_page_manager_tasks().
|
||||
*
|
||||
* Alter the search tabs to work with page manager. The search flow is
|
||||
* quite odd, and tracing through the code takes hours to realize
|
||||
* that the tab you click on does not normally actually handle
|
||||
* the search. This tries to account for that.
|
||||
*
|
||||
* Note to module authors: This tends to work a lot better with modules
|
||||
* that override their own search pages if their _alter runs *before*
|
||||
* this one.
|
||||
*/
|
||||
function page_manager_search_menu_alter(&$items, $task) {
|
||||
// We are creating two sets of tabs. One set is for searching without
|
||||
// keywords. A second set is for searching *with* keywords. This
|
||||
// is necessary because search/node/% and search/node need to be
|
||||
// different due to the way the search menu items function.
|
||||
|
||||
$default_info = search_get_default_module_info();
|
||||
if (empty($default_info)) {
|
||||
// Nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
// Go through each search module item.
|
||||
foreach (search_get_info() as $module => $info) {
|
||||
if (variable_get('page_manager_search_disabled_' . $module, TRUE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = 'search/' . $info['path'];
|
||||
$callback = $items["$path/%menu_tail"]['page callback'];
|
||||
|
||||
if ($callback == 'search_view' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items["$path"]['page callback'] = 'page_manager_search_page';
|
||||
$items["$path"]['file path'] = $task['path'];
|
||||
$items["$path"]['file'] = $task['file'];
|
||||
|
||||
$items["$path/%menu_tail"]['page callback'] = 'page_manager_search_page';
|
||||
$items["$path/%menu_tail"]['file path'] = $task['path'];
|
||||
$items["$path/%menu_tail"]['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
// automatically disable this task if it cannot be enabled.
|
||||
variable_set('page_manager_search_disabled_' . $module, TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_search'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable @path because some other module already has overridden with %callback.', array('%callback' => $callback, '@path' => $path)), 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden search page.
|
||||
*
|
||||
*/
|
||||
function page_manager_search_page($type) {
|
||||
ctools_include('menu');
|
||||
// menu_set_active_trail(ctools_get_menu_trail('search/' . $type));
|
||||
|
||||
// Get the arguments and construct a keys string out of them.
|
||||
$args = func_get_args();
|
||||
|
||||
// We have to remove the $type.
|
||||
array_shift($args);
|
||||
|
||||
// And implode() it all back together.
|
||||
$keys = $args ? implode('/', $args) : '';
|
||||
|
||||
// Allow other modules to alter the search keys
|
||||
drupal_alter(array('search_keys', 'search_'. $type .'_keys'), $keys);
|
||||
|
||||
// Load my task plugin
|
||||
$task = page_manager_get_task('search');
|
||||
$subtask = page_manager_get_task_subtask($task, $type);
|
||||
|
||||
// Load the node into a context.
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
$contexts = ctools_context_handler_get_task_contexts($task, $subtask, array($keys));
|
||||
|
||||
$output = ctools_context_handler_render($task, $subtask, $contexts, array($keys));
|
||||
if ($output !== FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$function = 'search_view';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('search')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back.
|
||||
|
||||
// Put the $type back on the arguments.
|
||||
module_load_include('inc', 'search', 'search.pages');
|
||||
array_unshift($args, $type);
|
||||
return call_user_func_array($function, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get arguments provided by this task handler.
|
||||
*
|
||||
* Since this is the node view and there is no UI on the arguments, we
|
||||
* create dummy arguments that contain the needed data.
|
||||
*/
|
||||
function page_manager_search_get_arguments($task, $subtask_id) {
|
||||
return array(
|
||||
array(
|
||||
'keyword' => 'keywords',
|
||||
'identifier' => t('Keywords'),
|
||||
'id' => 1,
|
||||
'name' => 'string',
|
||||
'settings' => array('use_tail' => TRUE),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get context placeholders provided by this handler.
|
||||
*/
|
||||
function page_manager_search_get_contexts($task, $subtask_id) {
|
||||
return ctools_context_get_placeholders_from_argument(page_manager_search_get_arguments($task, $subtask_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_search_enable($cache, $status) {
|
||||
variable_set('page_manager_search_disabled_' . $cache->subtask_id, $status);
|
||||
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_search'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Task callback to get all subtasks.
|
||||
*
|
||||
* Return a list of all subtasks.
|
||||
*/
|
||||
function page_manager_search_subtasks($task) {
|
||||
$return = array();
|
||||
foreach (search_get_info() as $module => $info) {
|
||||
if ($info['path']) {
|
||||
// We don't pass the $info because the subtask build could be called
|
||||
// singly without the $info when just the subtask needs to be built.
|
||||
$return[$module] = page_manager_search_build_subtask($task, $module);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to return a single subtask.
|
||||
*/
|
||||
function page_manager_search_subtask($task, $subtask_id) {
|
||||
return page_manager_search_build_subtask($task, $subtask_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a subtask array for a given page.
|
||||
*/
|
||||
function page_manager_search_build_subtask($task, $module) {
|
||||
$search_info = search_get_info();
|
||||
$info = $search_info[$module];
|
||||
$path = 'search/' . $info['path'];
|
||||
$subtask = array(
|
||||
'name' => $module,
|
||||
'admin title' => $info['title'],
|
||||
'admin path' => "$path/!keywords",
|
||||
'admin description' => t('Search @type', array('@type' => $info['title'])),
|
||||
'admin type' => t('System'),
|
||||
'row class' => empty($page->disabled) ? 'page-manager-enabled' : 'page-manager-disabled',
|
||||
'storage' => t('In code'),
|
||||
'disabled' => variable_get('page_manager_search_disabled_' . $module, TRUE),
|
||||
// This works for both enable AND disable
|
||||
'enable callback' => 'page_manager_search_enable',
|
||||
);
|
||||
|
||||
return $subtask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_search_access_check($task, $subtask_id, $contexts) {
|
||||
$context = reset($contexts);
|
||||
return _search_menu_access($context->data);
|
||||
}
|
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handle the 'term view' override task.
|
||||
*
|
||||
* This plugin overrides term/%term and reroutes it to the page manager, where
|
||||
* a list of tasks can be used to service this request based upon criteria
|
||||
* supplied by access plugins.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_term_view_page_manager_tasks() {
|
||||
if (module_exists('taxonomy')) {
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
|
||||
'title' => t('Taxonomy term template'),
|
||||
'admin title' => t('Taxonomy term template'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying taxonomy terms at <em>taxonomy/term/%term</em>. If you add variants, you may use selection criteria such as vocabulary or user access to provide different displays of the taxonomy term and associated nodes. If no variant is selected, the default Drupal taxonomy term display will be used. This page only affects items actually displayed ad taxonomy/term/%term. Some taxonomy terms, such as forums, have their displays moved elsewhere. Also please note that if you are using pathauto, aliases may make a taxonomy terms appear somewhere else, but as far as Drupal is concerned, they are still at taxonomy/term/%term.'),
|
||||
'admin path' => 'taxonomy/term/%taxonomy_term',
|
||||
'admin summary' => 'page_manager_term_view_admin_summary',
|
||||
|
||||
// Menu hooks so that we can alter the term/%term menu entry to point to us.
|
||||
'hook menu' => 'page_manager_term_view_menu',
|
||||
'hook menu alter' => 'page_manager_term_view_menu_alter',
|
||||
|
||||
// Provide a setting to the primary settings UI for Panels
|
||||
'admin settings' => 'page_manager_term_view_admin_settings',
|
||||
// Even though we don't have subtasks, this allows us to save our settings.
|
||||
'save subtask callback' => 'page_manager_term_view_save',
|
||||
|
||||
// Callback to add items to the page manager task administration form:
|
||||
'task admin' => 'page_manager_term_view_task_admin',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context',
|
||||
'get arguments' => 'page_manager_term_view_get_arguments',
|
||||
'get context placeholders' => 'page_manager_term_view_get_contexts',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_term_view_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_term_view_enable',
|
||||
'access callback' => 'page_manager_term_view_access_check',
|
||||
|
||||
// Allow additional operations
|
||||
'operations' => array(
|
||||
'settings' => array(
|
||||
'title' => t('Settings'),
|
||||
'description' => t('Edit name, path and other basic settings for the page.'),
|
||||
'form' => 'page_manager_term_view_settings',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_term_view_page_manager_tasks().
|
||||
*
|
||||
* Alter the term view input so that term view comes to us rather than the
|
||||
* normal term view process.
|
||||
*/
|
||||
function page_manager_term_view_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_term_view_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Override the term view handler for our purpose, but only if someone else
|
||||
// has not already done so.
|
||||
if (isset($items['taxonomy/term/%taxonomy_term']) && $items['taxonomy/term/%taxonomy_term']['page callback'] == 'taxonomy_term_page' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['taxonomy/term/%taxonomy_term']['page callback'] = 'page_manager_term_view_page';
|
||||
$items['taxonomy/term/%taxonomy_term']['file path'] = $task['path'];
|
||||
$items['taxonomy/term/%taxonomy_term']['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
// automatically disable this task if it cannot be enabled.
|
||||
variable_set('page_manager_term_view_disabled', TRUE);
|
||||
|
||||
if (isset($items['taxonomy/term/%taxonomy_term']['page callback'])) {
|
||||
$callback = $items['taxonomy/term/%taxonomy_term']['page callback'];
|
||||
}
|
||||
// Because Views changes %taxonomy_term to %views_arg, check to see if that
|
||||
// is why we can't enable:
|
||||
else if (isset($items['taxonomy/term/%views_arg']['page callback'])) {
|
||||
$callback = $items['taxonomy/term/%views_arg']['page callback'];
|
||||
}
|
||||
else {
|
||||
$callback = t('an unknown callback');
|
||||
}
|
||||
if (!empty($GLOBALS['page_manager_enabling_term_view'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable taxonomy/term/%taxonomy_term because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden term view.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* term view, which is term_page_view().
|
||||
*/
|
||||
function page_manager_term_view_page($term, $depth = NULL) {
|
||||
// Prep the term to be displayed so all of the regular hooks are triggered.
|
||||
// Rather than calling taxonomy_term_page() directly, as it that would
|
||||
// potentially load nodes that were not necessary, execute some of the code
|
||||
// prior to identifying the correct CTools or Page Manager task handler and
|
||||
// only proceed with the rest of the code if necessary.
|
||||
|
||||
// Assign the term name as the page title.
|
||||
drupal_set_title($term->name);
|
||||
|
||||
// If there is a menu link to this term, the link becomes the last part
|
||||
// of the active trail, and the link name becomes the page title.
|
||||
// Thus, we must explicitly set the page title to be the node title.
|
||||
$uri = entity_uri('taxonomy_term', $term);
|
||||
|
||||
// Set the term path as the canonical URL to prevent duplicate content.
|
||||
drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE);
|
||||
// Set the non-aliased path as a default shortlink.
|
||||
drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE);
|
||||
|
||||
// Trigger the main
|
||||
$build = taxonomy_term_show($term);
|
||||
|
||||
// Load my task plugin
|
||||
$task = page_manager_get_task('term_view');
|
||||
|
||||
// Load the term into a context.
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
$contexts = ctools_context_handler_get_task_contexts($task, '', array($term, $depth));
|
||||
|
||||
if (empty($contexts)) {
|
||||
return drupal_not_found();
|
||||
}
|
||||
|
||||
// Build the full output using the configured CTools plugin.
|
||||
$output = ctools_context_handler_render($task, '', $contexts, array($term->tid));
|
||||
if ($output !== FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Try loading an override plugin.
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('term_view')) && function_exists($rc)) {
|
||||
return $rc($node);
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back to replicating the output normally generated by
|
||||
// taxonomy_term_page().
|
||||
|
||||
// Build breadcrumb based on the hierarchy of the term.
|
||||
$current = (object) array(
|
||||
'tid' => $term->tid,
|
||||
);
|
||||
// @todo This overrides any other possible breadcrumb and is a pure hard-coded
|
||||
// presumption. Make this behavior configurable per vocabulary or term.
|
||||
$breadcrumb = array();
|
||||
while ($parents = taxonomy_get_parents($current->tid)) {
|
||||
$current = array_shift($parents);
|
||||
$breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
|
||||
}
|
||||
$breadcrumb[] = l(t('Home'), NULL);
|
||||
$breadcrumb = array_reverse($breadcrumb);
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
|
||||
|
||||
if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
|
||||
$nodes = node_load_multiple($nids);
|
||||
$build += node_view_multiple($nodes);
|
||||
$build['pager'] = array(
|
||||
'#theme' => 'pager',
|
||||
'#weight' => 5,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$build['no_content'] = array(
|
||||
'#prefix' => '<p>',
|
||||
'#markup' => t('There is currently no content classified with this term.'),
|
||||
'#suffix' => '</p>',
|
||||
);
|
||||
}
|
||||
return $build;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get arguments provided by this task handler.
|
||||
*
|
||||
* Since this is the term view and there is no UI on the arguments, we
|
||||
* create dummy arguments that contain the needed data.
|
||||
*/
|
||||
function page_manager_term_view_get_arguments($task, $subtask_id) {
|
||||
return array(
|
||||
array(
|
||||
'keyword' => 'term',
|
||||
'identifier' => page_manager_term_view_get_type() == 'multiple' ? t('Term(s) being viewed') : t('Term being viewed'),
|
||||
'id' => 1,
|
||||
'name' => page_manager_term_view_get_type() == 'multiple' ? 'terms' : 'term',
|
||||
'settings' => array('input_form' => 'tid', 'breadcrumb' => variable_get('page_manager_taxonomy_breadcrumb', TRUE)),
|
||||
'default' => '404',
|
||||
),
|
||||
array(
|
||||
'keyword' => 'depth',
|
||||
'identifier' => t('Depth'),
|
||||
'id' => 1,
|
||||
'name' => 'string',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get context placeholders provided by this handler.
|
||||
*/
|
||||
function page_manager_term_view_get_contexts($task, $subtask_id) {
|
||||
return ctools_context_get_placeholders_from_argument(page_manager_term_view_get_arguments($task, $subtask_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings page for this item.
|
||||
*/
|
||||
function page_manager_term_view_settings($form, &$form_state) {
|
||||
// This passes thru because the setting can also appear on the main Panels
|
||||
// settings form. If $settings is an array it will just pick up the default.
|
||||
$settings = isset($form_state->update_values) ? $form_state->update_values : array();
|
||||
return page_manager_term_view_admin_settings($form, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy form values into the page cache.
|
||||
*/
|
||||
function page_manager_term_view_settings_submit(&$form, &$form_state) {
|
||||
$form_state['page']->update_values = $form_state['values'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Save when the page cache is saved.
|
||||
*/
|
||||
function page_manager_term_view_save($subtask, $cache) {
|
||||
if (isset($cache->update_values)) {
|
||||
variable_set('page_manager_term_view_type', $cache->update_values['page_manager_term_view_type']);
|
||||
variable_set('page_manager_taxonomy_breadcrumb', $cache->update_values['page_manager_taxonomy_breadcrumb']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a setting to the Panels administrative form.
|
||||
*/
|
||||
function page_manager_term_view_admin_settings($form, $settings = array()) {
|
||||
if (empty($settings)) {
|
||||
$settings = array(
|
||||
'page_manager_term_view_type' => page_manager_term_view_get_type(),
|
||||
'page_manager_taxonomy_breadcrumb' => variable_get('page_manager_taxonomy_breadcrumb', TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
$form['page_manager_term_view_type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Allow multiple terms on taxonomy/term/%term'),
|
||||
'#options' => array('single' => t('Single term'), 'multiple' => t('Multiple terms')),
|
||||
'#description' => t('By default, Drupal allows multiple terms as an argument by separating them with commas or plus signs. If you set this to single, that feature will be disabled.') . ' ' . t('This feature does not currently work and is disabled.'),
|
||||
'#default_value' => $settings['page_manager_term_view_type'],
|
||||
// @todo -- fix this
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
$form['page_manager_taxonomy_breadcrumb'] = array(
|
||||
'#title' => t('Inject hierarchy of first term into breadcrumb trail'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['page_manager_taxonomy_breadcrumb'],
|
||||
'#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_term_view_enable($cache, $status) {
|
||||
variable_set('page_manager_term_view_disabled', $status);
|
||||
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_term_view'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
function page_manager_term_view_get_type() {
|
||||
// $view_type = variable_get('page_manager_term_view_type', 'multiple');
|
||||
// Revert to just allowing single.
|
||||
$view_type = 'single';
|
||||
|
||||
return $view_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a nice administrative summary of the page so an admin can see at a
|
||||
* glance what this page does and how it is configured.
|
||||
*/
|
||||
function page_manager_term_view_admin_summary($task, $subtask) {
|
||||
$task_name = page_manager_make_task_name($task['name'], $subtask['name']);
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Path')),
|
||||
array('class' => array('page-summary-data'), 'data' => 'taxonomy/term/%term'),
|
||||
array('class' => array('page-summary-operation'), 'data' => ''),
|
||||
);
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Access')),
|
||||
array('class' => array('page-summary-data'), 'data' => t('This page is publicly accessible.')),
|
||||
array('class' => array('page-summary-operation'), 'data' => ''),
|
||||
);
|
||||
|
||||
$menu = t('No menu entry');
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Menu')),
|
||||
array('class' => array('page-summary-data'), 'data' => $menu),
|
||||
array('class' => array('page-summary-operation'), 'data' => ''),
|
||||
);
|
||||
|
||||
if (page_manager_term_view_get_type() == 'multiple') {
|
||||
$message = t('Multiple terms may be used, separated by , or +.');
|
||||
}
|
||||
else {
|
||||
$message = t('Only a single term may be used.');
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('%term')),
|
||||
array('class' => array('page-summary-data'), 'data' => $message),
|
||||
array('class' => array('page-summary-operation'), 'data' => ''),
|
||||
);
|
||||
|
||||
if (variable_get('page_manager_taxonomy_breadcrumb', TRUE)) {
|
||||
$message = t('Breadcrumb trail will contain taxonomy term hierarchy');
|
||||
}
|
||||
else {
|
||||
$message = t('Breadcrumb trail will not contain taxonomy term hiearchy.');
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
array('class' => array('page-summary-label'), 'data' => t('Breadcrumb')),
|
||||
array('class' => array('page-summary-data'), 'data' => $message),
|
||||
array('class' => array('page-summary-operation'), 'data' => ''),
|
||||
);
|
||||
|
||||
$output = theme('table', array(), $rows, array('id' => 'page-manager-page-summary'));
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_term_view_access_check($task, $subtask_id, $contexts) {
|
||||
return user_access('access content');
|
||||
}
|
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Overrides the user profile display at user/%user.
|
||||
*
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_user_edit_page_manager_tasks() {
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
'title' => t('User Edit Template'),
|
||||
'admin title' => t('User edit template'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying user edit form at <em>user/%user/edit</em>.'),
|
||||
'admin path' => 'user/%user/edit',
|
||||
|
||||
// Callback to add items to the page managertask administration form:
|
||||
'task admin' => 'page_manager_user_edit_task_admin',
|
||||
|
||||
'hook menu' => 'page_manager_user_edit_menu',
|
||||
'hook menu alter' => 'page_manager_user_edit_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context', // handler type -- misnamed
|
||||
'get arguments' => 'page_manager_user_edit_get_arguments',
|
||||
'get context placeholders' => 'page_manager_user_edit_get_contexts',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_user_edit_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_user_edit_enable',
|
||||
'access callback' => 'page_manager_user_edit_access_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_user_view_page_manager_tasks().
|
||||
*
|
||||
* Alter the user view input so that user view comes to us rather than the
|
||||
* normal user view process.
|
||||
*/
|
||||
function page_manager_user_edit_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_user_edit_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Override the user view handler for our purpose.
|
||||
if ($items['user/%user/edit']['page callback'] == 'drupal_get_form' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['user/%user/edit']['page callback'] = 'page_manager_user_edit_page';
|
||||
$items['user/%user/edit']['page arguments'] = array(1);
|
||||
$items['user/%user/edit']['file path'] = $task['path'];
|
||||
$items['user/%user/edit']['file'] = $task['file'];
|
||||
if (($categories = _user_categories()) && (count($categories) > 1)) {
|
||||
foreach ($categories as $key => $category) {
|
||||
// 'account' is already handled by the MENU_DEFAULT_LOCAL_TASK.
|
||||
if ($category['name'] != 'account') {
|
||||
$items['user/%user_category/edit/' . $category['name']]['page callback'] = 'page_manager_user_edit_page';
|
||||
$items['user/%user_category/edit/' . $category['name']]['page arguments'] = array(1, 3);
|
||||
$items['user/%user_category/edit/' . $category['name']]['file path'] = $task['path'];
|
||||
$items['user/%user_category/edit/' . $category['name']]['file'] = $task['file'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// automatically disable this task if it cannot be enabled.
|
||||
variable_set('page_manager_user_edit_disabled', TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_user_edit'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable user/%user/edit because some other module already has overridden with %callback.', array('%callback' => $items['user/%user']['page callback'])), 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden user view.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* user edit, which is drupal_get_form('user_profile_form',$account).
|
||||
*/
|
||||
function page_manager_user_edit_page($account, $category = 'account') {
|
||||
// Store the category on the user for later usage.
|
||||
$account->user_category = $category;
|
||||
|
||||
// Load my task plugin:
|
||||
$task = page_manager_get_task('user_edit');
|
||||
|
||||
// Load the account into a context.
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
$contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
|
||||
// Build content. @todo -- this may not be right.
|
||||
user_build_content($account);
|
||||
|
||||
$output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
|
||||
if (is_array($output)) {
|
||||
$output = drupal_render($output);
|
||||
}
|
||||
if ($output != FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$function = 'drupal_get_form';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('user_edit')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back.
|
||||
if ($function == 'drupal_get_form') {
|
||||
|
||||
//In order to ajax fields to work we need to run form_load_include.
|
||||
//Hence we eschew drupal_get_form and manually build the info and
|
||||
//call drupal_build_form.
|
||||
$form_state = array();
|
||||
$form_id = 'user_profile_form';
|
||||
$args = array($account);
|
||||
$form_state['build_info']['args'] = $args;
|
||||
form_load_include($form_state, 'inc', 'user', 'user.pages');
|
||||
$output = drupal_build_form($form_id, $form_state);
|
||||
return $output;
|
||||
}
|
||||
//fire off "view" op so that triggers still work
|
||||
// @todo -- this doesn't work anymore, and the alternatives seem bad.
|
||||
// will have to figure out how to fix this.
|
||||
// user_module_invoke('view', $array = array(), $account);
|
||||
return $function($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get arguments provided by this task handler.
|
||||
*
|
||||
* Since this is the node view and there is no UI on the arguments, we
|
||||
* create dummy arguments that contain the needed data.
|
||||
*/
|
||||
function page_manager_user_edit_get_arguments($task, $subtask_id) {
|
||||
return array(
|
||||
array(
|
||||
'keyword' => 'user',
|
||||
'identifier' => t('User being edited'),
|
||||
'id' => 1,
|
||||
'name' => 'user_edit',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get context placeholders provided by this handler.
|
||||
*/
|
||||
function page_manager_user_edit_get_contexts($task, $subtask_id) {
|
||||
return ctools_context_get_placeholders_from_argument(page_manager_user_edit_get_arguments($task, $subtask_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_user_edit_enable($cache, $status) {
|
||||
variable_set('page_manager_user_edit_disabled', $status);
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_user_edit'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_user_edit_access_check($task, $subtask_id, $contexts) {
|
||||
$context = reset($contexts);
|
||||
return user_edit_access($context->data);
|
||||
}
|
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Overrides the user profile display at user/%user.
|
||||
*
|
||||
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
|
||||
* more information.
|
||||
*/
|
||||
function page_manager_user_view_page_manager_tasks() {
|
||||
return array(
|
||||
// This is a 'page' task and will fall under the page admin UI
|
||||
'task type' => 'page',
|
||||
'title' => t('User profile template'),
|
||||
'admin title' => t('User profile template'),
|
||||
'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying user profiles at <em>user/%user</em>. If you add variants, you may use selection criteria such as roles or user access to provide different views of user profiles. If no variant is selected, the default Drupal user view will be used. Please note that if you are using pathauto, aliases may make a node to be somewhere else, but as far as Drupal is concerned, they are still at user/%user.'),
|
||||
'admin path' => 'user/%user',
|
||||
|
||||
// Callback to add items to the page managertask administration form:
|
||||
'task admin' => 'page_manager_user_view_task_admin',
|
||||
|
||||
'hook menu' => 'page_manager_user_view_menu',
|
||||
'hook menu alter' => 'page_manager_user_view_menu_alter',
|
||||
|
||||
// This is task uses 'context' handlers and must implement these to give the
|
||||
// handler data it needs.
|
||||
'handler type' => 'context', // handler type -- misnamed
|
||||
'get arguments' => 'page_manager_user_view_get_arguments',
|
||||
'get context placeholders' => 'page_manager_user_view_get_contexts',
|
||||
|
||||
// Allow this to be enabled or disabled:
|
||||
'disabled' => variable_get('page_manager_user_view_disabled', TRUE),
|
||||
'enable callback' => 'page_manager_user_view_enable',
|
||||
'access callback' => 'page_manager_user_view_access_check',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defined by page_manager_user_view_page_manager_tasks().
|
||||
*
|
||||
* Alter the user view input so that user view comes to us rather than the
|
||||
* normal user view process.
|
||||
*/
|
||||
function page_manager_user_view_menu_alter(&$items, $task) {
|
||||
if (variable_get('page_manager_user_view_disabled', TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Override the user view handler for our purpose.
|
||||
if ($items['user/%user']['page callback'] == 'user_view_page' || variable_get('page_manager_override_anyway', FALSE)) {
|
||||
$items['user/%user']['page callback'] = 'page_manager_user_view_page';
|
||||
$items['user/%user']['file path'] = $task['path'];
|
||||
$items['user/%user']['file'] = $task['file'];
|
||||
}
|
||||
else {
|
||||
// automatically disable this task if it cannot be enabled.
|
||||
variable_set('page_manager_user_view_disabled', TRUE);
|
||||
if (!empty($GLOBALS['page_manager_enabling_user_view'])) {
|
||||
drupal_set_message(t('Page manager module is unable to enable user/%user because some other module already has overridden with %callback.', array('%callback' => $items['user/%user']['page callback'])), 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for our overridden user view.
|
||||
*
|
||||
* This function asks its assigned handlers who, if anyone, would like
|
||||
* to run with it. If no one does, it passes through to Drupal core's
|
||||
* user view, which is user_page_view().
|
||||
*/
|
||||
function page_manager_user_view_page($account) {
|
||||
// Load my task plugin:
|
||||
$task = page_manager_get_task('user_view');
|
||||
|
||||
// Load the account into a context.
|
||||
ctools_include('context');
|
||||
ctools_include('context-task-handler');
|
||||
$contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
|
||||
|
||||
// Build content. @todo -- this may not be right.
|
||||
user_build_content($account);
|
||||
|
||||
$output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
|
||||
if ($output != FALSE) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$function = 'user_view';
|
||||
foreach (module_implements('page_manager_override') as $module) {
|
||||
$call = $module . '_page_manager_override';
|
||||
if (($rc = $call('user_view')) && function_exists($rc)) {
|
||||
$function = $rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, fall back.
|
||||
if ($function == 'user_view') {
|
||||
module_load_include('inc', 'user', 'user.pages');
|
||||
}
|
||||
//fire off "view" op so that triggers still work
|
||||
// @todo -- this doesn't work anymore, and the alternatives seem bad.
|
||||
// will have to figure out how to fix this.
|
||||
// user_module_invoke('view', $array = array(), $account);
|
||||
return $function($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get arguments provided by this task handler.
|
||||
*
|
||||
* Since this is the node view and there is no UI on the arguments, we
|
||||
* create dummy arguments that contain the needed data.
|
||||
*/
|
||||
function page_manager_user_view_get_arguments($task, $subtask_id) {
|
||||
return array(
|
||||
array(
|
||||
'keyword' => 'user',
|
||||
'identifier' => t('User being viewed'),
|
||||
'id' => 1,
|
||||
'name' => 'entity_id:user',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get context placeholders provided by this handler.
|
||||
*/
|
||||
function page_manager_user_view_get_contexts($task, $subtask_id) {
|
||||
return ctools_context_get_placeholders_from_argument(page_manager_user_view_get_arguments($task, $subtask_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable/disable the page from the UI.
|
||||
*/
|
||||
function page_manager_user_view_enable($cache, $status) {
|
||||
variable_set('page_manager_user_view_disabled', $status);
|
||||
|
||||
// Set a global flag so that the menu routine knows it needs
|
||||
// to set a message if enabling cannot be done.
|
||||
if (!$status) {
|
||||
$GLOBALS['page_manager_enabling_user_view'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to determine if a page is accessible.
|
||||
*
|
||||
* @param $task
|
||||
* The task plugin.
|
||||
* @param $subtask_id
|
||||
* The subtask id
|
||||
* @param $contexts
|
||||
* The contexts loaded for the task.
|
||||
* @return
|
||||
* TRUE if the current user can access the page.
|
||||
*/
|
||||
function page_manager_user_view_access_check($task, $subtask_id, $contexts) {
|
||||
$context = reset($contexts);
|
||||
return user_view_access($context->data);
|
||||
}
|
Reference in New Issue
Block a user