uppdated modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-01-22 16:19:36 +01:00
parent 03be8f82aa
commit 8416e3eea1
748 changed files with 32317 additions and 20900 deletions
@@ -0,0 +1,44 @@
<?php
/**
* @file
* Plugin for controlling access based on the existence of a query string.
*/
$plugin = array(
'title' => t('Query string exists'),
'description' => t('Control access by whether or not a query string exists.'),
'callback' => 'ctools_query_string_exists_ctools_access_check',
'settings form' => 'ctools_query_string_exists_ctools_access_settings',
'summary' => 'ctools_query_string_exists_ctools_access_summary',
'defaults' => array('key' => ''),
);
/**
* Settings form.
*/
function ctools_query_string_exists_ctools_access_settings($form, &$form_state, $config) {
$form['settings']['key'] = array(
'#title' => t('Query string key'),
'#description' => t('Enter the key of the query string.'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => $config['key']
);
return $form;
}
/**
* Check for access.
*/
function ctools_query_string_exists_ctools_access_check($config, $context) {
return isset($_GET[$config['key']]);
}
/**
* Provide a summary description.
*/
function ctools_query_string_exists_ctools_access_summary($config, $context) {
return t('@identifier exists', array('@identifier' => $config['key']));
}
@@ -3,7 +3,7 @@
/**
* @file
*
* Plugin to provide an argument handler for all entity ids
* Plugin to provide an argument handler for all entity ids.
*/
/**
@@ -17,7 +17,7 @@ $plugin = array(
'get child' => 'ctools_argument_entity_id_get_child',
'get children' => 'ctools_argument_entity_id_get_children',
'default' => array(
'entity_id' => ''
'entity_id' => '',
),
'placeholder form' => 'ctools_argument_entity_id_ctools_argument_placeholder',
);
@@ -41,6 +41,7 @@ function ctools_argument_entity_id_get_children($original_plugin, $parent) {
$plugins[$plugin_id] = $plugin;
}
drupal_alter('ctools_entity_contexts', $plugins);
return $plugins;
}
@@ -60,9 +61,12 @@ function ctools_argument_entity_id_context($arg = NULL, $conf = NULL, $empty = F
return ctools_context_create('entity:' . $entity_type, $arg);
}
// Trim spaces and other garbage.
$arg = trim($arg);
if (!is_numeric($arg)) {
$preg_matches = array();
$match = preg_match('/\[id: (\d+)\]/', $arg, $preg_matches);
$match = preg_match('/\[id: (\d+)\]/', $arg, $preg_matches);
if (!$match) {
$match = preg_match('/^id: (\d+)/', $arg, $preg_matches);
}
@@ -70,18 +74,18 @@ function ctools_argument_entity_id_context($arg = NULL, $conf = NULL, $empty = F
if ($match) {
$id = $preg_matches[1];
}
if (is_numeric($id)) {
if (isset($id) && is_numeric($id)) {
return ctools_context_create('entity:' . $entity_type, $id);
}
return FALSE;
}
$entity = entity_load($entity_type, array($arg));
if (!$entity) {
$entities = entity_load($entity_type, array($arg));
if (empty($entities)) {
return FALSE;
}
return ctools_context_create('entity:' . $entity_type, $entity[$arg]);
return ctools_context_create('entity:' . $entity_type, reset($entities));
}
function ctools_argument_entity_id_settings_form(&$form, &$form_state, $conf) {
@@ -119,7 +123,7 @@ function ctools_argument_entity_id_settings_form(&$form, &$form_state, $conf) {
$form['settings']['entity_id'] = array(
'#type' => 'value',
'#value' => $conf['entity_id'],
'#value' => isset($conf['entity_id']) ? $conf['entity_id'] : '',
);
$form['settings']['entity_type'] = array(
@@ -132,11 +136,12 @@ function ctools_argument_entity_id_settings_form(&$form, &$form_state, $conf) {
function ctools_argument_entity_id_ctools_argument_placeholder($conf) {
$conf = array(
'#title' => t('Enter the title or ID of a @entity entity', array('@entity' => $conf['keyword'])),
'#type' => 'textfield',
'#maxlength' => 512,
'#title' => t('Enter the title or ID of a @entity entity', array('@entity' => $conf['keyword'])),
'#type' => 'textfield',
'#maxlength' => 512,
'#autocomplete_path' => 'ctools/autocomplete/' . $conf['keyword'],
'#weight' => -10,
'#weight' => -10,
);
return $conf;
}
@@ -18,6 +18,7 @@ $plugin = array(
'context' => 'ctools_term_context',
'default' => array('input_form' => 'tid', 'breadcrumb' => TRUE, 'transform' => FALSE),
'settings form' => 'ctools_term_settings_form',
'settings form validate' => 'ctools_term_settings_form_validate',
'placeholder form' => 'ctools_term_ctools_argument_placeholder',
'breadcrumb' => 'ctools_term_breadcrumb',
);
@@ -31,6 +32,16 @@ function ctools_term_context($arg = NULL, $conf = NULL, $empty = FALSE) {
return ctools_context_create_empty('entity:taxonomy_term');
}
if (isset($conf['vocabularies'])) {
$vocabularies = $conf['vocabularies'];
}
else {
$vids = isset($conf['vids']) ? $conf['vids'] : array();
// Convert legacy use of vids to machine names.
$vocabularies = _ctools_term_vocabulary_machine_name_convert($vids);
}
if (is_object($arg)) {
$term = $arg;
}
@@ -50,12 +61,11 @@ function ctools_term_context($arg = NULL, $conf = NULL, $empty = FALSE) {
}
$terms = taxonomy_get_term_by_name($arg);
$conf['vids'] = is_array($conf['vids']) ? array_filter($conf['vids']) : NULL;
if ((count($terms) > 1) && isset($conf['vids'])) {
// If only one term is found, fall through to vocabulary check below.
if ((count($terms) > 1) && $vocabularies) {
foreach ($terms as $potential) {
foreach ($conf['vids'] as $vid => $active) {
if ($active && $potential->vid == $vid) {
foreach ($vocabularies as $machine_name) {
if ($potential->vocabulary_machine_name == $machine_name) {
$term = $potential;
// break out of the foreaches AND the case
break 3;
@@ -72,7 +82,7 @@ function ctools_term_context($arg = NULL, $conf = NULL, $empty = FALSE) {
}
}
if (!empty($conf['vids']) && array_filter($conf['vids']) && empty($conf['vids'][$term->vid])) {
if ($vocabularies && !isset($vocabularies[$term->vocabulary_machine_name])) {
return NULL;
}
@@ -98,13 +108,20 @@ function ctools_term_settings_form(&$form, &$form_state, $conf) {
$vocabularies = taxonomy_get_vocabularies();
$options = array();
foreach ($vocabularies as $vid => $vocab) {
$options[$vid] = $vocab->name;
$options[$vocab->machine_name] = $vocab->name;
}
$form['settings']['vids'] = array(
// Fallback on legacy 'vids', when no vocabularies are available.
if (empty($conf['vocabularies']) && !empty($conf['vids'])) {
$conf['vocabularies'] = _ctools_term_vocabulary_machine_name_convert(array_filter($conf['vids']));
unset($conf['vids']);
}
$form['settings']['vocabularies'] = array(
'#title' => t('Limit to these vocabularies'),
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => !empty($conf['vids']) ? $conf['vids'] : array(),
'#default_value' => !empty($conf['vocabularies']) ? $conf['vocabularies'] : array(),
'#description' => t('If no vocabularies are checked, terms from all vocabularies will be accepted.'),
);
@@ -123,6 +140,12 @@ function ctools_term_settings_form(&$form, &$form_state, $conf) {
// return $form;
}
function ctools_term_settings_form_validate (&$form, &$form_state) {
// Filter the selected vocabularies to avoid storing redundant data.
$vocabularies = array_filter($form_state['values']['settings']['vocabularies']);
form_set_value($form['settings']['vocabularies'], $vocabularies, $form_state);
}
/**
* Form fragment to get an argument to convert a placeholder for preview.
*/
@@ -161,3 +184,20 @@ function ctools_term_breadcrumb($conf, $context) {
$breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb));
drupal_set_breadcrumb($breadcrumb);
}
/**
* Helper function to convert convert legacy vocabulary ids into machine names.
*
* @param array $vids
* Array of either vids.
* @return array
* A keyed array of machine names.
*/
function _ctools_term_vocabulary_machine_name_convert($vids) {
$vocabularies = taxonomy_vocabulary_load_multiple($vids);
$return = array();
foreach($vocabularies as $vocabulary) {
$return[$vocabulary->machine_name] = $vocabulary->machine_name;
}
return $return;
}
@@ -65,6 +65,7 @@ function ctools_terms_breadcrumb($conf, $context) {
return;
}
$current = new stdClass();
$current->tid = $context->tids[0];
$breadcrumb = array();
while ($parents = taxonomy_get_parents($current->tid)) {
@@ -372,9 +372,9 @@ function profile_ctools_block_info($module, $delta, &$info) {
}
function book_ctools_block_info($module, $delta, &$info) {
// Hide the book navigation block which isn't as rich as what we can
// do with context.
$info = NULL;
$info['title'] = t('Book navigation menu');
$info['icon'] = 'icon_core_block_menu.png';
$info['category'] = t('Node');
}
function blog_ctools_block_info($module, $delta, &$info) {
@@ -0,0 +1,74 @@
<?php
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'single' => TRUE,
'title' => t('Comment created date'),
'icon' => 'icon_comment.png',
'description' => t('The date the referenced comment was created.'),
'required context' => new ctools_context_required(t('Comment'), 'entity:comment'),
'category' => t('Comment'),
'defaults' => array(
'format' => 'small',
),
);
/**
* Render the custom content type.
*/
function ctools_comment_created_content_type_render($subtype, $conf, $panel_args, $context) {
if (empty($context) || empty($context->data)) {
return;
}
// Get a shortcut to the comment.
$comment = $context->data;
// Build the content type block.
$block = new stdClass();
$block->module = 'comment_created';
$block->title = t('Created date');
$block->content = format_date($comment->created, $conf['format']);
$block->delta = $comment->cid;
return $block;
}
/**
* Returns an edit form for custom type settings.
*/
function ctools_comment_created_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$date_types = array();
foreach (system_get_date_types() as $date_type => $definition) {
$date_types[$date_type] = format_date(REQUEST_TIME, $date_type);
}
$form['format'] = array(
'#title' => t('Date format'),
'#type' => 'select',
'#options' => $date_types,
'#default_value' => $conf['format'],
);
return $form;
}
/**
* Submit handler for the custom type settings form.
*/
function ctools_comment_created_content_type_edit_form_submit($form, &$form_state) {
// Copy everything from our defaults.
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
/**
* Returns the administrative title for a type.
*/
function ctools_comment_created_content_type_admin_title($subtype, $conf, $context) {
return t('"@s" created date', array('@s' => $context->identifier));
}
@@ -26,7 +26,7 @@ function ctools_comment_links_content_type_render($subtype, $conf, $panel_args,
return;
}
$comment = isset($context->data) ? clone($context->data) : NULL;
$comment = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'comment';
$block->delta = $comment->cid;
@@ -25,7 +25,7 @@ if (module_exists('comment')) {
function ctools_comment_reply_form_content_type_render($subtype, $conf, $panel_args, $context) {
$comment = ($context[1]->identifier == t('No context')) ? NULL : clone($context[1]->data);
$comment = ($context[1]->identifier == t('No context')) ? NULL : clone $context[1]->data;
$block = new stdClass();
$block->module = 'comments';
if ($comment) $block->delta = $comment->cid;
@@ -16,7 +16,7 @@
$plugin = array(
'title' => t('Custom content'),
'no title override' => TRUE,
'defaults' => array('admin_title' => '', 'title' => '', 'body' => '', 'format' => filter_default_format(), 'substitute' => TRUE),
'defaults' => array('admin_title' => '', 'title' => '', 'title_heading' => 'h2', 'body' => '', 'format' => filter_default_format(), 'substitute' => TRUE),
'js' => array('misc/autocomplete.js', 'misc/textarea.js', 'misc/collapse.js'),
// Make sure the edit form is only used for some subtypes.
'edit form' => '',
@@ -135,6 +135,7 @@ function ctools_custom_content_type_get_conf($subtype, $conf) {
$settings = array(
'admin_title' => t('Missing/deleted content'),
'title' => '',
'title_heading' => '',
'body' => '',
'format' => filter_default_format(),
'substitute' => TRUE,
@@ -180,6 +181,8 @@ function ctools_custom_content_type_render($subtype, $conf, $args, $contexts) {
$block = new stdClass();
$block->subtype = ++$delta;
$block->title = filter_xss_admin($settings['title']);
$block->title_heading = isset($settings['title_heading']) ? $settings['title_heading'] : 'h2';
// Add keyword substitutions if we were configured to do so.
$content = $settings['body'];
@@ -277,10 +280,36 @@ function ctools_custom_content_type_edit_form($form, &$form_state) {
'#description' => t('This title will be used administratively to identify this pane. If blank, the regular title will be used.'),
);
// Copy over the title override settings for a title heading.
$form['aligner_start'] = array(
'#markup' => '<div class="option-text-aligner clearfix">',
);
$form['title'] = array(
'#type' => 'textfield',
'#default_value' => $settings['title'],
'#title' => t('Title'),
'#id' => 'override-title-textfield',
);
$form['title_heading'] = array(
'#type' => 'select',
'#default_value' => isset($settings['title_heading']) ? $settings['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',
);
$form['aligner_stop'] = array(
'#markup' => '</div>',
);
$form['body'] = array(
@@ -34,6 +34,14 @@ function ctools_entity_field_content_type_content_types() {
return $types;
}
$cache_key = 'ctools_entity_field_content_type_content_types';
if ($cache = cache_get($cache_key)) {
$types = $cache->data;
if (!empty($types)) {
return $types;
}
}
// This will hold all the individual field content types.
$context_types = array();
$entities = entity_get_info();
@@ -82,6 +90,8 @@ function ctools_entity_field_content_type_content_types() {
unset($context_types[$key]['types']);
}
cache_set($cache_key, $types);
return $types;
}
@@ -127,25 +137,24 @@ function ctools_entity_field_content_type_render($subtype, $conf, $panel_args, $
$field_settings['settings'] = $conf['formatter_settings'];
}
$all_values = field_get_items($entity_type, $entity, $field_name, $language);
if (!is_array($all_values)) {
// Do not render if the field is empty.
return;
}
// Reverse values.
if (isset($conf['delta_reversed']) && $conf['delta_reversed']) {
$all_values = array_reverse($all_values, TRUE);
}
if (isset($conf['delta_limit'])) {
$offset = intval($conf['delta_offset']);
$limit = !empty($conf['delta_limit']) ? $conf['delta_limit'] : NULL;
$all_values = array_slice($all_values, $offset, $limit, TRUE);
}
$clone = clone $entity;
$clone->{$field_name}[$language] = $all_values;
$all_values = field_get_items($entity_type, $entity, $field_name, $language);
if (is_array($all_values)) {
// Reverse values.
if (isset($conf['delta_reversed']) && $conf['delta_reversed']) {
$all_values = array_reverse($all_values, TRUE);
}
if (isset($conf['delta_limit'])) {
$offset = intval($conf['delta_offset']);
$limit = !empty($conf['delta_limit']) ? $conf['delta_limit'] : NULL;
$all_values = array_slice($all_values, $offset, $limit, TRUE);
}
$clone->{$field_name}[$language] = $all_values;
}
$field_output = field_view_field($entity_type, $clone, $field_name, $field_settings, $language);
if (!empty($field_output) && !empty($conf['override_title'])) {
@@ -260,10 +269,7 @@ function ctools_entity_field_content_type_admin_title($subtype, $conf, $context)
$identifier = $context->identifier;
}
else {
$type = 'ctools_entity_field_content_type_admin_title';
$message = t('Context is missing for field: @name', array('@name' => $subtype));
$variables = array($subtype, $conf, $context);
watchdog($type, $message, $variables, $severity = WATCHDOG_NOTICE);
watchdog('ctools_entity_field_content_type_admin_title', 'Context is missing for field: @name', array('@name' => $subtype), WATCHDOG_NOTICE);
$identifier = t('Unknown');
}
@@ -57,6 +57,26 @@ function ctools_entity_form_field_content_type_content_types() {
}
}
if (module_exists('field_group')) {
foreach ($entities as $entity_type => $entity) {
foreach ($entity['bundles'] as $type => $bundle) {
if ($group_info = field_group_info_groups($entity_type, $type, "form")) {
foreach ($group_info as $group_name => $group) {
if (!isset($types[$entity_type . ':' . $group_name])) {
$types[$entity_type . ':' . $group_name] = array(
'category' => t('Form'),
'icon' => 'icon_field.png',
'title' => t('Group form: @widget_label', array('@widget_label' => $group->label)),
'description' => t('Field group on the referenced entity.'),
);
}
$content_types[$entity_type . ':' . $group_name]['types'][$type] = $bundle['label'];
}
}
}
}
}
// Create the required context for each field related to the bundle types.
foreach ($types as $key => $field_content_type) {
list($entity_type, $field_name) = explode(':', $key, 2);
@@ -85,16 +105,38 @@ function ctools_entity_form_field_content_type_render($subtype, $conf, $panel_ar
$ids = entity_extract_ids($entity_type, $entity);
$field = field_info_instance($entity_type, $field_name, $ids[2]);
// Do not render if the entity type does not have this field.
if (empty($field)) {
// Check for field groups.
if (empty($field) && module_exists('field_group')) {
$groups = field_group_info_groups($entity_type, $entity->type, "form");
$group = !empty($groups[$field_name]) ? $groups[$field_name] : NULL;
}
// Do not render if the entity type does not have this field or group.
if (empty($field) && empty($group)) {
return;
}
$block = new stdClass();
$block = new stdClass();
if (isset($context->form)) {
$block->content = array();
$block->content[$field_name] = $context->form[$field_name];
unset($context->form[$field_name]);
if (!empty($field)) {
$block->content[$field_name] = $context->form[$field_name];
unset($context->form[$field_name]);
}
else {
// Pre-render the form to populate field groups.
if (isset($context->form['#pre_render'])) {
foreach ($context->form['#pre_render'] as $function) {
if (function_exists($function)) {
$context->form = $function($context->form);
}
}
unset($context->form['#pre_render']);
}
$block->content[$field_name] = $context->form[$field_name];
unset($context->form[$field_name]);
}
}
else {
$block->content = t('Entity info.');
@@ -66,7 +66,7 @@ function ctools_node_content_type_render($subtype, $conf, $panel_args) {
// Don't store viewed node data on the node, this can mess up other
// views of the node.
$node = clone($node);
$node = clone $node;
$block->module = 'node';
$block->delta = $node->nid;
@@ -14,7 +14,7 @@ $plugin = array(
);
function ctools_node_attachments_content_type_render($subtype, $conf, $panel_args, $context) {
$node = isset($context->data) ? clone($context->data) : NULL;
$node = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'attachments';
@@ -16,7 +16,7 @@ if (module_exists('book')) {
}
function ctools_node_book_children_content_type_render($subtype, $conf, $panel_args, $context) {
$node = isset($context->data) ? clone($context->data) : NULL;
$node = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'book_children';
@@ -0,0 +1,101 @@
<?php
if (module_exists('book')) {
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'single' => TRUE,
'title' => t('Book navigation menu'),
'icon' => '../block/icon_core_block_menu.png',
'description' => t('The book menu belonging to the current book node.'),
'required context' => new ctools_context_required(t('Node'), 'node'),
'category' => t('Node'),
);
}
function ctools_node_book_menu_content_type_render($subtype, $conf, $panel_args, $context) {
$node = isset($context->data) ? clone($context->data) : NULL;
$block = new stdClass();
$block->module = 'book_menu';
if ($conf['override_title']) {
$block->title = t($conf['override_title_text']);
}
else {
$block->title = t('Book navigation menu');
}
if ($node) {
$block->delta = $node->nid;
// TODO: the value is not available somehow?!?
$book_block_mode = isset($conf['book_block_mode']) ? $conf['book_block_mode'] : 'book pages';
// Code below is taken from function book_block_view().
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
if ($book_block_mode === 'all pages') {
$block->subject = t('Book navigation');
$book_menus = array();
$pseudo_tree = array(0 => array('below' => FALSE));
foreach (book_get_books() as $book_id => $book) {
if ($book['bid'] === $current_bid) {
// If the current page is a node associated with a book, the menu
// needs to be retrieved.
$book_menus[$book_id] = menu_tree_output(menu_tree_all_data($node->book['menu_name'], $node->book));
}
else {
// Since we know we will only display a link to the top node, there
// is no reason to run an additional menu tree query for each book.
$book['in_active_trail'] = FALSE;
// Check whether user can access the book link.
$book_node = node_load($book['nid']);
$book['access'] = node_access('view', $book_node);
$pseudo_tree[0]['link'] = $book;
$book_menus[$book_id] = menu_tree_output($pseudo_tree);
}
}
$book_menus['#theme'] = 'book_all_books_block';
$block->content = $book_menus;
}
elseif ($current_bid) {
// Only display this block when the user is browsing a book.
$select = db_select('node', 'n')
->fields('n', array('title'))
->condition('n.nid', $node->book['bid'])
->addTag('node_access');
$title = $select->execute()->fetchField();
// Only show the block if the user has view access for the top-level node.
if ($title) {
$tree = menu_tree_all_data($node->book['menu_name'], $node->book);
// There should only be one element at the top level.
$data = array_shift($tree);
// TODO: subject is not rendered
$block->subject = theme('book_title_link', array('link' => $data['link']));
$block->content = ($data['below']) ? menu_tree_output($data['below']) : '';
}
}
}
else {
$block->content = t('Book navigation pager goes here.');
$block->delta = 'unknown';
}
return $block;
}
function ctools_node_book_menu_content_type_admin_title($subtype, $conf, $context) {
return t('"@s" book navigation pager', array('@s' => $context->identifier));
}
function ctools_node_book_menu_content_type_edit_form($form, &$form_state) {
// Grab block form from the book module.
$block_form = book_block_configure($delta = '');
// TODO: this does not work yet.
// See TODO in: ctools_node_book_menu_content_type_render
if (isset($form_state['input']['book_block_mode'])) {
$block_form['book_block_mode']['#default_value'] = $form_state['input']['book_block_mode'];
}
$form += $block_form;
return $form;
}
@@ -7,26 +7,26 @@ if (module_exists('book')) {
*/
$plugin = array(
'single' => TRUE,
'title' => t('Book navigation'),
'icon' => 'icon_node.png',
'description' => t('The navigation menu the book the node belongs to.'),
'title' => t('Book navigation pager'),
'icon' => '../block/icon_core_booknavigation.png',
'description' => t('The navigational pager and sub pages of the current book node.'),
'required context' => new ctools_context_required(t('Node'), 'node'),
'category' => t('Node'),
);
}
function ctools_node_book_nav_content_type_render($subtype, $conf, $panel_args, $context) {
$node = isset($context->data) ? clone($context->data) : NULL;
$node = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'book_nav';
$block->title = t('Book navigation');
$block->title = t('Book navigation pager');
if ($node) {
$block->content = isset($node->book) ? theme('book_navigation', array('book_link' => $node->book)) : '';
$block->delta = $node->nid;
}
else {
$block->content = t('Book navigation goes here.');
$block->content = t('Book navigation pager goes here.');
$block->delta = 'unknown';
}
@@ -34,7 +34,7 @@ function ctools_node_book_nav_content_type_render($subtype, $conf, $panel_args,
}
function ctools_node_book_nav_content_type_admin_title($subtype, $conf, $context) {
return t('"@s" book navigation', array('@s' => $context->identifier));
return t('"@s" book navigation pager', array('@s' => $context->identifier));
}
function ctools_node_book_nav_content_type_edit_form($form, &$form_state) {
@@ -17,7 +17,7 @@ if (module_exists('comment')) {
}
function ctools_node_comment_form_content_type_render($subtype, $conf, $panel_args, $context) {
$node = isset($context->data) ? clone($context->data) : NULL;
$node = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'comments';
$block->delta = $node->nid;
@@ -77,20 +77,3 @@ function ctools_node_comment_form_content_type_edit_form_submit($form, &$form_st
}
}
/**
* Alter the comment form to get a little more control over it.
*/
function ctools_form_comment_form_alter(&$form, &$form_state) {
if (!empty($form_state['ctools comment alter'])) {
// Force the form to post back to wherever we are.
$form['#action'] = url($_GET['q'], array('fragment' => 'comment-form'));
if (empty($form['#submit'])) {
$form['#submit'] = array('comment_form_submit');
}
$form['#submit'][] = 'ctools_node_comment_form_submit';
}
}
function ctools_node_comment_form_submit(&$form, &$form_state) {
$form_state['redirect'][0] = $_GET['q'];
}
@@ -23,7 +23,7 @@ if (module_exists('comment')) {
* Render the node comments.
*/
function ctools_node_comment_wrapper_content_type_render($subtype, $conf, $panel_args, $context) {
$node = isset($context->data) ? clone($context->data) : NULL;
$node = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'comments';
$block->delta = $node->nid;
@@ -77,7 +77,7 @@ function ctools_node_comment_wrapper_content_type_render($subtype, $conf, $panel
/**
* Returns an edit form for the comment wrapper.
*/
*/
function ctools_node_comment_wrapper_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$form['mode'] = array(
@@ -20,7 +20,7 @@ if (module_exists('comment')) {
}
function ctools_node_comments_content_type_render($subtype, $conf, $panel_args, $context) {
$node = isset($context->data) ? clone($context->data) : NULL;
$node = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'comments';
$block->delta = $node->nid;
@@ -31,7 +31,7 @@ function ctools_node_content_content_type_render($subtype, $conf, $panel_args, $
return;
}
$node = isset($context->data) ? clone($context->data) : NULL;
$node = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'node';
$block->delta = $node->nid;
@@ -29,7 +29,7 @@ function ctools_node_links_content_type_render($subtype, $conf, $panel_args, $co
return;
}
$node = isset($context->data) ? clone($context->data) : NULL;
$node = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'node';
$block->delta = $node->nid;
@@ -18,7 +18,7 @@ $plugin = array(
* based on the module and delta supplied in the configuration.
*/
function ctools_node_type_desc_content_type_render($subtype, $conf, $panel_args, $context) {
$node = isset($context->data) ? clone($context->data) : NULL;
$node = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'node_type';
@@ -29,6 +29,9 @@ $plugin = array(
* Outputs the page title of the current page.
*/
function ctools_page_title_content_type_render($subtype, $conf, $panel_args) {
if (!drupal_get_title()) {
return;
}
// TODO: This should have a setting or something for the markup.
if (empty($conf['markup'])) {
$conf['markup'] = 'h1';
@@ -14,12 +14,12 @@ $plugin = array(
);
function ctools_term_description_content_type_render($subtype, $conf, $panel_args, $context) {
$term = isset($context->data) ? clone($context->data) : NULL;
$term = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'node_type';
$block->title = $term->name;
if ($term) {
if (!empty($term)) {
$block->title = $term->name;
$block->content = check_markup($term->description, $term->format, '', TRUE);
$block->delta = $term->tid;
@@ -33,6 +33,7 @@ function ctools_term_description_content_type_render($subtype, $conf, $panel_arg
}
}
else {
$block->title = '';
$block->content = t('Term description goes here.');
$block->delta = 'unknown';
}
@@ -21,7 +21,7 @@ $plugin = array(
);
function ctools_term_list_content_type_render($subtype, $conf, $panel_args, $context) {
$term = isset($context->data) ? clone($context->data) : NULL;
$term = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'term-list';
$path = empty($conf['path']) ? 'taxonomy/term/%tid' : $conf['path'];
@@ -21,7 +21,7 @@ if (module_exists('profile') && !(defined('MAINTENANCE_MODE') && MAINTENANCE_MOD
* 'Render' callback for the 'profile fields' content type.
*/
function ctools_profile_fields_content_type_render($subtype, $conf, $panel_args, $context) {
$account = isset($context->data) ? clone($context->data) : NULL;
$account = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'profile fields';
@@ -20,7 +20,7 @@ $plugin = array(
* Render the user profile content type.
*/
function ctools_user_profile_content_type_render($subtype, $conf, $panel_args, $context) {
$account = isset($context->data) ? clone($context->data) : NULL;
$account = isset($context->data) ? clone $context->data : NULL;
if (!$account) {
return NULL;
}
@@ -13,7 +13,7 @@ $plugin = array(
);
function ctools_user_signature_content_type_render($subtype, $conf, $panel_args, $context) {
$account = isset($context->data) ? clone($context->data) : NULL;
$account = isset($context->data) ? clone $context->data : NULL;
$block = new stdClass();
$block->module = 'user-signature';
@@ -21,7 +21,7 @@ if (module_exists('taxonomy')) {
* list of terms for the input vocabulary.
*/
function ctools_vocabulary_terms_content_type_render($subtype, $conf, $panel_args, $context) {
$vocab = isset($context->data) ? clone($context->data) : NULL;
$vocab = isset($context->data) ? clone $context->data : NULL;
$max_depth = (!empty($conf['max_depth']) ? (int)$conf['max_depth'] : NULL);
if ($conf['tree'] == FALSE) {
$terms = taxonomy_get_tree($vocab->vid, 0, $max_depth);
@@ -0,0 +1,89 @@
<?php
/**
* @file query_string.inc
* Context plugin that can extract arbitrary values from the query string.
*/
/**
* $plugin array which will be used by the system that includes this file.
*/
$plugin = array(
'title' => t('Query string value'),
'description' => t('A context that extracts a value from the query string.'),
'context' => 'ctools_context_query_string_create_query_string',
'context name' => 'query_string',
'keyword' => 'query_string',
'edit form' => 'ctools_context_query_string_settings_form',
'convert list' => array(
'raw' => t('Raw string'),
'html_safe' => t('HTML-safe string'),
),
'convert' => 'ctools_context_query_string_convert',
);
/**
* Create a context from manual configuration.
*/
function ctools_context_query_string_create_query_string($empty, $data = NULL, $conf = FALSE) {
$context = new ctools_context('query_string');
$context->plugin = 'query_string';
if ($empty) {
return $context;
}
if ($conf) {
if (!empty($_GET[$data['key']])) {
$context->data = $_GET[$data['key']];
}
else {
$context->data = $data['fallback_value'];
}
}
return $context;
}
/**
* Form builder; settings for the context.
*/
function ctools_context_query_string_settings_form($form, &$form_state) {
$form['key'] = array(
'#title' => t('Query string key'),
'#description' => t('Enter the key of the value that must be returned from the query string.'),
'#type' => 'textfield',
'#required' => TRUE
);
if (isset($form_state['conf']['key'])) {
$form['key']['#default_value'] = $form_state['conf']['key'];
}
$form['fallback_value'] = array(
'#title' => t('Fallback value'),
'#description' => t('Enter a value that must be returned if the above specified key does not exist in the query string.'),
'#type' => 'textfield',
);
if (!empty($form_state['conf']['fallback_value'])) {
$form['fallback_value']['#default_value'] = $form_state['conf']['fallback_value'];
}
return $form;
}
/**
* Submit handler; settings form for the context.
*/
function ctools_context_query_string_settings_form_submit($form, &$form_state) {
$form_state['conf']['key'] = $form_state['values']['key'];
$form_state['conf']['fallback_value'] = $form_state['values']['fallback_value'];
}
/**
* Convert a context into a string.
*/
function ctools_context_query_string_convert($context, $type) {
switch ($type) {
case 'raw':
return $context->data;
case 'html_safe':
return check_plain($context->data);
}
}
@@ -43,7 +43,9 @@ function ctools_context_create_user($empty, $data = NULL, $conf = FALSE) {
if ($data['type'] == 'current') {
global $user;
$data = user_load($user->uid);
$data->logged_in_user = TRUE;
if (user_is_logged_in()) {
$data->logged_in_user = TRUE;
}
}
else {
$data = user_load($data['uid']);
@@ -34,15 +34,15 @@ function ctools_context_create_user_edit_form($empty, $user = NULL, $conf = FALS
$category = !empty($conf['category']) ? $conf['category'] : FALSE;
unset($conf['category']);
// If no category was specified, use the default 'account'.
if (!$category) {
$category = 'account';
}
// Return previously created contexts, per category.
static $created = array();
if (!empty($created[$category])) {
return $created[$category];
}
// If no category was specified, use the default 'account'.
if (!$category) {
$category = 'account';
}
$context = new ctools_context(array('form', 'user_edit', 'user_form', 'user_edit_form', 'user', 'entity:user'));
// Store this context for later.
@@ -107,7 +107,7 @@ function ctools_context_user_edit_form_settings_form($form, &$form_state) {
);
if (!empty($conf['uid'])) {
$info = db_query('SELECT * FROM {user} WHERE uid = :uid', array(':uid' => $conf['uid']))->fetchObject();
$info = db_query('SELECT * FROM {users} WHERE uid = :uid', array(':uid' => $conf['uid']))->fetchObject();
if ($info) {
$link = l(t("'%name' [user id %uid]", array('%name' => $info->name, '%uid' => $info->uid)), "user/$info->uid", array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE));
$form['user']['#description'] = t('Currently set to !link', array('!link' => $link));
@@ -154,10 +154,10 @@ function ctools_context_user_edit_form_settings_form_validate($form, &$form_stat
$uid = $preg_matches[1];
}
if (is_numeric($uid)) {
$user = db_query('SELECT uid FROM {user} WHEREuid = :uid', array(':uid' => $uid))->fetchObject();
$user = db_query('SELECT uid FROM {users} WHERE uid = :uid', array(':uid' => $uid))->fetchObject();
}
else {
$user = db_query('SELECT uid FROM {user} WHERE LOWER(name) = LOWER(:name)', array(':name' => $uid))->fetchObject();
$user = db_query('SELECT uid FROM {users} WHERE LOWER(name) = LOWER(:name)', array(':name' => $uid))->fetchObject();
}
form_set_value($form['uid'], $user->uid, $form_state);
@@ -724,7 +724,13 @@ class ctools_export_ui {
// Export the handler, which is a fantastic way to clean database IDs out of it.
$export = ctools_export_crud_export($this->plugin['schema'], $original);
$item = ctools_export_crud_import($this->plugin['schema'], $export);
$item->{$this->plugin['export']['key']} = 'clone_of_' . $item->{$this->plugin['export']['key']};
if (!empty($input[$this->plugin['export']['key']])) {
$item->{$this->plugin['export']['key']} = $input[$this->plugin['export']['key']];
}
else {
$item->{$this->plugin['export']['key']} = 'clone_of_' . $item->{$this->plugin['export']['key']};
}
}
// Tabs and breadcrumb disappearing, this helps alleviate through cheating.
@@ -1441,7 +1447,7 @@ function ctools_export_ui_delete_confirm_form($form, &$form_state) {
$export_key = $plugin['export']['key'];
$question = str_replace('%title', check_plain($item->{$export_key}), $plugin['strings']['confirmation'][$form_state['op']]['question']);
$path = empty($_REQUEST['cancel_path']) ? ctools_export_ui_plugin_base_path($plugin) : $_REQUEST['cancel_path'];
$path = (!empty($_REQUEST['cancel_path']) && !url_is_external($_REQUEST['cancel_path'])) ? $_REQUEST['cancel_path'] : ctools_export_ui_plugin_base_path($plugin);
$form = confirm_form($form,
$question,
@@ -185,7 +185,7 @@ function ctools_entity_from_field_context($context, $conf) {
$loaded_to_entity = array_shift($loaded_to_entity);
// Pass current user account and entity type to access callback.
if (function_exists($to_entity_info['access callback']) && !call_user_func($to_entity_info['access callback'], 'view', $loaded_to_entity, $account, $to_entity)) {
if (isset($to_entity_info['access callback']) && function_exists($to_entity_info['access callback']) && !call_user_func($to_entity_info['access callback'], 'view', $loaded_to_entity, $account, $to_entity)) {
return ctools_context_create_empty('entity:' . $to_entity, NULL);
}
else {
@@ -0,0 +1,70 @@
<?php
/**
* @file
* Plugin to provide an relationship handler for entities from query string.
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t('Entity from query string'),
'keyword' => 'query_string_entity',
'description' => t('Entity from query string.'),
'required context' => new ctools_context_required(t('Query string'), 'query_string'),
'context' => 'ctools_entity_from_query_string_context',
'edit form' => 'ctools_entity_from_query_string_settings_form',
);
/**
* Return a new context based on an existing context.
*/
function ctools_entity_from_query_string_context($context, $conf) {
$entity_type = $conf['entity_type'];
// If unset it wants a generic, unfilled context, which is just NULL.
if (empty($context->data) || !isset($context->data) || !is_numeric($context->data)) {
return ctools_context_create_empty('entity:' . $entity_type, NULL);
}
if (!empty($context->data) && is_numeric($context->data)) {
// Load the entity from the query string value.
$entity_id = $context->data;
$entity = entity_load_single($entity_type, $entity_id);
// Send it to ctools.
return ctools_context_create('entity:' . $entity_type, $entity);
}
}
/**
* Settings form for the relationship.
*/
function ctools_entity_from_query_string_settings_form($form, &$form_state) {
//Get all avalible enity types
foreach (entity_get_info() as $key => $value) {
$entity_types[$key] = $value['label'];
}
$form['entity_type'] = array(
'#title' => t('Entity type'),
'#description' => t('Choose entity type to load from query value'),
'#type' => 'select',
'#options' => $entity_types,
);
if (isset($form_state['conf']['entity_type'])) {
$form['entity_type']['#default_value'] = $form_state['conf']['entity_type'];
}
return $form;
}
/**
* Submit handler; settings form for the context.
*/
function ctools_entity_from_query_string_settings_form_submit($form, &$form_state) {
$form_state['conf']['entity_type'] = $form_state['values']['entity_type'];
}
@@ -15,6 +15,8 @@ $plugin = array(
'description' => t('Adds user category edit form from a user context.'),
'required context' => new ctools_context_required(t('User'), 'user'),
'context' => 'ctools_user_category_edit_form_from_user_context',
'edit form' => 'ctools_user_category_edit_form_from_user_settings_form',
'defaults' => array('category' => NULL),
);
/**
@@ -25,7 +27,35 @@ function ctools_user_category_edit_form_from_user_context($context, $conf) {
return ctools_context_create_empty('user_edit_form', NULL);
}
if(!empty($conf['category'])) {
return ctools_context_create('user_edit_form', $context->data, array('category' => $conf['category']));
}
if (isset($context->data->user_category)) {
return ctools_context_create('user_edit_form', $context->data, array('category' => $context->data->user_category));
}
return ctools_context_create('user_edit_form', $context->data);
}
/**
* Settings form for the relationship.
*/
function ctools_user_category_edit_form_from_user_settings_form($form, &$form_state) {
$conf = $form_state['conf'];
$categories = _user_categories();
$options = array();
foreach($categories as $category) {
$options[$category['name']] = $category['title'];
}
$form['category'] = array(
'#type' => 'select',
'#title' => t('Category'),
'#options' => $options,
'#default_value' => isset($conf['category']) ? $conf['category'] : NULL,
'#empty_option' => 'Default',
);
return $form;
}