Commit 5ac4f2b0 authored by Riccardo Padovani's avatar Riccardo Padovani

Updated module ctools to 7.x-1.6

parent 3e677343
......@@ -3,6 +3,9 @@ Current API Version: 2.0.8
Please note that the API version is an internal number and does not match release numbers. It is entirely possible that releases will not increase the API version number, and increasing this number too often would burden contrib module maintainers who need to keep up with API changes.
This file contains a log of changes to the API.
API Version 2.0.9
Changed import permissions to use the new 'use ctools import' permission.
API Version 2.0.8
Introduce ctools_class_add().
Introduce ctools_class_remove().
......
......@@ -3,10 +3,12 @@ description = Performs bulk exporting of data objects known about by Chaos tools
core = 7.x
dependencies[] = ctools
package = Chaos tool suite
version = CTOOLS_MODULE_VERSION
; Information added by Drupal.org packaging script on 2014-11-19
version = "7.x-1.5"
; Information added by Drupal.org packaging script on 2015-01-28
version = "7.x-1.6"
core = "7.x"
project = "ctools"
datestamp = "1416423525"
datestamp = "1422471484"
......@@ -2,13 +2,16 @@ name = Chaos tools
description = A library of helpful tools by Merlin of Chaos.
core = 7.x
package = Chaos tool suite
version = CTOOLS_MODULE_VERSION
files[] = includes/context.inc
files[] = includes/css-cache.inc
files[] = includes/math-expr.inc
files[] = includes/stylizer.inc
files[] = tests/css_cache.test
; Information added by Drupal.org packaging script on 2014-11-19
version = "7.x-1.5"
; Information added by Drupal.org packaging script on 2015-01-28
version = "7.x-1.6"
core = "7.x"
project = "ctools"
datestamp = "1416423525"
datestamp = "1422471484"
......@@ -40,7 +40,19 @@ function ctools_requirements($phase) {
* Implements hook_schema().
*/
function ctools_schema() {
return ctools_schema_2();
return ctools_schema_3();
}
/**
* Version 3 of the CTools schema.
*/
function ctools_schema_3() {
$schema = ctools_schema_2();
// update the 'obj' field to be 128 bytes long:
$schema['ctools_object_cache']['fields']['obj']['length'] = 128;
return $schema;
}
/**
......@@ -141,6 +153,21 @@ function ctools_schema_1() {
return $schema;
}
/**
* Implements hook_install().
*/
function ctools_install() {
// Activate our custom cache handler for the CSS cache.
variable_set('cache_class_cache_ctools_css', 'CToolsCssCache');
}
/**
* Implements hook_uninstall().
*/
function ctools_uninstall() {
variable_del('cache_class_cache_ctools_css');
}
/**
* Enlarge the ctools_object_cache.name column to prevent truncation and weird
* errors.
......@@ -217,3 +244,22 @@ function ctools_update_6008() {
)
);
}
/**
* Enable the custom CSS cache handler.
*/
function ctools_update_7000() {
variable_set('cache_class_cache_ctools_css', 'CToolsCssCache');
}
/**
* Increase the length of the ctools_object_cache.obj column.
*/
function ctools_update_7001() {
db_change_field('ctools_object_cache', 'obj', 'obj', array(
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'description' => 'The type of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.',
));
}
......@@ -9,7 +9,21 @@
* must be implemented in the module file.
*/
define('CTOOLS_API_VERSION', '2.0.7');
define('CTOOLS_API_VERSION', '2.0.8');
/**
* The current working ctools version.
*
* In a release, it should be 7.x-1.x, which should match what drush make will
* create. In a dev format, it should be 7.x-1.(x+1)-dev, which will allow
* modules depending on new features in ctools to depend on ctools > 7.x-1.x.
*
* To define a specific version of CTools as a dependency for another module,
* simply include a dependency line in that module's info file, e.g.:
* ; Requires CTools v7.x-1.4 or newer.
* dependencies[] = ctools (>=1.4)
*/
define('CTOOLS_MODULE_VERSION', '7.x-1.6');
/**
* Test the CTools API version.
......@@ -536,6 +550,19 @@ function ctools_menu() {
return $items;
}
/**
* Implements hook_permission().
*/
function ctools_permission() {
return array(
'use ctools import' => array(
'title' => t('Use CTools importer'),
'description' => t('The import functionality allows users to execute arbitrary PHP code, so extreme caution must be taken.'),
'restrict access' => TRUE,
),
);
}
/**
* Implementation of hook_cron. Clean up old caches.
*/
......@@ -546,19 +573,12 @@ function ctools_cron() {
}
/**
* Ensure the CTools CSS cache is flushed whenever hook_flush_caches is invoked.
* Implements hook_flush_caches().
*/
function ctools_flush_caches() {
// Do not actually flush caches if running on cron. Drupal uses this hook
// in an inconsistent fashion and it does not necessarily mean to *flush*
// caches when running from cron. Instead it's just getting a list of cache
// tables and may not do any flushing.
if (!empty($GLOBALS['locks']['cron'])) {
return;
}
ctools_include('css');
ctools_css_flush_caches();
// Only return the CSS cache bin if it has been activated, to avoid
// drupal_flush_all_caches() from trying to truncate a non-existing table.
return variable_get('cache_class_cache_ctools_css', FALSE) ? array('cache_ctools_css') : array();
}
/**
......@@ -638,7 +658,26 @@ function ctools_preprocess_node(&$vars) {
}
}
/**
* Implements hook_page_alter().
*
* Last ditch attempt to remove sidebar regions if the "no blocks"
* functionality has been activated.
*
* @see ctools_block_list_alter().
*/
function ctools_page_alter(&$page) {
$check = drupal_static('ctools_set_no_blocks', TRUE);
if (!$check) {
foreach ($page as $region_id => $region) {
// @todo -- possibly we can set configuration for this so that users can
// specify which blocks will not get rendered.
if (strpos($region_id, 'sidebar') !== FALSE) {
unset($page[$region_id]);
}
}
}
$page['#post_render'][] = 'ctools_page_token_processing';
}
......@@ -786,6 +825,15 @@ function ctools_js_load($js) {
return 0;
}
/**
* Provides the default value for %ctools_js.
*
* This allows drupal_valid_path() to work with %ctools_js.
*/
function ctools_js_to_arg($arg) {
return empty($arg) || $arg == '%' ? 'nojs' : $arg;
}
/**
* Menu _load hook.
*
......@@ -905,11 +953,25 @@ function ctools_block_list_alter(&$blocks) {
}
/**
* Implement hook_modules_enabled to clear static caches for detecting new plugins
* Implements hook_modules_enabled().
*
* Clear caches for detecting new plugins.
*/
function ctools_modules_enabled($modules) {
ctools_include('plugins');
ctools_get_plugins_reset();
cache_clear_all('ctools_plugin_files:', 'cache', TRUE);
}
/**
* Implements hook_modules_disabled().
*
* Clear caches for removing disabled plugins.
*/
function ctools_modules_disabled($modules) {
ctools_include('plugins');
ctools_get_plugins_reset();
cache_clear_all('ctools_plugin_files:', 'cache', TRUE);
}
/**
......
......@@ -2,11 +2,12 @@ name = Custom rulesets
description = Create custom, exportable, reusable access rulesets for applications like Panels.
core = 7.x
package = Chaos tool suite
version = CTOOLS_MODULE_VERSION
dependencies[] = ctools
; Information added by Drupal.org packaging script on 2014-11-19
version = "7.x-1.5"
; Information added by Drupal.org packaging script on 2015-01-28
version = "7.x-1.6"
core = "7.x"
project = "ctools"
datestamp = "1416423525"
datestamp = "1422471484"
name = Chaos Tools (CTools) AJAX Example
description = Shows how to use the power of Chaos AJAX.
package = Chaos tool suite
version = CTOOLS_MODULE_VERSION
dependencies[] = ctools
core = 7.x
; Information added by Drupal.org packaging script on 2014-11-19
version = "7.x-1.5"
; Information added by Drupal.org packaging script on 2015-01-28
version = "7.x-1.6"
core = "7.x"
project = "ctools"
datestamp = "1416423525"
datestamp = "1422471484"
......@@ -2,11 +2,12 @@ name = Custom content panes
description = Create custom, exportable, reusable content panes for applications like Panels.
core = 7.x
package = Chaos tool suite
version = CTOOLS_MODULE_VERSION
dependencies[] = ctools
; Information added by Drupal.org packaging script on 2014-11-19
version = "7.x-1.5"
; Information added by Drupal.org packaging script on 2015-01-28
version = "7.x-1.6"
core = "7.x"
project = "ctools"
datestamp = "1416423525"
datestamp = "1422471484"
name = Chaos Tools (CTools) Plugin Example
description = Shows how an external module can provide ctools plugins (for Panels, etc.).
package = Chaos tool suite
version = CTOOLS_MODULE_VERSION
dependencies[] = ctools
dependencies[] = panels
dependencies[] = page_manager
dependencies[] = advanced_help
core = 7.x
; Information added by Drupal.org packaging script on 2014-11-19
version = "7.x-1.5"
; Information added by Drupal.org packaging script on 2015-01-28
version = "7.x-1.6"
core = "7.x"
project = "ctools"
datestamp = "1416423525"
datestamp = "1422471484"
......@@ -244,6 +244,7 @@ function ctools_content_prepare_subtype(&$subtype, $plugin) {
* The content as rendered by the plugin. This content should be an array
* with the following possible keys:
* - title: The safe to render title of the content.
* - title_heading: The title heading.
* - content: The safe to render HTML content.
* - links: An array of links associated with the content suitable for
* theme('links').
......@@ -299,6 +300,7 @@ function ctools_content_render($type, $subtype, $conf, $keywords = array(), $arg
$keywords['%title'] = empty($content->title) ? '' : $content->title;
$content->original_title = $keywords['%title'];
$content->title = $conf['override_title_text'];
$content->title_heading = isset($conf['override_title_heading']) ? $conf['override_title_heading'] : 'h2';
}
if (!empty($content->title)) {
......@@ -504,8 +506,26 @@ function ctools_content_configure_form_defaults($form, &$form_state) {
'#size' => 35,
'#id' => 'override-title-textfield',
'#dependency' => array('override-title-checkbox' => array(1)),
'#dependency_type' => 'disable',
'#dependency_type' => 'hidden',
);
$form['override_title_heading'] = array(
'#type' => 'select',
'#default_value' => isset($conf['override_title_heading']) ? $conf['override_title_heading'] : 'h2',
'#options' => array(
'h1' => t('h1'),
'h2' => t('h2'),
'h3' => t('h3'),
'h4' => t('h4'),
'h5' => t('h5'),
'h6' => t('h6'),
'div' => t('div'),
'span' => t('span'),
),
'#id' => 'override-title-heading',
'#dependency' => array('override-title-checkbox' => array(1)),
'#dependency_type' => 'hidden',
);
$form['aligner_stop'] = array(
'#markup' => '</div>',
);
......@@ -536,6 +556,7 @@ function ctools_content_configure_form_defaults_submit(&$form, &$form_state) {
if (isset($form_state['values']['override_title'])) {
$form_state['conf']['override_title'] = $form_state['values']['override_title'];
$form_state['conf']['override_title_text'] = $form_state['values']['override_title_text'];
$form_state['conf']['override_title_heading'] = $form_state['values']['override_title_heading'];
}
}
......
......@@ -27,6 +27,9 @@ function ctools_content_autocomplete_entity($type, $string = '') {
if ($string != '') {
global $user;
$entity_info = entity_get_info($type);
if ($type == 'node') {
$entity_info['entity keys']['bundle field'] = 'type';
}
// We must query all ids, because if every one of the 10 don't have access
// the user may never be able to autocomplete a node title.
......@@ -56,6 +59,7 @@ function ctools_content_autocomplete_entity($type, $string = '') {
}
else {
$matches[$result['label'] . " [id: $entity_id]"] = '<span class="autocomplete_title">' . check_plain($result['label']) . '</span>';
$matches[$result['label'] . " [id: $entity_id]"] .= isset($result['bundle field']) ? ' <span class="autocomplete_bundle">(' . check_plain($result['bundle field']) . ')</span>' : '';
}
}
......@@ -83,6 +87,11 @@ function _ctools_buildQuery($entity_type, $entity_info, $match = NULL, $match_op
$query->fields($base_table, array($entity_info['entity keys']['label']));
}
// Add bundle field to the query, if it exists.
if (isset($entity_info['entity keys']['bundle field'])) {
$query->fields($base_table, array($entity_info['entity keys']['bundle field']));
}
// Add a generic entity access tag to the query.
$query->addTag('ctools');
......@@ -131,6 +140,7 @@ function _ctools_getReferencableEntities($entity_type, $entity_info, $match = NU
foreach ($results as $record) {
$options[$record->{$entity_info['entity keys']['id']}] = array(
'label' => isset($entity_info['entity keys']['label']) ? check_plain($record->{$entity_info['entity keys']['label']}) : $record->{$entity_info['entity keys']['id']},
'bundle field' => isset($entity_info['entity keys']['bundle field']) ? check_plain($record->{$entity_info['entity keys']['bundle field']}) : '',
);
}
}
......
......@@ -416,13 +416,14 @@ function ctools_context_ajax_item_add($mechanism = NULL, $type = NULL, $cache_ke
ctools_cache_operation($mechanism, $cache_key, 'finalize', $object);
// Very irritating way to update the form for our contexts.
$arg_form_state = array(
$arg_form_state = form_state_defaults() + array(
'values' => array(),
'programmed' => FALSE,
'process_input' => FALSE,
'complete form' => array(),
);
$rel_form_state = $arg_form_state;
$arg_form = array(
'#post' => array(),
'#programmed' => FALSE,
......@@ -469,7 +470,7 @@ function ctools_context_ajax_item_add($mechanism = NULL, $type = NULL, $cache_ke
$output = array();
if (!empty($available_relationships)) {
ctools_context_add_item_table_buttons('relationship', $mechanism, $rel_form, $available_relationships);
$rel_form = form_builder('dummy_form_id', $rel_form, $arg_form_state);
$rel_form = form_builder('dummy_form_id', $rel_form, $rel_form_state);
$output[] = ajax_command_replace('div#ctools-relationships-table div.buttons', drupal_render($rel_form));
}
......@@ -591,8 +592,16 @@ function ctools_context_ajax_item_edit($mechanism = NULL, $type = NULL, $cache_k
$output = array();
$output[] = ctools_modal_command_dismiss();
$arg_form_state = form_state_defaults() + array(
'values' => array(),
'process_input' => FALSE,
'complete form' => array(),
);
$arg_form = array(
'#post' => array(),
'#parents' => array(),
'#array_parents' => array(),
'#programmed' => FALSE,
'#tree' => FALSE,
);
......
......@@ -169,7 +169,12 @@ class ctools_context_required {
function select($contexts, $context) {
if (!is_array($contexts)) {
$contexts = array($contexts);
if (is_object($contexts) && $contexts instanceof ctools_context) {
$contexts = array($contexts->id => $contexts);
}
else {
$contexts = array($contexts);
}
}
// If we had requested a $context but that $context doesn't exist
......@@ -328,13 +333,15 @@ function _ctools_context_selector($contexts, $required, $default, $num = 0) {
$title = $num ? t('Context %count', array('%count' => $num)) : t('Context');
}
return array(
$form = array(
'#type' => 'select',
'#options' => $options,
'#title' => $title,
'#default_value' => $default,
);
}
return $form;
}
/**
......@@ -1587,7 +1594,9 @@ function ctools_access_add_restrictions($settings, $contexts) {
$required_context = isset($plugin['required context']) ? $plugin['required context'] : array();
$context = isset($test['context']) ? $test['context'] : array();
$contexts = ctools_context_select($contexts, $required_context, $context);
$function($test['settings'], $contexts);
if ($contexts !== FALSE) {
$function($test['settings'], $contexts);
}
}
}
}
<?php
/**
* @file
* Custom cache implementation for the CTools CSS cache.
*/
class CToolsCssCache implements DrupalCacheInterface {
/**
* {@inheritdoc}
*/
public function clear($cid = NULL, $wildcard = FALSE) {
// Only clear the caches if the wildcard is set, this ensures that the cache
// is only cleared when the full caches are cleared manually (eg by invoking
// drupal_flush_all_caches()), and not on a cron run.
// @see drupal_flush_all_caches()
// @see system_cron()
if ($wildcard) {
ctools_include('css');
ctools_css_flush_caches();
}
}
/**
* {@inheritdoc}
*/
public function get($cid) {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getMultiple(&$cids) {
return array();
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function set($cid, $data, $expire = CACHE_PERMANENT) {
}
}
......@@ -79,6 +79,19 @@ function ctools_fields_get_field_formatter_settings_form($field, $formatter_type
$instance = ctools_fields_fake_field_instance($field['field_name'], $view_mode, $formatter_type, $conf['formatter_settings']);
$settings_form = $function($field, $instance, $view_mode, $form, $form_state);
if ($settings_form) {
// Allow other modules to alter the formatter settings form.
$context = array(
'module' => $formatter['module'],
'formatter' => $formatter,
'field' => $field,
'instance' => $instance,
'view_mode' => $view_mode,
'form' => $form,
'form_state' => $form_state,
);
drupal_alter('field_formatter_settings_form', $settings_form, $context);
$settings_form['#tree'] = TRUE;
$form['ctools_field_list']['#value'][] = $field;
$form += $settings_form;
}
......
......@@ -187,7 +187,7 @@ function ctools_modal_text_button($text, $dest, $alt, $class = '') {
/**
* Wrap a form so that we can use it properly with AJAX. Essentially if the
* form wishes to render, it automatically does that, otherwise it returns
* so we can see submission results.
* the render array so we can see submission results.
* @param array $form
* An associative array containing the structure of the form.
......@@ -201,9 +201,9 @@ function ctools_modal_text_button($text, $dest, $alt, $class = '') {
* is set, this will use ctools_modal_form_render so it will be
* a $command object suitable for ajax_render already.
*
* The return will be NULL if the form was successfully submitted unless
* you specifically set re_render = TRUE. If ajax is set the
* form will never be redirected.
* If the form was not rendered, the raw render array will be returned.
*
* If ajax is set the form will never be redirected.
*/
function ctools_modal_form_wrapper($form_id, &$form_state) {
// Since this will run again on form rebuild while still in the modal, prevent
......@@ -220,7 +220,7 @@ function ctools_modal_form_wrapper($form_id, &$form_state) {
);
$output = drupal_build_form($form_id, $form_state);
if (!empty($form_state['ajax']) && (!$form_state['executed'] || $form_state['rebuild'])) {
if (!empty($form_state['ajax']) && (!$form_state['executed'] || $form_state['rebuild'])) {
return ctools_modal_form_render($form_state, $output);
}
......
......@@ -214,7 +214,12 @@ function ctools_plugin_api_get_hook($owner, $api) {
function ctools_get_plugins($module, $type, $id = NULL) {
// Store local caches of plugins and plugin info so we don't have to do full
// lookups everytime.
$plugins = &drupal_static('ctools_plugins', array());
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast['plugins'] = &drupal_static('ctools_plugins', array());
}
$plugins = &$drupal_static_fast['plugins'];
$info = ctools_plugin_get_plugin_type_info();
// Bail out noisily if an invalid module/type combination is requested.
......@@ -423,25 +428,15 @@ function ctools_plugin_load_includes($info, $filename = NULL) {
// store static of plugin arrays for reference because they can't be reincluded.
static $plugin_arrays = array();
// If we're being asked for all plugins of a type, skip any caching
// we may have done because this is an admin task and it's ok to
// spend the extra time.
if (!isset($filename)) {
$all_files[$info['module']][$info['type']] = NULL;
}
if (!isset($all_files[$info['module']][$info['type']])) {
// If a filename was set, we will try to load our list of files from
// cache. This is considered normal operation and we try to reduce
// the time spent finding files.
if (isset($filename)) {
$cache = cache_get("ctools_plugin_files:$info[module]:$info[type]");
if ($cache) {
$all_files[$info['module']][$info['type']] = $cache->data;
}
}
if (!isset($all_files[$info['module']][$info['type']])) {
$cache = cache_get("ctools_plugin_files:$info[module]:$info[type]");
if ($cache) {
$all_files[$info['module']][$info['type']] = $cache->data;
}
// Do not attempt any file scan even if the cached entry was empty.
// A NULL entry here would mean the plugin just does not exists, and we
// cannot afford to run file scan on production sites normal run.
elseif (!isset($all_files[$info['module']][$info['type']])) {
$all_files[$info['module']][$info['type']] = array();
// Load all our plugins.
$directories = ctools_plugin_get_directories($info);
......@@ -683,7 +678,7 @@ function ctools_plugin_process($info, $module, $identifier, $path, $file = NULL,
if (!function_exists($function)) {
return NULL;
}
$result = $function();
$result = $function($info);
if (!isset($result) || !is_array($result)) {
return NULL;
}
......
......@@ -274,7 +274,7 @@ function ctools_wizard_wrapper($form, &$form_state) {
if (!empty($form_info['show trail'])) {
ctools_add_css('wizard');
$form['ctools_trail'] = array(
'#markup' => theme(array('ctools_wizard_trail__' . $form_info['id'], 'ctools_wizard_trail'), array('trail' => $trail)),
'#markup' => theme(array('ctools_wizard_trail__' . $form_info['id'], 'ctools_wizard_trail'), array('trail' => $trail, 'form_info' => $form_info)),
'#weight' => -1000,
);
}
......
......@@ -7,19 +7,16 @@
function ctools_wizard_theme(&$theme) {
$theme['ctools_wizard_trail'] = array(
'variables' => array('trail' => NULL),
'variables' => array('trail' => NULL, 'form_info' => NULL, 'divider' => ' » '),
'file' => 'includes/wizard.theme.inc',
);
}
/**
* Themable display of the 'breadcrumb' trail to show the order of the
* forms.
* Themable display of the 'breadcrumb' trail to show the order of the forms.
*/
function theme_ctools_wizard_trail($vars) {
$trail = $vars['trail'];
if (!empty($trail)) {