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
@@ -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)) {