first import
This commit is contained in:
83
sites/all/modules/panels/includes/add-content.inc
Normal file
83
sites/all/modules/panels/includes/add-content.inc
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains template preprocess files for the add content modal themes.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Preprocess the primary entry level theme.
|
||||
*/
|
||||
function template_preprocess_panels_add_content_modal(&$vars) {
|
||||
// Process the list of categories.
|
||||
foreach ($vars['categories'] as $key => $category_info) {
|
||||
// 'root' category is actually displayed under the categories, so
|
||||
// skip it.
|
||||
if ($key == 'root') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$class = 'panels-modal-add-category';
|
||||
if ($key == $vars['category']) {
|
||||
$class .= ' active';
|
||||
}
|
||||
|
||||
$url = $vars['renderer']->get_url('select-content', $vars['region'], $key);
|
||||
$vars['categories_array'][] = ctools_ajax_text_button($category_info['title'], $url, '', $class);
|
||||
}
|
||||
|
||||
// Now render the top level buttons (aka the root category) if any.
|
||||
$vars['root_content'] = '';
|
||||
if (!empty($vars['categories']['root'])) {
|
||||
foreach ($vars['categories']['root']['content'] as $content_type) {
|
||||
$vars['root_content'] .= theme('panels_add_content_link', array('renderer' => $vars['renderer'], 'region' => $vars['region'], 'content_type' => $content_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the panels add content modal.
|
||||
*
|
||||
* This is run here so that preprocess can make changes before links are
|
||||
* actually rendered.
|
||||
*/
|
||||
function template_process_panels_add_content_modal(&$vars) {
|
||||
$content = !empty($vars['categories'][$vars['category']]['content']) ? $vars['categories'][$vars['category']]['content'] : array();
|
||||
|
||||
// If no category is selected or the category is empty or our special empty
|
||||
// category render a 'header' that will appear instead of the columns.
|
||||
if (empty($vars['category']) || empty($content) || $vars['category'] == 'root') {
|
||||
$vars['header'] = t('Content options are divided by category. Please select a category from the left to proceed.');
|
||||
}
|
||||
else {
|
||||
$titles = array_keys($content);
|
||||
natcasesort($titles);
|
||||
|
||||
// This will default to 2 columns in the theme definition but could be
|
||||
// changed by a preprocess. Ensure there is at least one column.
|
||||
$columns = max(1, $vars['column_count']);
|
||||
$vars['columns'] = array_fill(1, $columns, '');
|
||||
|
||||
$col_size = count($titles) / $columns;
|
||||
$count = 0;
|
||||
foreach ($titles as $title) {
|
||||
$which = floor($count++ / $col_size) + 1;
|
||||
$vars['columns'][$which] .= theme('panels_add_content_link', array('renderer' => $vars['renderer'], 'region' => $vars['region'], 'content_type' => $content[$title]));
|
||||
}
|
||||
}
|
||||
|
||||
$vars['messages'] = theme('status_messages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess the add content link used in the modal.
|
||||
*/
|
||||
function template_preprocess_panels_add_content_link(&$vars) {
|
||||
$vars['title'] = filter_xss_admin($vars['content_type']['title']);
|
||||
$vars['description'] = isset($vars['content_type']['description']) ? $vars['content_type']['description'] : $vars['title'];
|
||||
$vars['icon'] = ctools_content_admin_icon($vars['content_type']);
|
||||
$vars['url'] = $vars['renderer']->get_url('add-pane', $vars['region'], $vars['content_type']['type_name'], $vars['content_type']['subtype_name']);
|
||||
|
||||
$vars['image_button'] = ctools_ajax_image_button($vars['icon'], $vars['url'], $vars['description'], 'panels-modal-add-config');
|
||||
$vars['text_button'] = ctools_ajax_text_button($vars['title'], $vars['url'], $vars['description'], 'panels-modal-add-config');
|
||||
}
|
205
sites/all/modules/panels/includes/callbacks.inc
Normal file
205
sites/all/modules/panels/includes/callbacks.inc
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* @file callbacks.inc
|
||||
* Minor menu callbacks for Panels helpers.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A central administrative page for Panels.
|
||||
*/
|
||||
function panels_admin_page() {
|
||||
// @todo I think this should return a renderable array somehow?
|
||||
return theme('panels_dashboard');
|
||||
}
|
||||
|
||||
function panels_dashboard_final_blocks(&$vars) {
|
||||
// Add in links for missing modules that we still want to mention:
|
||||
if (empty($vars['links']['page_manager'])) {
|
||||
$vars['links']['page_manager'] = array(
|
||||
'weight' => -100,
|
||||
'title' => t('Panel page'),
|
||||
'description' => '<em>' . t('You must activate the page manager module for this functionality.') . '</em>',
|
||||
);
|
||||
}
|
||||
if (empty($vars['links']['panels_mini'])) {
|
||||
$vars['links']['panels_mini'] = array(
|
||||
'title' => t('Mini panel'),
|
||||
'description' => '<em>' . t('You must activate the Mini panels module for this functionality.') . '</em>',
|
||||
);
|
||||
}
|
||||
if (empty($vars['links']['panels_node'])) {
|
||||
$vars['links']['panels_mini'] = array(
|
||||
'title' => t('Panel node'),
|
||||
'description' => '<em>' . t('You must activate the panel node module for this functionality.') . '</em>',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_panels_dashboard_blocks().
|
||||
*
|
||||
* Adds page information to the Panels dashboard.
|
||||
*/
|
||||
function panels_panels_dashboard_blocks(&$vars) {
|
||||
$vars['links']['panels_layout'] = array(
|
||||
'title' => l(t('Custom layout'), 'admin/structure/panels/layouts/add'),
|
||||
'description' => t('Custom layouts can add more, site-specific layouts that you can use in your panels.'),
|
||||
);
|
||||
|
||||
// Load all mini panels and their displays.
|
||||
ctools_include('export');
|
||||
$items = ctools_export_crud_load_all('panels_layout');
|
||||
$count = 0;
|
||||
$rows = array();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$rows[] = array(
|
||||
check_plain($item->admin_title),
|
||||
array(
|
||||
'data' => l(t('Edit'), "admin/structure/panels/layouts/list/$item->name/edit"),
|
||||
'class' => 'links',
|
||||
),
|
||||
);
|
||||
|
||||
// Only show 10.
|
||||
if (++$count >= 10) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($rows) {
|
||||
$content = theme('table', array('rows' => $rows, 'attributes' => array('class' => 'panels-manage')));
|
||||
}
|
||||
else {
|
||||
$content = '<p>' . t('There are no custom layouts.') . '</p>';
|
||||
}
|
||||
|
||||
$vars['blocks']['panels_layout'] = array(
|
||||
'title' => t('Manage custom layouts'),
|
||||
'link' => l(t('Go to list'), 'admin/structure/panels/layouts'),
|
||||
'content' => $content,
|
||||
'class' => 'dashboard-layouts',
|
||||
'section' => 'right',
|
||||
);
|
||||
}
|
||||
|
||||
function template_preprocess_panels_dashboard(&$vars) {
|
||||
ctools_add_css('panels-dashboard', 'panels');
|
||||
ctools_include('plugins');
|
||||
|
||||
$vars['image_path'] = ctools_image_path('', 'panels');
|
||||
|
||||
$vars['links'] = array();
|
||||
$vars['blocks'] = array();
|
||||
|
||||
foreach (module_implements('panels_dashboard_blocks') as $module) {
|
||||
$function = $module . '_panels_dashboard_blocks';
|
||||
$function($vars);
|
||||
}
|
||||
|
||||
// Add in any default links for modules that are not active
|
||||
panels_dashboard_final_blocks($vars);
|
||||
|
||||
// If page manager module is enabled, add a very low eight block to
|
||||
// list the page wizards.
|
||||
if (module_exists('page_manager')) {
|
||||
$vars['blocks']['wizards'] = array(
|
||||
'weight' => -101,
|
||||
'section' => 'right',
|
||||
'title' => t('Page wizards'),
|
||||
'content' => '',
|
||||
'class' => 'dashboard-wizards',
|
||||
);
|
||||
|
||||
ctools_include('page-wizard');
|
||||
$plugins = page_manager_get_page_wizards();
|
||||
uasort($plugins, 'ctools_plugin_sort');
|
||||
|
||||
foreach ($plugins as $id => $plugin) {
|
||||
if (isset($plugin['type']) && $plugin['type'] == 'panels') {
|
||||
$link = array(
|
||||
'title' => l($plugin['title'], 'admin/structure/pages/wizard/' . $id),
|
||||
'description' => $plugin['description'],
|
||||
);
|
||||
|
||||
$vars['blocks']['wizards']['content'] .= theme('panels_dashboard_link', array('link' => $link));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uasort($vars['links'], 'ctools_plugin_sort');
|
||||
|
||||
$vars['blocks']['links'] = array(
|
||||
'weight' => -100,
|
||||
'section' => 'left',
|
||||
'title' => t('Create new') . '...',
|
||||
'content' => '',
|
||||
'class' => 'dashboard-create',
|
||||
);
|
||||
|
||||
// Turn the links into a block
|
||||
foreach ($vars['links'] as $link) {
|
||||
$vars['blocks']['links']['content'] .= theme('panels_dashboard_link', array('link' => $link));
|
||||
}
|
||||
|
||||
uasort($vars['blocks'], 'ctools_plugin_sort');
|
||||
|
||||
$vars['left'] = '';
|
||||
$vars['right'] = '';
|
||||
|
||||
// Render all the blocks
|
||||
foreach ($vars['blocks'] as $block) {
|
||||
$section = !empty($block['section']) ? $block['section'] : 'left';
|
||||
$vars[$section] .= theme('panels_dashboard_block', array('block' => $block));
|
||||
}
|
||||
}
|
||||
|
||||
function panels_admin_settings_page() {
|
||||
$form = array();
|
||||
if (module_exists('page_manager')) {
|
||||
foreach (page_manager_get_tasks() as $task) {
|
||||
if ($function = ctools_plugin_get_function($task, 'admin settings')) {
|
||||
$function($form);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctools_include('content');
|
||||
foreach (ctools_get_content_types() as $content) {
|
||||
if ($function = ctools_plugin_get_function($content, 'admin settings')) {
|
||||
$function($form);
|
||||
}
|
||||
}
|
||||
|
||||
ctools_include('plugins', 'panels');
|
||||
$pipelines = panels_get_renderer_pipelines();
|
||||
$options = array();
|
||||
foreach ($pipelines as $key => $value) {
|
||||
$options[$key] = $value->admin_title;
|
||||
}
|
||||
if (count($options) > 1) {
|
||||
$form['panels_renderer_default'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Default renderer'),
|
||||
'#options' => $options,
|
||||
'#default_value' => variable_get('panels_renderer_default', 'standard'),
|
||||
'#description' => t('The default renderer for new panel pages.'),
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($form)) {
|
||||
return array('#value' => t('There are currently no settings to change, but additional plugins or modules may provide them in the future.'));
|
||||
}
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings for panel contexts created by the page manager.
|
||||
*/
|
||||
function panels_admin_panel_context_page() {
|
||||
ctools_include('common', 'panels');
|
||||
return drupal_get_form('panels_common_settings', 'panels_page');
|
||||
}
|
||||
|
614
sites/all/modules/panels/includes/common.inc
Normal file
614
sites/all/modules/panels/includes/common.inc
Normal file
@@ -0,0 +1,614 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Functions used by more than one panels client module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class definition for the allowed layouts governing structure.
|
||||
*
|
||||
* @ingroup mainapi
|
||||
*
|
||||
* This class is designed to handle panels allowed layouts data from start to finish, and sees
|
||||
* action at two times:\n
|
||||
* - When a client module wants to generate a form allowing an admin to create or edit a set
|
||||
* of allowed layouts. In this case, either a new panels_allowed_layouts object is created
|
||||
* or one is retrieved from storage and panels_allowed_layouts::set_allowed() is called to
|
||||
* generate the allowed layouts form. \n
|
||||
* - When a client module is calling panels_edit_layout(), a saved instantiation of this object
|
||||
* can be called up and passed in to the fourth parameter, and only the allowed layouts saved
|
||||
* in that object will be displayed on the form. \n
|
||||
* Because the panels API does not impose a data structure on the allowed_layouts data, client
|
||||
* modules can create as many of these objects as they want, and organize them around any concept:
|
||||
* node types, date published, author roles...anything.
|
||||
*
|
||||
* To call the settings form, instantiate this class - or, if your client module's needs are
|
||||
* heavy-duty, extend this class and instantiate your subclass - assign values to any relevant
|
||||
* desired members, and call panels_allowed_layouts::set_allowed(). See the documentation on
|
||||
* that method for a sample implementation.
|
||||
*
|
||||
* Note that when unserializing saved tokens of this class, you must
|
||||
* run panels_load_include('common') before unserializing in order to ensure
|
||||
* that the object is properly loaded.
|
||||
*
|
||||
* Client modules extending this class should implement a save() method and use it for
|
||||
* their custom data storage routine. You'll need to rewrite other class methods if
|
||||
* you choose to go another route.
|
||||
*
|
||||
* @see panels_edit_layout()
|
||||
* @see _panels_edit_layout()
|
||||
*
|
||||
*/
|
||||
class panels_allowed_layouts {
|
||||
|
||||
/**
|
||||
* Specifies whether newly-added layouts (as in, new .inc files) should be automatically
|
||||
* allowed (TRUE) or disallowed (FALSE) for $this. Defaults to TRUE, which is more
|
||||
* permissive but less of an administrative hassle if/when you add new layouts. Note
|
||||
* that this parameter will be derived from $allowed_layouts if a value is passed in.
|
||||
*/
|
||||
var $allow_new = TRUE;
|
||||
|
||||
/**
|
||||
* Optional member. If provided, the Panels API will generate a drupal variable using
|
||||
* variable_set($module_name . 'allowed_layouts', serialize($this)), thereby handling the
|
||||
* storage of this object entirely within the Panels API. This object will be
|
||||
* called and rebuilt by panels_edit_layout() if the same $module_name string is passed in
|
||||
* for the $allowed_types parameter. \n
|
||||
* This is primarily intended for convenience - client modules doing heavy-duty implementations
|
||||
* of the Panels API will probably want to create their own storage method.
|
||||
* @see panels_edit_layout()
|
||||
*/
|
||||
var $module_name = NULL;
|
||||
|
||||
/**
|
||||
* An associative array of all available layouts, keyed by layout name (as defined
|
||||
* in the corresponding layout plugin definition), with value = 1 if the layout is
|
||||
* allowed, and value = 0 if the layout is not allowed.
|
||||
* Calling array_filter(panels_allowed_layouts::$allowed_layout_settings) will return an associative array
|
||||
* containing only the allowed layouts, and wrapping that in array_keys() will
|
||||
* return an indexed version of that array.
|
||||
*/
|
||||
var $allowed_layout_settings = array();
|
||||
|
||||
/**
|
||||
* Hack-imitation of D6's $form_state. Used by the panels_common_set_allowed_types()
|
||||
* form to indicate whether the returned value is in its 'render', 'failed-validate',
|
||||
* or 'submit' stage.
|
||||
*/
|
||||
var $form_state;
|
||||
|
||||
/**
|
||||
* Constructor function; loads the $allowed_layout_settings array with initial values according
|
||||
* to $start_allowed
|
||||
*
|
||||
* @param bool $start_allowed
|
||||
* $start_allowed determines whether all available layouts will be marked
|
||||
* as allowed or not allowed on the initial call to panels_allowed_layouts::set_allowed()
|
||||
*
|
||||
*/
|
||||
function panels_allowed_layouts($start_allowed = TRUE) {
|
||||
// TODO would be nice if there was a way to just fetch the names easily
|
||||
foreach ($this->list_layouts() as $layout_name) {
|
||||
$this->allowed_layout_settings[$layout_name] = $start_allowed ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage panels_common_set_allowed_layouts(), the FAPI code for selecting allowed layouts.
|
||||
*
|
||||
* MAKE SURE to set panels_allowed_layouts::allow_new before calling this method. If you want the panels API
|
||||
* to handle saving these allowed layout settings, panels_allowed_layouts::module_name must also be set.
|
||||
*
|
||||
* Below is a sample implementation; refer to the rest of the class documentation to understand all the
|
||||
* specific pieces. Values that are intended to be replaced are wrapped with <>.
|
||||
*
|
||||
* \n @code
|
||||
* function docdemo_allowed_layouts() {
|
||||
* ctools_include('common', 'panels');
|
||||
* if (!is_a($allowed_layouts = unserialize(variable_get('panels_common_allowed_layouts', serialize(''))), 'panels_allowed_layouts')) {
|
||||
* $allowed_layouts = new panels_allowed_layouts();
|
||||
* $allowed_layouts->allow_new = TRUE;
|
||||
* $allowed_layouts->module_name = '<client_module_name>';
|
||||
* }
|
||||
* $result = $allowed_layouts->set_allowed('<Desired client module form title>');
|
||||
* if (in_array($allowed_layouts->form_state, array('failed-validate', 'render'))) {
|
||||
* return $result;
|
||||
* }
|
||||
* elseif ($allowed_layouts->form_state == 'submit') {
|
||||
* drupal_goto('</path/to/desired/redirect>');
|
||||
* }
|
||||
* }
|
||||
* @endcode \n
|
||||
*
|
||||
* If $allowed_layouts->form_state == 'failed-validate' || 'render', then you'll need to return
|
||||
* $result as it contains the structured form HTML generated by drupal_render_form() and is ready
|
||||
* to be passed through index.php's call to theme('page', ...).
|
||||
*
|
||||
* However, if $allowed_layouts->form_state == 'submit', then the form has been submitted and we should
|
||||
* react. It's really up to your client module how you handle the rest; panels_allowed_layouts::save() (or
|
||||
* panels_allowed_layouts::api_save(), if that's the route you're going) will have already been called,
|
||||
* so if those methods handle your save routine, then all there is left to do is handle redirects, if you
|
||||
* want. The current implementation of the allowed layouts form currently never redirects, so it's up to
|
||||
* you to control where the user ends up next.
|
||||
*
|
||||
* @param string $title
|
||||
* Used to set the title of the allowed layouts form. If no value is given, defaults to
|
||||
* 'Panels: Allowed Layouts'.
|
||||
*
|
||||
* @return mixed $result
|
||||
* - On the first passthrough when the form is being rendered, $result is the form's structured
|
||||
* HTML, ready to be pushed to the screen with a call to theme('page', ...).
|
||||
* - A successful second passthrough indicates a successful submit, and
|
||||
* $result === panels_allowed_layouts::allowed_layout_settings. Returning it is simply for convenience.
|
||||
*/
|
||||
function set_allowed($title = 'Panels: Allowed Layouts') {
|
||||
$this->sync_with_available();
|
||||
$form_id = 'panels_common_set_allowed_layouts';
|
||||
// TODO switch to drupal_build_form(); need to pass by ref
|
||||
$form = drupal_retrieve_form($form_id, $this, $title);
|
||||
|
||||
if ($result = drupal_process_form($form_id, $form)) {
|
||||
// successful submit
|
||||
$this->form_state = 'submit';
|
||||
return $result;
|
||||
}
|
||||
$this->form_state = isset($_POST['op']) ? 'failed-validate' : 'render';
|
||||
$result = drupal_render_form($form_id, $form);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for newly-added layouts and deleted layouts. If any are found, updates panels_allowed_layouts::allowed_layout_settings;
|
||||
* new additions are made according to panels_allowed_layouts::allow_new, while deletions are unset().
|
||||
*
|
||||
* Note that any changes made by this function are not saved in any permanent location.
|
||||
*/
|
||||
function sync_with_available() {
|
||||
$layouts = $this->list_layouts();
|
||||
foreach (array_diff($layouts, array_keys($this->allowed_layout_settings)) as $new_layout) {
|
||||
$this->allowed_layout_settings[$new_layout] = $this->allow_new ? 1 : 0;
|
||||
}
|
||||
foreach (array_diff(array_keys($this->allowed_layout_settings), $layouts) as $deleted_layout) {
|
||||
unset($this->allowed_layout_settings[$deleted_layout]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use panels_allowed_layouts::module_name to generate a variable for variable_set(), in which
|
||||
* a serialized version of $this will be stored.
|
||||
*
|
||||
* Does nothing if panels_allowed_layouts::module_name is not set.
|
||||
*
|
||||
* IMPORTANT NOTE: if you use variable_get() in a custom client module save() method, you MUST
|
||||
* wrap $this in serialize(), then unserialize() what you get from variable_get(). Failure to
|
||||
* do so will result in an incomplete object. The following code will work:
|
||||
* @code
|
||||
* $allowed_layouts = unserialize(variable_get('your_variable_name', serialize(''));
|
||||
* @endcode
|
||||
*
|
||||
* If you don't serialize the second parameter of variable_get() and the variable name you provide
|
||||
* can't be found, an E_STRICT warning will be generated for trying to unserialize an entity
|
||||
* that has not been serialized.
|
||||
*
|
||||
*/
|
||||
function save() {
|
||||
if (!is_null($this->module_name)) {
|
||||
variable_set($this->module_name . "_allowed_layouts", serialize($this));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Snag a list of the current layouts for internal use.
|
||||
*
|
||||
* Data is not saved in a class member in order to ensure that it's
|
||||
* fresh.
|
||||
*
|
||||
* @return array $layouts
|
||||
* An indexed array of the system names for all currently available layouts.
|
||||
*/
|
||||
function list_layouts() {
|
||||
static $layouts = array();
|
||||
if (empty($layouts)) {
|
||||
ctools_include('plugins', 'panels');
|
||||
$layouts = array_keys(panels_get_layouts());
|
||||
}
|
||||
return $layouts;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A common settings page for Panels modules, because this code is relevant to
|
||||
* any modules that don't already have special requirements.
|
||||
*/
|
||||
function panels_common_settings($form, &$form_state, $module_name = 'panels_common') {
|
||||
ctools_include('plugins', 'panels');
|
||||
ctools_include('content');
|
||||
$content_types = ctools_get_content_types();
|
||||
$skip = FALSE;
|
||||
|
||||
$default_types = variable_get($module_name . '_default', NULL);
|
||||
if (!isset($default_types)) {
|
||||
$default_types = array('other' => TRUE);
|
||||
$skip = TRUE;
|
||||
}
|
||||
|
||||
foreach ($content_types as $id => $info) {
|
||||
if (empty($info['single'])) {
|
||||
$default_options[$id] = t('New @s', array('@s' => $info['title']));
|
||||
if ($skip) {
|
||||
$default_types[$id] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$default_options['other'] = t('New content of other types');
|
||||
|
||||
$form['additional_settings'] = array(
|
||||
'#type' => 'vertical_tabs',
|
||||
);
|
||||
|
||||
$form['common'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('New content behavior'),
|
||||
'#group' => 'additional_settings',
|
||||
'#weight' => -10,
|
||||
);
|
||||
$form['common']['panels_common_default'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#description' => t('Select the default behavior of new content added to the system. If checked, new content will automatically be immediately available to be added to Panels pages. If not checked, new content will not be available until specifically allowed here.'),
|
||||
'#options' => $default_options,
|
||||
'#default_value' => array_keys(array_filter($default_types)),
|
||||
);
|
||||
|
||||
$form_state['skip'] = $skip;
|
||||
if ($skip) {
|
||||
$form['markup'] = array('#value' => t('<p>Click Submit to be presented with a complete list of available content types set to the defaults you selected.</p>'));
|
||||
}
|
||||
else {
|
||||
// Rebuild the entire list, setting appropriately from defaults. Give
|
||||
// each type its own checkboxes set unless it's 'single' in which
|
||||
// case it can go into our fake other set.
|
||||
$available_content_types = ctools_content_get_all_types();
|
||||
$allowed_content_types = variable_get($module_name . '_allowed_types', array());
|
||||
|
||||
foreach ($available_content_types as $id => $types) {
|
||||
foreach ($types as $type => $info) {
|
||||
$key = $id . '-' . $type;
|
||||
$checkboxes = empty($content_types[$id]['single']) ? $id : 'other';
|
||||
$options[$checkboxes][$key] = $info['title'];
|
||||
if (!isset($allowed_content_types[$key])) {
|
||||
$allowed[$checkboxes][$key] = isset($default_types[$id]) ? $default_types[$id] : $default_types['other'];
|
||||
}
|
||||
else {
|
||||
$allowed[$checkboxes][$key] = $allowed_content_types[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form['content_types'] = array(
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
// cheat a bit
|
||||
$content_types['other'] = array('title' => t('Other'), 'weight' => 10);
|
||||
foreach ($content_types as $id => $info) {
|
||||
if (isset($allowed[$id])) {
|
||||
|
||||
$form['content_types'][$id] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#group' => 'additional_settings',
|
||||
'#title' => t('Allowed @s content', array('@s' => $info['title'])),
|
||||
);
|
||||
|
||||
$form['content_types'][$id]['options'] = array(
|
||||
'#prefix' => '<div class="panels-page-type-container">',
|
||||
'#suffix' => '</div>',
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options[$id],
|
||||
'#default_value' => array_keys(array_filter($allowed[$id])),
|
||||
'#checkall' => TRUE,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Layout selection.
|
||||
panels_common_allowed_layouts_form($form, $form_state, $module_name);
|
||||
|
||||
$form['allowed'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => isset($allowed) ? array_keys($allowed) : array(),
|
||||
);
|
||||
|
||||
$form['module_name'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $module_name,
|
||||
);
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
|
||||
ctools_add_css('panels_page', 'panels');
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit hook for panels_common_settings
|
||||
*/
|
||||
function panels_common_settings_validate($form, &$form_state) {
|
||||
panels_common_allowed_layouts_form_validate($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit hook for panels_common_settings
|
||||
*/
|
||||
function panels_common_settings_submit($form, &$form_state) {
|
||||
panels_common_allowed_layouts_form_submit($form, $form_state);
|
||||
$module_name = $form_state['values']['module_name'];
|
||||
variable_set($module_name . '_default', $form_state['values']['panels_common_default']);
|
||||
if (!$form_state['skip']) {
|
||||
// merge the broken apart array neatly back together
|
||||
$allowed = $form_state['values']['allowed'];
|
||||
$allowed_content_types = array();
|
||||
foreach ($form_state['values']['allowed'] as $allowed) {
|
||||
$allowed_content_types = array_merge($allowed_content_types, $form_state['values']['content_types'][$allowed]['options']);
|
||||
}
|
||||
variable_set($module_name . '_allowed_types', $allowed_content_types);
|
||||
}
|
||||
drupal_set_message(t('Your changes have been saved.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Based upon the settings, get the allowed types for this node.
|
||||
*/
|
||||
function panels_common_get_allowed_types($module, $contexts = array(), $has_content = FALSE, $default_defaults = array(), $default_allowed_types = array()) {
|
||||
// Get a list of all types that are available
|
||||
|
||||
$default_types = variable_get($module . '_default', $default_defaults);
|
||||
$allowed_types = variable_get($module . '_allowed_types', $default_allowed_types);
|
||||
|
||||
// By default, if they haven't gone and done the initial setup here,
|
||||
// let all 'other' types (which will be all types) be available.
|
||||
if (!isset($default_types['other'])) {
|
||||
$default_types['other'] = TRUE;
|
||||
}
|
||||
|
||||
ctools_include('content');
|
||||
$content_types = ctools_content_get_available_types($contexts, $has_content, $allowed_types, $default_types);
|
||||
|
||||
return $content_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* The FAPI code for generating an 'allowed layouts' selection form.
|
||||
*
|
||||
* NOTE: Because the Panels API does not guarantee a particular method of storing the data on allowed layouts,
|
||||
* it is not_possible for the Panels API to implement any checks that determine whether reductions in
|
||||
* the set of allowed layouts conflict with pre-existing layout selections. $displays in that category
|
||||
* will continue to function with their current layout as normal until the user/owner/admin attempts
|
||||
* to change layouts on that display, at which point they will have to select from the new set of
|
||||
* allowed layouts. If this is not the desired behavior for your client module, it's up to you to
|
||||
* write a validation routine that determines what should be done with conflicting layouts.
|
||||
*
|
||||
* Remember that changing layouts where panes have already been created can result in data loss;
|
||||
* consult panels_change_layout() to see how the Panels API handles that process. Running
|
||||
* drupal_execute('panels_change_layout', ...) is one possible starting point.
|
||||
*
|
||||
* @ingroup forms
|
||||
*
|
||||
* @param array $allowed_layouts
|
||||
* The set of allowed layouts that should be used as the default values
|
||||
* for this form. If none is provided, then by default no layouts will be restricted.
|
||||
*/
|
||||
function panels_common_allowed_layouts_form(&$form, &$form_state, $module_name) {
|
||||
// Fetch our allowed layouts from variables.
|
||||
$allowed_layouts = panels_common_get_allowed_layout_object($module_name);
|
||||
|
||||
$layouts = panels_get_layouts();
|
||||
foreach ($layouts as $id => $layout) {
|
||||
$options[$id] = panels_print_layout_icon($id, $layout, check_plain($layout['title']));
|
||||
}
|
||||
|
||||
$form_state['allowed_layouts'] = &$allowed_layouts;
|
||||
|
||||
ctools_add_js('layout', 'panels');
|
||||
|
||||
$form['layout_selection'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Select allowed layouts'),
|
||||
'#group' => 'additional_settings',
|
||||
'#weight' => 10,
|
||||
);
|
||||
$form['layout_selection']['layouts'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options,
|
||||
'#description' => t('Check the boxes for all layouts you want to allow users choose from when picking a layout. You must allow at least one layout.'),
|
||||
'#default_value' => array_keys(array_filter($allowed_layouts->allowed_layout_settings)),
|
||||
'#prefix' => '<div class="clearfix panels-layouts-checkboxes">',
|
||||
'#suffix' => '</div>',
|
||||
'#checkall' => TRUE,
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function panels_common_allowed_layouts_form_validate($form, &$form_state) {
|
||||
$selected = array_filter($form_state['values']['layouts']);
|
||||
if (empty($selected)) {
|
||||
form_set_error('layouts', 'You must choose at least one layout to allow.');
|
||||
}
|
||||
}
|
||||
|
||||
function panels_common_allowed_layouts_form_submit($form, &$form_state) {
|
||||
foreach ($form_state['values']['layouts'] as $layout => $setting) {
|
||||
$form_state['allowed_layouts']->allowed_layout_settings[$layout] = (bool) $setting;
|
||||
}
|
||||
$form_state['allowed_layouts']->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the allowed layout object for the given module.
|
||||
*/
|
||||
function panels_common_get_allowed_layout_object($module_name) {
|
||||
$allowed_layouts = unserialize(variable_get($module_name . "_allowed_layouts", serialize('')));
|
||||
|
||||
// if no parameter was provided, or the variable_get failed
|
||||
if (!$allowed_layouts) {
|
||||
// still no dice. simply creates a dummy version where all layouts
|
||||
// are allowed.
|
||||
$allowed_layouts = new panels_allowed_layouts();
|
||||
$allowed_layouts->allow_new = TRUE;
|
||||
$allowed_layouts->module_name = $module_name;
|
||||
}
|
||||
|
||||
// sanitize allowed layout listing; this is redundant if the
|
||||
// $allowed_layouts param was null, but the data is cached anyway
|
||||
$allowed_layouts->sync_with_available();
|
||||
|
||||
return $allowed_layouts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the allowed layouts for the given module.
|
||||
*/
|
||||
function panels_common_get_allowed_layouts($module_name) {
|
||||
ctools_include('plugins', 'panels');
|
||||
$available_layouts = panels_get_layouts();
|
||||
if (empty($module_name)) {
|
||||
return $available_layouts;
|
||||
}
|
||||
else if (is_object($module_name)) {
|
||||
$allowed_layouts = $module_name;
|
||||
}
|
||||
else {
|
||||
$allowed_layouts = panels_common_get_allowed_layout_object($module_name);
|
||||
}
|
||||
|
||||
$allowed = array_filter($allowed_layouts->allowed_layout_settings);
|
||||
$order = array();
|
||||
foreach ($available_layouts as $name => $plugin) {
|
||||
if (!empty($allowed[$name])) {
|
||||
$order[$name] = $plugin['category'] . ':' . $plugin['title'];
|
||||
}
|
||||
}
|
||||
|
||||
// Sort
|
||||
$layouts = array();
|
||||
|
||||
asort($order);
|
||||
foreach ($order as $name => $junk) {
|
||||
$layouts[$name] = $available_layouts[$name];
|
||||
}
|
||||
|
||||
return $layouts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a visible list of content in a display.
|
||||
* Note that the contexts must be pre-loaded.
|
||||
*/
|
||||
function theme_panels_common_content_list($vars) {
|
||||
$display = $vars['display'];
|
||||
|
||||
$layout = panels_get_layout($display->layout);
|
||||
$content = '<dl class="content-list">';
|
||||
foreach (panels_get_regions($layout, $display) as $panel_id => $title) {
|
||||
$content .= "<dt>$title</dt><dd>";
|
||||
if (!empty($display->panels[$panel_id])) {
|
||||
$content .= '<ol>';
|
||||
foreach ($display->panels[$panel_id] as $pid) {
|
||||
$content .= '<li>' . panels_get_pane_title($display->content[$pid], $display->context) . '</li>';
|
||||
}
|
||||
$content .= '</ol>';
|
||||
}
|
||||
else {
|
||||
$content .= t('Empty');
|
||||
}
|
||||
$content .= '</dd>';
|
||||
}
|
||||
$content .= '</dl>';
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a selector of layouts, each linked to the next step.
|
||||
*
|
||||
* Most operations use radio buttons for selecting layouts, but some will
|
||||
* give each layout as a link that goes to the next step. This function
|
||||
* makes it easy to simply provide a list of allowed layouts and the base
|
||||
* path.
|
||||
*
|
||||
* One limitation is that it will only append the layout name to the end, so
|
||||
* if the actual layout name is needed in the middle, that can't happen.
|
||||
*
|
||||
* @return
|
||||
* The rendered output.
|
||||
*/
|
||||
function panels_common_print_layout_links($layouts, $base_path, $link_options = array(), $current_layout = NULL) {
|
||||
$output = '';
|
||||
|
||||
$categories = array();
|
||||
ctools_include('cleanstring');
|
||||
$default_category = '';
|
||||
foreach ($layouts as $id => $layout) {
|
||||
$category = ctools_cleanstring($layout['category']);
|
||||
|
||||
$categories[$category] = $layout['category'];
|
||||
if ($id == $current_layout) {
|
||||
$default_category = $category;
|
||||
}
|
||||
|
||||
$options[$category][$id] = panels_print_layout_link($id, $layout, $base_path . '/' . $id, $link_options, $current_layout);
|
||||
}
|
||||
|
||||
$form = array();
|
||||
$form['categories'] = array(
|
||||
'#title' => t('Category'),
|
||||
'#type' => 'select',
|
||||
'#options' => $categories,
|
||||
'#name' => 'categories',
|
||||
'#id' => 'edit-categories',
|
||||
'#value' => $default_category,
|
||||
'#parents' => array('categories'),
|
||||
'#access' => (count($categories) > 1) ? TRUE : FALSE,
|
||||
);
|
||||
|
||||
$output .= drupal_render($form);
|
||||
|
||||
$output .= '<div class="panels-choose-layout panels-layouts-checkboxes clearfix">';
|
||||
|
||||
// We're doing these dependencies completely manualy, which is unusual, but
|
||||
// the process code only supports doing them in a form.
|
||||
// @todo modify dependent.inc to make this easier.
|
||||
|
||||
$dependencies = array();
|
||||
foreach ($options as $category => $links) {
|
||||
$dependencies['panels-layout-category-' . $category] = array(
|
||||
'values' => array('edit-categories' => array($category)),
|
||||
'num' => 1,
|
||||
'type' => 'hide',
|
||||
);
|
||||
|
||||
$output .= '<div id="panels-layout-category-' . $category . '-wrapper">';
|
||||
$output .= '<div id="panels-layout-category-' . $category . '" class="form-checkboxes clearfix">';
|
||||
$output .= (count($categories) > 1) ? '<div class="panels-layouts-category">' . $categories[$category] . '</div>' : '';
|
||||
|
||||
foreach ($links as $key => $link) {
|
||||
$output .= $link;
|
||||
}
|
||||
$output .= '</div></div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
ctools_add_js('dependent');
|
||||
$js['CTools']['dependent'] = $dependencies;
|
||||
drupal_add_js($js, 'setting');
|
||||
|
||||
return $output;
|
||||
}
|
328
sites/all/modules/panels/includes/display-edit.inc
Normal file
328
sites/all/modules/panels/includes/display-edit.inc
Normal file
@@ -0,0 +1,328 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @file
|
||||
* Core Panels API include file containing various display-editing functions.
|
||||
* This includes all the basic editing forms (content, layout, layout settings)
|
||||
* as well as the ajax modal forms associated with them.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling and processing of the form for editing display content.
|
||||
*
|
||||
* Helper function for panels_edit().
|
||||
*
|
||||
* @see panels_edit() for details on the various behaviors of this function.
|
||||
*/
|
||||
function _panels_edit($display, $destination, $content_types, $title = FALSE) {
|
||||
$did = $display->did;
|
||||
if (!$did) {
|
||||
$display->did = $did = 'new';
|
||||
}
|
||||
|
||||
// Load the display being edited from cache, if possible.
|
||||
if (!empty($_POST) && is_object($cache = panels_edit_cache_get($did))) {
|
||||
$display = $cache->display;
|
||||
}
|
||||
else {
|
||||
$cache = panels_edit_cache_get_default($display, $content_types, $title);
|
||||
}
|
||||
|
||||
// Get a renderer.
|
||||
$renderer = panels_get_renderer_handler('editor', $display);
|
||||
$renderer->cache = $cache;
|
||||
|
||||
$output = $renderer->edit();
|
||||
if (is_object($output) && $destination) {
|
||||
return panels_goto($destination);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form definition for the panels display editor
|
||||
*
|
||||
* No validation function is necessary, as all 'validation' is handled
|
||||
* either in the lead-up to form rendering (through the selection of
|
||||
* specified content types) or by the validation functions specific to
|
||||
* the ajax modals & content types.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see panels_edit_display_submit()
|
||||
*/
|
||||
function panels_edit_display_form($form, &$form_state) {
|
||||
$display = &$form_state['display'];
|
||||
$renderer = &$form_state['renderer'];
|
||||
|
||||
// Make sure there is a valid cache key.
|
||||
$cache_key = isset($display->cache_key) ? $display->cache_key : $display->did;
|
||||
$display->cache_key = $cache_key;
|
||||
|
||||
// Annoyingly, theme doesn't have access to form_state so we have to do this.
|
||||
$form['#display'] = $display;
|
||||
|
||||
// The flexible layout maker wants to be able to edit a display without
|
||||
// actually editing a display, so we provide this 'setting' to allow
|
||||
// that to go away.
|
||||
if (empty($form_state['no display settings'])) {
|
||||
$links = $renderer->get_display_links();
|
||||
}
|
||||
else {
|
||||
$renderer->no_edit_links = TRUE;
|
||||
$links = '';
|
||||
}
|
||||
$form['hide']['display-settings'] = array(
|
||||
'#markup' => $links,
|
||||
);
|
||||
|
||||
$form += panels_edit_display_settings_form($form, $form_state);
|
||||
|
||||
$form['panel'] = array('#tree' => TRUE);
|
||||
$form['panel']['pane'] = array('#tree' => TRUE);
|
||||
|
||||
$form['display'] = array(
|
||||
'#markup' => $renderer->render(),
|
||||
);
|
||||
|
||||
foreach ($renderer->plugins['layout']['regions'] as $region_id => $title) {
|
||||
// Make sure we at least have an empty array for all possible locations.
|
||||
if (!isset($display->panels[$region_id])) {
|
||||
$display->panels[$region_id] = array();
|
||||
}
|
||||
|
||||
$form['panel']['pane'][$region_id] = array(
|
||||
// Use 'hidden' instead of 'value' so the js can access it.
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => implode(',', (array) $display->panels[$region_id]),
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($form_state['no buttons'])) {
|
||||
$form['buttons']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
'#id' => 'panels-dnd-save',
|
||||
'#submit' => array('panels_edit_display_form_submit'),
|
||||
'#save-display' => TRUE,
|
||||
);
|
||||
$form['buttons']['cancel'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Cancel'),
|
||||
);
|
||||
}
|
||||
|
||||
// Build up the preview portion of the form, if necessary.
|
||||
if (empty($form_state['no preview'])) {
|
||||
$form['preview'] = array(
|
||||
'#tree' => TRUE,
|
||||
'#prefix' => '<h2>' . t('Live preview') . '</h2>' . '<div id="panels-live-preview">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
ctools_context_replace_form($form['preview'], $display->context);
|
||||
$form['preview']['button'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Preview'),
|
||||
'#attributes' => array('class' => array('use-ajax-submit')),
|
||||
'#id' => 'panels-live-preview-button',
|
||||
'#submit' => array('panels_edit_display_form_submit', 'panels_edit_display_form_preview'),
|
||||
);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle form validation of the display content editor.
|
||||
*/
|
||||
function panels_edit_display_form_validate($form, &$form_state) {
|
||||
panels_edit_display_settings_form_validate($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle form submission of the display content editor.
|
||||
*
|
||||
* This reads the location of the various panes from the form, which will
|
||||
* have been modified from the ajax, rearranges them and then saves
|
||||
* the display.
|
||||
*/
|
||||
function panels_edit_display_form_submit($form, &$form_state) {
|
||||
$display = &$form_state['display'];
|
||||
|
||||
$old_content = $display->content;
|
||||
$display->content = array();
|
||||
|
||||
if (!empty($form_state['values']['panel']['pane'])) {
|
||||
foreach ($form_state['values']['panel']['pane'] as $region_id => $panes) {
|
||||
$display->panels[$region_id] = array();
|
||||
if ($panes) {
|
||||
$pids = explode(',', $panes);
|
||||
// need to filter the array, b/c passing it in a hidden field can generate trash
|
||||
foreach (array_filter($pids) as $pid) {
|
||||
if ($old_content[$pid]) {
|
||||
$display->panels[$region_id][] = $pid;
|
||||
$old_content[$pid]->panel = $region_id;
|
||||
$display->content[$pid] = $old_content[$pid];
|
||||
|
||||
// If the panel has region locking, make sure that the region
|
||||
// the panel is in is applicable. This can happen if the panel
|
||||
// was moved and then the lock changed and the server didn't
|
||||
// know.
|
||||
if (!empty($old_content[$pid]->locks) && $old_content[$pid]->locks['type'] == 'regions') {
|
||||
$old_content[$pid]->locks['regions'][$region_id] = $region_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
panels_edit_display_settings_form_submit($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submission of the preview button. Render the preview and put it into
|
||||
* the preview widget area.
|
||||
*/
|
||||
function panels_edit_display_form_preview(&$form, &$form_state) {
|
||||
$display = &$form_state['display'];
|
||||
ctools_include('ajax');
|
||||
|
||||
$display->context = ctools_context_replace_placeholders($display->context, $form_state['values']['preview']);
|
||||
$display->skip_cache = TRUE;
|
||||
$output = panels_render_display($display);
|
||||
|
||||
// Add any extra CSS that some layouts may have added specifically for this.
|
||||
if (!empty($display->add_css)) {
|
||||
$output = "<style type=\"text/css\">\n$display->add_css</style>\n" . $output;
|
||||
}
|
||||
|
||||
$commands = array();
|
||||
$commands[] = array(
|
||||
'command' => 'panel_preview',
|
||||
'output' => $output,
|
||||
);
|
||||
|
||||
print ajax_render($commands);
|
||||
ajax_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Form for display settings.
|
||||
*/
|
||||
function panels_edit_display_settings_form($form, &$form_state) {
|
||||
$display = &$form_state['display'];
|
||||
|
||||
$layout = panels_get_layout($display->layout);
|
||||
$form_state['layout'] = $layout;
|
||||
|
||||
ctools_include('dependent');
|
||||
|
||||
if ($form_state['display_title']) {
|
||||
$form['display_title'] = array (
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
$form['display_title']['hide_title'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Title type'),
|
||||
'#default_value' => (int) $display->hide_title,
|
||||
'#options' => array(
|
||||
PANELS_TITLE_NONE => t('No title'),
|
||||
PANELS_TITLE_FIXED => t('Manually set'),
|
||||
PANELS_TITLE_PANE => t('From pane'),
|
||||
),
|
||||
);
|
||||
|
||||
$form['display_title']['title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $display->title,
|
||||
'#title' => t('Title'),
|
||||
'#description' => t('The title of this panel. If left blank, a default title may be used. Set to No Title if you want the title to actually be blank.'),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-display-title-hide-title' => array(PANELS_TITLE_FIXED)),
|
||||
'#maxlength' => 255,
|
||||
);
|
||||
|
||||
if (!empty($display->context)) {
|
||||
$form['display_title']['title']['#description'] .= ' ' . t('You may use substitutions in this title.');
|
||||
|
||||
// We have to create a manual fieldset because fieldsets do not support IDs.
|
||||
// Use 'hidden' instead of 'markup' so that the process will run.
|
||||
// Add js for collapsible fieldsets manually
|
||||
// drupal_add_js('misc/form.js');
|
||||
// drupal_add_js('misc/collapse.js');
|
||||
// $form['display_title']['contexts_prefix'] = array(
|
||||
// '#type' => 'hidden',
|
||||
// '#id' => 'edit-display-substitutions',
|
||||
// '#prefix' => '<div><fieldset id="edit-display-substitutions" class="collapsed collapsible"><legend>' . t('Substitutions') . '</legend><div class="fieldset-wrapper">',
|
||||
// '#process' => array('ctools_dependent_process'),
|
||||
// '#dependency' => array('edit-display-title-hide-title' => array(PANELS_TITLE_FIXED)),
|
||||
// );
|
||||
|
||||
$rows = array();
|
||||
foreach ($display->context as $context) {
|
||||
foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
|
||||
$rows[] = array(
|
||||
check_plain($keyword),
|
||||
t('@identifier: @title', array('@title' => $title, '@identifier' => $context->identifier)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$header = array(t('Keyword'), t('Value'));
|
||||
$form['display_title']['contexts'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Substitutions'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#value' => theme('table', array('header' => $header, 'rows' => $rows)),
|
||||
// '#process' => array('form_process_fieldset', 'ctools_dependent_process'),
|
||||
// '#id' => 'edit-display-title-context',
|
||||
// '#dependency' => array('edit-display-title-hide-title' => array(PANELS_TITLE_FIXED)),
|
||||
);
|
||||
// $form['display_title']['contexts_suffix'] = array(
|
||||
// '#value' => '</div></fieldset></div>',
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
// TODO doc the ability to do this as part of the API
|
||||
if (!empty($layout['settings form']) && function_exists($layout['settings form'])) {
|
||||
$form['layout_settings'] = $layout['settings form']($display, $layout, $display->layout_settings);
|
||||
}
|
||||
$form['layout_settings']['#tree'] = TRUE;
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the layout settings form.
|
||||
*/
|
||||
function panels_edit_display_settings_form_validate($form, &$form_state) {
|
||||
if ($function = panels_plugin_get_function('layout', $form_state['layout'], 'settings validate')) {
|
||||
$function($form_state['values']['layout_settings'], $form['layout_settings'], $form_state['display'], $form_state['layout'], $form_state['display']->layout_settings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store changes from the layout settings form.
|
||||
*/
|
||||
function panels_edit_display_settings_form_submit($form, &$form_state) {
|
||||
$display = &$form_state['display'];
|
||||
if ($function = panels_plugin_get_function('layout', $form_state['layout'], 'settings submit')) {
|
||||
$function($form_state['values']['layout_settings'], $display, $form_state['layout'], $display->layout_settings);
|
||||
}
|
||||
|
||||
// Since not all layouts have layout settings, check here in case of notices.
|
||||
if (isset($form_state['values']['layout_settings'])) {
|
||||
$display->layout_settings = $form_state['values']['layout_settings'];
|
||||
}
|
||||
|
||||
if (isset($form_state['values']['display_title']['title'])) {
|
||||
$display->title = $form_state['values']['display_title']['title'];
|
||||
$display->hide_title = $form_state['values']['display_title']['hide_title'];
|
||||
}
|
||||
}
|
333
sites/all/modules/panels/includes/display-layout.inc
Normal file
333
sites/all/modules/panels/includes/display-layout.inc
Normal file
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Handle the forms for changing a display's layout.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle calling and processing of the form for editing display layouts.
|
||||
*
|
||||
* Helper function for panels_edit_layout().
|
||||
*
|
||||
* @see panels_edit_layout() for details on the various behaviors of this function.
|
||||
*/
|
||||
function _panels_edit_layout($display, $finish, $destination, $allowed_layouts) {
|
||||
ctools_include('common', 'panels');
|
||||
|
||||
$form_state = array(
|
||||
'display' => &$display,
|
||||
'finish' => $finish,
|
||||
'destination' => $destination,
|
||||
'allowed_layouts' => $allowed_layouts,
|
||||
're_render' => FALSE,
|
||||
'no_redirect' => TRUE,
|
||||
);
|
||||
|
||||
$change_form_state = $form_state;
|
||||
|
||||
$change_form = FALSE;
|
||||
|
||||
// Examine $_POST to see which form they're currently using.
|
||||
if (empty($_POST) || empty($_POST['form_id']) || $_POST['form_id'] != 'panels_change_layout') {
|
||||
$output = drupal_build_form('panels_choose_layout', $form_state);
|
||||
if (!empty($form_state['executed'])) {
|
||||
// upon submission go to next form.
|
||||
$change_form_state['layout'] = $_SESSION['layout'][$display->did] = $form_state['layout'];
|
||||
$change_form = TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$change_form_state['layout'] = $_SESSION['layout'][$display->did];
|
||||
$change_form = TRUE;
|
||||
}
|
||||
|
||||
if ($change_form) {
|
||||
$output = drupal_build_form('panels_change_layout', $change_form_state);
|
||||
if (!empty($change_form_state['executed'])) {
|
||||
if (isset($change_form_state['back'])) {
|
||||
unset($_POST);
|
||||
return _panels_edit_layout($display, $finish, $destination, $allowed_layouts);
|
||||
}
|
||||
|
||||
if (!empty($change_form_state['clicked_button']['#save-display'])) {
|
||||
drupal_set_message(t('Panel layout has been updated.'));
|
||||
panels_save_display($display);
|
||||
}
|
||||
|
||||
if ($destination) {
|
||||
return panels_goto($destination);
|
||||
}
|
||||
return $change_form_state['display'];
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form definition for the display layout editor.
|
||||
*
|
||||
* @ingroup forms
|
||||
*/
|
||||
function panels_choose_layout($form, &$form_state) {
|
||||
$display = &$form_state['display'];
|
||||
ctools_include('common', 'panels');
|
||||
ctools_include('cleanstring');
|
||||
|
||||
$layouts = panels_common_get_allowed_layouts($form_state['allowed_layouts']);
|
||||
$categories = array();
|
||||
$current = '';
|
||||
foreach ($layouts as $id => $layout) {
|
||||
$category = ctools_cleanstring($layout['category']);
|
||||
// Default category to first in case layout doesn't exist or there isn't one.
|
||||
if (empty($current)) {
|
||||
$current = $category;
|
||||
}
|
||||
|
||||
$categories[$category] = $layout['category'];
|
||||
$options[$category][$id] = panels_print_layout_icon($id, $layout, check_plain($layout['title']));
|
||||
|
||||
// Set current category to what is chosen.
|
||||
if ($id == $display->layout) {
|
||||
$current = $category;
|
||||
}
|
||||
}
|
||||
|
||||
ctools_add_js('layout', 'panels');
|
||||
|
||||
$form['categories'] = array(
|
||||
'#title' => t('Category'),
|
||||
'#type' => 'select',
|
||||
'#options' => $categories,
|
||||
'#default_value' => $current,
|
||||
);
|
||||
|
||||
$form['layout'] = array(
|
||||
'#prefix' => '<div class="panels-choose-layout panels-layouts-checkboxes clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
// We set up the dependencies manually because these aren't really form
|
||||
// items. It's possible there's a simpler way to do this, but I could not
|
||||
// think of one at the time.
|
||||
$dependencies = array();
|
||||
foreach ($options as $category => $radios) {
|
||||
$dependencies['panels-layout-category-' . $category] = array(
|
||||
'values' => array('edit-categories' => array($category)),
|
||||
'num' => 1,
|
||||
'type' => 'hide',
|
||||
);
|
||||
|
||||
$form['layout'][$category] = array(
|
||||
'#prefix' => '<div id="panels-layout-category-' . $category . '-wrapper"><div id="panels-layout-category-' . $category . '" class="form-checkboxes clearfix"><div class="panels-layouts-category">' . $categories[$category] . '</div>',
|
||||
'#suffix' => '</div></div>',
|
||||
);
|
||||
|
||||
foreach ($radios as $key => $choice) {
|
||||
// Set the first available layout as default value.
|
||||
if (empty($display->layout)) {
|
||||
$display->layout = $key;
|
||||
}
|
||||
// Generate the parents as the autogenerator does, so we will have a
|
||||
// unique id for each radio button.
|
||||
$form['layout'][$category][$key] = array(
|
||||
'#type' => 'radio',
|
||||
'#title' => $choice,
|
||||
'#parents' => array('layout'),
|
||||
'#id' => drupal_clean_css_identifier('edit-layout-' . $key),
|
||||
'#return_value' => check_plain($key),
|
||||
'#default_value' => in_array($display->layout, array_keys($layouts)) ? $display->layout : NULL,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ctools_add_js('dependent');
|
||||
$js['CTools']['dependent'] = $dependencies;
|
||||
drupal_add_js($js, 'setting');
|
||||
|
||||
|
||||
if (empty($form_state['no buttons'])) {
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Next'),
|
||||
);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle form submission of the display layout editor.
|
||||
*/
|
||||
function panels_choose_layout_submit($form, &$form_state) {
|
||||
$form_state['layout'] = $form_state['values']['layout'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Form definition for the display layout converter.
|
||||
*
|
||||
* This form is only triggered if the user attempts to change the layout
|
||||
* for a display that has already had content assigned to it. It allows
|
||||
* the user to select where the panes located in to-be-deleted panels should
|
||||
* be relocated to.
|
||||
*
|
||||
* @ingroup forms
|
||||
*
|
||||
* @param array $form
|
||||
* A structured FAPI $form array.
|
||||
* @param &$form_state
|
||||
* The Drupal $form_state
|
||||
*/
|
||||
function panels_change_layout($form, &$form_state) {
|
||||
// Provide a temporary display and renderer.
|
||||
$form_state['layout_display'] = $display = panels_new_display();
|
||||
if (isset($form_state['cache_key'])) {
|
||||
$display->cache_key = $form_state['cache_key'];
|
||||
}
|
||||
|
||||
$new_layout = panels_get_layout($form_state['layout']);
|
||||
$new_layout_regions = panels_get_regions($new_layout, $display);
|
||||
|
||||
$old_layout = panels_get_layout($form_state['display']->layout);
|
||||
$old_layout_regions = panels_get_regions($old_layout, $form_state['display']);
|
||||
|
||||
$display->layout = $form_state['layout'];
|
||||
$renderer = panels_get_renderer_handler('editor', $display);
|
||||
|
||||
$renderer->meta_location = 'inline';
|
||||
|
||||
ctools_add_css('panels_admin', 'panels');
|
||||
ctools_add_css('panels_dnd', 'panels');
|
||||
ctools_add_css('dropdown');
|
||||
|
||||
// For every region that had content in the old layout, create a custom pane
|
||||
// in the new layout that represents that region.
|
||||
$keys = array_keys($new_layout_regions);
|
||||
$default_region = reset($keys);
|
||||
foreach ($old_layout_regions as $region_id => $region_name) {
|
||||
if (!empty($form_state['display']->panels[$region_id])) {
|
||||
$pane = panels_new_pane('custom', 'custom', TRUE);
|
||||
$pane->pid = $region_id;
|
||||
$pane->configuration['title'] = t('Panes');
|
||||
$pane->configuration['admin_title'] = $region_name;
|
||||
// Get a list of pane titles used.
|
||||
$titles = array();
|
||||
foreach ($form_state['display']->panels[$region_id] as $pid) {
|
||||
$content_type = ctools_get_content_type($form_state['display']->content[$pid]->type);
|
||||
$titles[$pid] = ctools_content_admin_title($content_type, $form_state['display']->content[$pid]->subtype, $form_state['display']->content[$pid]->configuration, $form_state['display']->context);
|
||||
}
|
||||
$pane->configuration['body'] = '<ul><li>' . implode('</li><li>', $titles) . '</li></ul>';
|
||||
|
||||
// If the region id matches, make it the same; otherwise, put it
|
||||
// in the default region.
|
||||
$pane->panel = empty($new_layout_regions[$region_id]) ? $default_region : $region_id;
|
||||
|
||||
// Add the pane to the approprate spots.
|
||||
$display->content[$pane->pid] = $pane;
|
||||
$display->panels[$pane->panel][] = $pane->pid;
|
||||
}
|
||||
}
|
||||
|
||||
$form['container'] = array(
|
||||
'#prefix' => '<div class="change-layout-display clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$form['container']['old_layout'] = array(
|
||||
'#markup' => panels_print_layout_icon($form_state['display']->layout, $old_layout, check_plain($old_layout['title'])),
|
||||
);
|
||||
|
||||
$form['container']['right_arrow'] = array(
|
||||
'#markup' => theme('image', array('path' => drupal_get_path('module', 'panels') . '/images/go-right.png')),
|
||||
);
|
||||
$form['container']['new_layout'] = array(
|
||||
'#markup' => panels_print_layout_icon($form_state['layout'], $new_layout, check_plain($new_layout['title'])),
|
||||
);
|
||||
|
||||
$edit_form_state = array(
|
||||
'display' => $display,
|
||||
'renderer' => $renderer,
|
||||
'no buttons' => TRUE,
|
||||
'no preview' => TRUE,
|
||||
'no display settings' => TRUE,
|
||||
'display_title' => '',
|
||||
);
|
||||
|
||||
ctools_include('display-edit', 'panels');
|
||||
$form = panels_edit_display_form($form, $edit_form_state);
|
||||
|
||||
if (empty($form_state['no buttons'])) {
|
||||
$form['back'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Back'),
|
||||
'#submit' => array('panels_choose_layout_back'),
|
||||
);
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => $form_state['finish'],
|
||||
'#submit' => array('panels_change_layout_submit'),
|
||||
'#save-display' => TRUE,
|
||||
);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle submission of the change layout form.
|
||||
*
|
||||
* This submit handler will move panes around and save the display.
|
||||
*/
|
||||
function panels_change_layout_submit($form, &$form_state) {
|
||||
$display = $form_state['display'];
|
||||
$layout_display = $form_state['layout_display'];
|
||||
|
||||
$switch = array();
|
||||
|
||||
// Calculate the pids submitted by the display and make a list of
|
||||
// translation to the regions. Remember the 'pid' of the pane
|
||||
// is the region id in the old layout.
|
||||
if (!empty($form_state['values']['panel']['pane'])) {
|
||||
foreach ($form_state['values']['panel']['pane'] as $region_id => $panes) {
|
||||
if ($panes) {
|
||||
$pids = explode(',', $panes);
|
||||
// need to filter the array, b/c passing it in a hidden field can generate trash
|
||||
foreach (array_filter($pids) as $pid) {
|
||||
$switch[$pid] = $region_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$content = array();
|
||||
foreach ($switch as $region_id => $new_region_id) {
|
||||
if (isset($display->panels[$region_id])) {
|
||||
if (!isset($content[$new_region_id])) {
|
||||
$content[$new_region_id] = array();
|
||||
}
|
||||
$content[$new_region_id] = array_merge($content[$new_region_id], $display->panels[$region_id]);
|
||||
}
|
||||
}
|
||||
|
||||
// Go through each pane and make sure its region id is correct.
|
||||
foreach ($content as $region_id => $region) {
|
||||
foreach ($region as $pid) {
|
||||
$display->content[$pid]->panel = $region_id;
|
||||
}
|
||||
}
|
||||
|
||||
$display->panels = $content;
|
||||
|
||||
$display->layout = $form_state['layout'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle submission of the change layout form.
|
||||
*
|
||||
* This submit handler sets a flag on the form state, which is then used
|
||||
* by the calling wrapper to restart the process.
|
||||
*/
|
||||
function panels_choose_layout_back($form, &$form_state) {
|
||||
$form_state['back'] = TRUE;
|
||||
}
|
41
sites/all/modules/panels/includes/legacy.inc
Normal file
41
sites/all/modules/panels/includes/legacy.inc
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Legacy state manager for Panels.
|
||||
*
|
||||
* Checks all possible ways (using discovery of patterned method names) in which
|
||||
* Panels may need to operate in legacy mode,
|
||||
* sets variables as appropriate, and returns an informational
|
||||
*
|
||||
*/
|
||||
class PanelsLegacyState {
|
||||
var $legacy = NULL;
|
||||
|
||||
function t() {
|
||||
$func = get_t();
|
||||
$args = func_get_args();
|
||||
return call_user_func_array($func, $args);
|
||||
}
|
||||
|
||||
function getStatus() {
|
||||
if (!isset($this->legacy)) {
|
||||
$this->determineStatus();
|
||||
}
|
||||
return $this->legacy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all compatibility checks.
|
||||
*/
|
||||
function determineStatus() {
|
||||
$this->legacy = array();
|
||||
foreach(get_class_methods($this) as $method) {
|
||||
if (strtolower(substr($method, 0, 5)) == 'check') {
|
||||
$this->legacy[$method] = $this->$method();
|
||||
}
|
||||
}
|
||||
$this->legacy = array_filter($this->legacy);
|
||||
}
|
||||
|
||||
// At this time there are no legacy checks.
|
||||
}
|
86
sites/all/modules/panels/includes/page-wizard.inc
Normal file
86
sites/all/modules/panels/includes/page-wizard.inc
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains helper functions for the Panels page wizards.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add layout form helper for panels page wizards.
|
||||
*
|
||||
* This is not a proper form, it is meant to be called by a form to add
|
||||
* elements to it.
|
||||
*/
|
||||
function panels_page_wizard_add_layout(&$form, &$form_state) {
|
||||
$form_state['allowed_layouts'] = 'panels_page';
|
||||
$form_state['display'] = $form_state['wizard cache']->display;
|
||||
|
||||
// Tell the Panels form not to display buttons.
|
||||
$form_state['no buttons'] = TRUE;
|
||||
|
||||
// Change the #id of the form so the CSS applies properly.
|
||||
$form['#id'] = 'panels-choose-layout';
|
||||
|
||||
$form['layout_prefix'] = array(
|
||||
'#value' => '<fieldset><legend>' . t('Layout') . '</legend>',
|
||||
);
|
||||
|
||||
ctools_include('common', 'panels');
|
||||
ctools_include('display-layout', 'panels');
|
||||
ctools_include('plugins', 'panels');
|
||||
|
||||
$form = panels_choose_layout($form, $form_state);
|
||||
|
||||
$form['layout_suffix'] = array(
|
||||
'#value' => '</fieldset>',
|
||||
);
|
||||
|
||||
// $form_state['cache'] = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add content editor form helper for panels page wizards.
|
||||
*
|
||||
* This is not a proper form, it is meant to be called by a form to add
|
||||
* elements to it.
|
||||
*/
|
||||
function panels_page_wizard_add_content(&$form, &$form_state) {
|
||||
ctools_include('ajax');
|
||||
ctools_include('plugins', 'panels');
|
||||
ctools_include('common', 'panels');
|
||||
ctools_include('display-edit', 'panels');
|
||||
|
||||
// Panels provides this caching mechanism to make it easy to use the
|
||||
// wizard to cache the display.
|
||||
|
||||
$cache = panels_edit_cache_get('panels_page_wizard:' . $form_state['plugin']['name']);
|
||||
|
||||
$form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
|
||||
$form_state['renderer']->cache = &$cache;
|
||||
|
||||
$form_state['display'] = &$cache->display;
|
||||
$form_state['content_types'] = $cache->content_types;
|
||||
// Tell the Panels form not to display buttons.
|
||||
$form_state['no buttons'] = TRUE;
|
||||
$form_state['display_title'] = !empty($cache->display_title);
|
||||
|
||||
$form = panels_edit_display_form($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add content form submit handler
|
||||
*
|
||||
* This is not a proper submit handler, it is meant to be called by a form's
|
||||
* submit handler to handle submission.
|
||||
*/
|
||||
function panels_page_wizard_add_content_submit(&$form, &$form_state) {
|
||||
// Call the normal panels edit form submit to make sure values are stored
|
||||
// on the display
|
||||
panels_edit_display_form_submit($form, $form_state);
|
||||
$cache = &$form_state['wizard cache'];
|
||||
|
||||
// Copy the "being edited" cached display to the "actual" cached display.
|
||||
$cache->display = &$form_state['display'];
|
||||
unset($cache->display_cache);
|
||||
}
|
||||
|
33
sites/all/modules/panels/includes/panels.pipelines.inc
Normal file
33
sites/all/modules/panels/includes/panels.pipelines.inc
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Bulk export of panels_layouts objects generated by Bulk export module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_default_panels_renderer_pipeline().
|
||||
*/
|
||||
function panels_default_panels_renderer_pipeline() {
|
||||
$pipelines = array();
|
||||
|
||||
$pipeline = new stdClass;
|
||||
$pipeline->disabled = FALSE; /* Edit this to true to make a default pipeline disabled initially */
|
||||
$pipeline->api_version = 1;
|
||||
$pipeline->name = 'standard';
|
||||
$pipeline->admin_title = t('Standard');
|
||||
$pipeline->admin_description = t('Renders a panel normally. This is the most common option.');
|
||||
$pipeline->weight = -100;
|
||||
$pipeline->settings = array(
|
||||
'renderers' => array(
|
||||
0 => array(
|
||||
'access' => array(),
|
||||
'renderer' => 'standard',
|
||||
'options' => array(),
|
||||
),
|
||||
),
|
||||
);
|
||||
$pipelines[$pipeline->name] = $pipeline;
|
||||
|
||||
return $pipelines;
|
||||
}
|
485
sites/all/modules/panels/includes/plugins.inc
Normal file
485
sites/all/modules/panels/includes/plugins.inc
Normal file
@@ -0,0 +1,485 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Contains helper code for plugins and contexts.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Determine if a pane is visible.
|
||||
*
|
||||
* @param $pane
|
||||
* The pane object to test for access.
|
||||
* @param $display
|
||||
* The display object containing the pane object to be tested.
|
||||
*/
|
||||
function panels_pane_access($pane, $display) {
|
||||
ctools_include('context');
|
||||
return ctools_access($pane->access, $display->context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of panels available in the layout.
|
||||
*/
|
||||
function panels_get_regions($layout, $display) {
|
||||
if ($function = ctools_plugin_get_function($layout, 'regions function')) {
|
||||
return $function($display, $display->layout_settings, $layout);
|
||||
}
|
||||
|
||||
if (!empty($layout['regions'])) {
|
||||
return $layout['regions'];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cached content for a given display and possibly pane.
|
||||
*
|
||||
* @return
|
||||
* The cached content, or FALSE to indicate no cached content exists.
|
||||
*/
|
||||
function panels_get_cached_content($display, $args, $context, $pane = NULL) {
|
||||
// Never use cache on a POST
|
||||
if (!empty($_POST)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$method = $pane ? $pane->cache['method'] : $display->cache['method'];
|
||||
$function = panels_plugin_get_function('cache', $method, 'cache get');
|
||||
|
||||
if (!$function) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$conf = $pane ? $pane->cache['settings'] : $display->cache['settings'];
|
||||
$cache = $function($conf, $display, $args, $context, $pane);
|
||||
if (empty($cache)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// restore it.
|
||||
$cache->restore();
|
||||
return $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store cached content for a given display and possibly pane.
|
||||
*/
|
||||
function panels_set_cached_content($cache, $display, $args, $context, $pane = NULL) {
|
||||
// Never use cache on a POST
|
||||
if (!empty($_POST)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$method = $pane ? $pane->cache['method'] : $display->cache['method'];
|
||||
$function = panels_plugin_get_function('cache', $method, 'cache set');
|
||||
|
||||
if (!$function) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$conf = $pane ? $pane->cache['settings'] : $display->cache['settings'];
|
||||
|
||||
// snapshot it.
|
||||
$cache->cache();
|
||||
return $function($conf, $cache, $display, $args, $context, $pane);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all cached content for a display.
|
||||
*/
|
||||
function panels_clear_cached_content($display) {
|
||||
// Figure out every method we might be using to cache content in this display:
|
||||
$methods = array();
|
||||
if (!empty($display->cache['method'])) {
|
||||
$methods[$display->cache['method']] = TRUE;
|
||||
}
|
||||
|
||||
foreach ($display->content as $pane) {
|
||||
if (!empty($pane->cache['method'])) {
|
||||
$methods[$pane->cache['method']] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array_keys($methods) as $method) {
|
||||
$function = panels_plugin_get_function('cache', $method, 'cache clear');
|
||||
if ($function) {
|
||||
$function($display);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An object to hold caching information while it is happening.
|
||||
*/
|
||||
class panels_cache_object {
|
||||
var $content = '';
|
||||
var $head = NULL;
|
||||
var $css = NULL;
|
||||
var $js = NULL;
|
||||
var $tokens = NULL;
|
||||
var $ready = FALSE;
|
||||
|
||||
/**
|
||||
* When constructed, take a snapshot of our existing out of band data.
|
||||
*/
|
||||
function panels_cache_object() {
|
||||
$this->head = drupal_add_html_head();
|
||||
$this->css = drupal_add_css();
|
||||
$this->tokens = ctools_set_page_token();
|
||||
$this->js = drupal_add_js();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add content to the cache. This assumes a pure stream;
|
||||
* use set_content() if it's something else.
|
||||
*/
|
||||
function add_content($content) {
|
||||
$this->content .= $content;
|
||||
}
|
||||
|
||||
function set_content($content) {
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object for storing. This overwrites.
|
||||
*/
|
||||
function cache() {
|
||||
if ($this->ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->ready = TRUE;
|
||||
|
||||
// Simple replacement for head
|
||||
$this->head = str_replace($this->head, '', drupal_add_html_head());
|
||||
|
||||
// Slightly less simple for CSS:
|
||||
$css = drupal_add_css();
|
||||
$start = $this->css;
|
||||
$this->css = array();
|
||||
|
||||
foreach ($css as $name => $data) {
|
||||
if (!isset($start[$name])) {
|
||||
$this->css[$name] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
$js = drupal_add_js();
|
||||
|
||||
$start = $this->js;
|
||||
$this->js = array();
|
||||
|
||||
// If there are any differences between the old and the new javascript then
|
||||
// store them to be added later.
|
||||
if ($diff = array_diff_assoc($js, $start)) {
|
||||
$this->js = $diff;
|
||||
}
|
||||
|
||||
// Special case the settings key and get the difference of the data.
|
||||
if ($settings_diff = array_diff_assoc($js['settings']['data'], $start['settings']['data'])) {
|
||||
$this->js['settings'] = $settings_diff;
|
||||
}
|
||||
|
||||
// And for tokens:
|
||||
$tokens = ctools_set_page_token();
|
||||
foreach ($this->tokens as $token => $argument) {
|
||||
if (isset($tokens[$token])) {
|
||||
unset($tokens[$token]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->tokens = $tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore out of band data saved to cache.
|
||||
*/
|
||||
function restore() {
|
||||
if (!empty($this->head)) {
|
||||
drupal_add_html_head($this->head);
|
||||
}
|
||||
if (!empty($this->css)) {
|
||||
foreach ($this->css as $args) {
|
||||
drupal_add_css($args['data'], $args);
|
||||
}
|
||||
}
|
||||
if (!empty($this->js)) {
|
||||
foreach ($this->js as $key => $args) {
|
||||
if ($key !== 'settings') {
|
||||
drupal_add_js($args['data'], $args);
|
||||
}
|
||||
else {
|
||||
foreach ($args as $setting) {
|
||||
drupal_add_js($setting, 'setting');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->tokens)) {
|
||||
foreach ($this->tokens as $token => $key) {
|
||||
list($type, $argument) = $key;
|
||||
ctools_set_page_token($token, $type, $argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of a pane.
|
||||
*
|
||||
* @deprecated @todo this function should be removed.
|
||||
*
|
||||
* @param $pane
|
||||
* The $pane object.
|
||||
*/
|
||||
function panels_get_pane_title(&$pane, $context = array(), $incoming_content = NULL) {
|
||||
ctools_include('content');
|
||||
return ctools_content_admin_title($pane->type, $pane->subtype, $pane->configuration, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch metadata on a specific layout plugin.
|
||||
*
|
||||
* @param $layout
|
||||
* Name of a panel layout. If the layout name contains a ':' this
|
||||
* indicates that we need to separate the sublayout out and
|
||||
* load it individually.
|
||||
*
|
||||
* @return
|
||||
* An array with information about the requested panel layout.
|
||||
*/
|
||||
function panels_get_layout($layout) {
|
||||
ctools_include('plugins');
|
||||
return ctools_get_plugins('panels', 'layouts', $layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch metadata for all layout plugins.
|
||||
*
|
||||
* @return
|
||||
* An array of arrays with information about all available panel layouts.
|
||||
*/
|
||||
function panels_get_layouts() {
|
||||
ctools_include('plugins');
|
||||
return ctools_get_plugins('panels', 'layouts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch metadata for all layout plugins that provide builders.
|
||||
*
|
||||
* The layout builders allow reusable layouts be stored in the database and
|
||||
* exported. Since there are different methods, we are not limiting this
|
||||
* to just one plugin.
|
||||
*
|
||||
* @return
|
||||
* An array of arrays with information about panel layouts with builders.
|
||||
*/
|
||||
function panels_get_layout_builders() {
|
||||
ctools_include('plugins');
|
||||
$plugins = ctools_get_plugins('panels', 'layouts');
|
||||
$builders = array();
|
||||
foreach ($plugins as $name => $plugin) {
|
||||
if (!empty($plugin['builder'])) {
|
||||
$builders[$name] = $plugin;
|
||||
}
|
||||
}
|
||||
|
||||
return $builders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch metadata on a specific style plugin.
|
||||
*
|
||||
* @param $style
|
||||
* Name of a panel style.
|
||||
*
|
||||
* @return
|
||||
* An array with information about the requested panel style.
|
||||
*/
|
||||
function panels_get_style($style) {
|
||||
ctools_include('plugins');
|
||||
return ctools_get_plugins('panels', 'styles', $style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch metadata for all style plugins.
|
||||
*
|
||||
* @return
|
||||
* An array of arrays with information about all available panel styles.
|
||||
*/
|
||||
function panels_get_styles() {
|
||||
ctools_include('plugins');
|
||||
return ctools_get_plugins('panels', 'styles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch metadata on a specific caching plugin.
|
||||
*
|
||||
* @param $cache
|
||||
* Name of a panel cache.
|
||||
*
|
||||
* @return
|
||||
* An array with information about the requested panel cache.
|
||||
*/
|
||||
function panels_get_cache($cache) {
|
||||
ctools_include('plugins');
|
||||
return ctools_get_plugins('panels', 'cache', $cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch metadata for all context plugins.
|
||||
*
|
||||
* @return
|
||||
* An array of arrays with information about all available panel caches.
|
||||
*/
|
||||
function panels_get_caches() {
|
||||
ctools_include('plugins');
|
||||
return ctools_get_plugins('panels', 'cache');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch metadata on a specific display renderer plugin.
|
||||
*
|
||||
* @return
|
||||
* An array of arrays with information about the requested panels display
|
||||
* renderer.
|
||||
*/
|
||||
function panels_get_display_renderer($renderer) {
|
||||
ctools_include('plugins');
|
||||
return ctools_get_plugins('panels', 'display_renderers', $renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch metadata for all display renderer plugins.
|
||||
*
|
||||
* @return
|
||||
* An array of arrays with information about all available panels display
|
||||
* renderer.
|
||||
*/
|
||||
function panels_get_display_renderers() {
|
||||
ctools_include('plugins');
|
||||
return ctools_get_plugins('panels', 'display_renderers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and initialize the class to handle rendering a display.
|
||||
*
|
||||
* @return
|
||||
* Either the instantiated renderer or FALSE if one could not be found.
|
||||
*/
|
||||
function panels_get_renderer_handler($plugin, &$display) {
|
||||
if (is_string($plugin)) {
|
||||
$plugin = panels_get_display_renderer($plugin);
|
||||
}
|
||||
|
||||
$class = ctools_plugin_get_class($plugin, 'renderer');
|
||||
if ($class) {
|
||||
$renderer = new $class();
|
||||
$renderer->init($plugin, $display);
|
||||
return $renderer;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose a renderer for a display based on a render pipeline setting.
|
||||
*/
|
||||
function panels_get_renderer($pipeline_name, &$display) {
|
||||
// Load the pipeline
|
||||
ctools_include('export');
|
||||
$pipeline = ctools_export_crud_load('panels_renderer_pipeline', $pipeline_name);
|
||||
|
||||
// If we can't, or it has no renderers, default.
|
||||
if (!$pipeline || empty($pipeline->settings['renderers'])) {
|
||||
return panels_get_renderer_handler('standard', $display);
|
||||
}
|
||||
|
||||
// Get contexts set on the pipeline:
|
||||
$contexts = array();
|
||||
if (!empty($pipeline->settings['contexts'])) {
|
||||
$contexts = ctools_context_load_contexts($pipeline->settings['context']);
|
||||
}
|
||||
|
||||
// Cycle through our renderers and see.
|
||||
foreach ($pipeline->settings['renderers'] as $candidate) {
|
||||
// See if this passes selection criteria.
|
||||
if (!ctools_access($candidate['access'], $contexts)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$renderer = panels_get_renderer_handler($candidate['renderer'], $display);
|
||||
|
||||
if (!empty($candidate['options'])) {
|
||||
$renderer->set_options($candidate['options']);
|
||||
}
|
||||
|
||||
return $renderer;
|
||||
}
|
||||
|
||||
// Fall through. If no renderer is selected, use the standard renderer
|
||||
return panels_get_renderer_handler('standard', $display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort callback for sorting renderer pipelines.
|
||||
*
|
||||
* Sort first by weight, then by title.
|
||||
*/
|
||||
function _panels_renderer_pipeline_sort($a, $b) {
|
||||
if ($a->weight == $b->weight) {
|
||||
if ($a->admin_title == $b->admin_title) {
|
||||
return 0;
|
||||
}
|
||||
return ($a->admin_title < $b->admin_title) ? -1 : 1;
|
||||
}
|
||||
return ($a->weight < $b->weight) ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of available renderer pipelines.
|
||||
*
|
||||
* This can be used to form a select or radios widget by enabling
|
||||
* sorting. Descriptions are left in.
|
||||
*/
|
||||
function panels_get_renderer_pipelines($sort = TRUE) {
|
||||
ctools_include('export');
|
||||
$pipelines = ctools_export_crud_load_all('panels_renderer_pipeline');
|
||||
if ($sort) {
|
||||
uasort($pipelines, '_panels_renderer_pipeline_sort');
|
||||
}
|
||||
|
||||
return $pipelines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a function from a plugin, if it exists.
|
||||
*
|
||||
* @param $plugin
|
||||
* The type of plugin
|
||||
* @param $which
|
||||
* Either the loaded plugin object (or the same data in array form)
|
||||
* or a string with the name of the desired the specific plugin.
|
||||
* @param $function_name
|
||||
* The identifier of the function. For example, 'settings form'.
|
||||
*
|
||||
* @return
|
||||
* The actual name of the function to call, or NULL if the function
|
||||
* does not exist.
|
||||
*
|
||||
* @deprecated All calls to this function should be removed.
|
||||
*/
|
||||
function panels_plugin_get_function($plugin, $which, $function_name) {
|
||||
ctools_include('plugins');
|
||||
if (is_object($which) || is_array($which)) {
|
||||
return ctools_plugin_get_function($which, $function_name);
|
||||
}
|
||||
else {
|
||||
return ctools_plugin_load_function('panels', $plugin, $which, $function_name);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user