updated mailgun, mailsystem, honeypot, googleanalitycs, features, content_taxonomy

This commit is contained in:
2019-05-13 17:55:28 +02:00
parent 2ffad14939
commit e08a2639c6
54 changed files with 1911 additions and 423 deletions

View File

@@ -0,0 +1,42 @@
Content_Taxonomy 7.x-1.0-rc1, 2016-03-22
----------------------------------------
#1373716 by Owen Barton: Added hook_disable() to disable the custom field
widget and prevent site from breaking.
By mh86: Added hook for altering the term tree callback used in the allowed
values function.
By mh86: Added new submodule that supports the Entity Translation mode for
taxonomy terms.
By mh86: Fixed translated term names on initial autocomplete deluxe suggestions.
#1208164 by skein, mrded, rbayliss, drzraf, DamienMcKenna: Fix field migration.
#2580251 by michel.settembrino, DamienMcKenna: Added EntityReference
autocomplete support.
#2379611 by justanothermark: Wording change on autocomplete error message.
#1160146 by moskito: Added ActiveTags support.
#1395276 by bigjim: Fixed options field on migration.
#2348363 by james.williams, DamienMcKenna: Only alter field instances for
content_taxonomy fields.
#1558050 by bdimaggio, DamienMcKenna: The 'array_parents' element might not
exist.
#1643858 by DamienMcKenna, hatuhay, BrightBold, marthinal, benjy, mikhailian,
MakaziMtingwa, zhilevan, klidifia, pappuksingh, cameronbprince: Fix invalid
default values.
Content_Taxonomy 7.x-1.0-beta2, 2013-01-21
------------------------------------------
By mh86: Fixed validate handlers for new terms.
By mh86: Added Search API Postprocessor for filtering out moderated terms from
facets.
#1631000 by klausi: Fixed Strict warning: Declaration of
ContentTaxonomyAutocompleteModeratedTermsSearchAPIProcessor.
By mh86: Added option for selects lists with opt groups
Content_Taxonomy 7.x-1.0-beta1, 2011-06-22
------------------------------------------
By mh86: Initial port to D7.
#1079846 by mh86: Fixed error in content_taxonomy_autocomplete when using
without autocomplete_deluxe.
#1079938 by mh86: Fixed error in migration module.
#1086228 by mh86: Support for upgrading Hierarchical Select fields.
By mh86: Added option for the tree depth.

View File

@@ -0,0 +1,42 @@
<?php
/**
* @file
* This file contains no working PHP code; it exists to provide additional
* documentation for doxygen as well as to document hooks in the standard
* Drupal manner.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter the term tree callback that is used for content taxonomy options lists.
*
* By default taxonomy_get_tree is used to retrieve the list of terms. It is
* important that any provided tree callback must have the same function
* signature as hook_content_taxonomy_tree_callback_alter().
* For example this hook can be used to exchange the callback with a language
* specific tree function.
*
* @param $tree_callback
* The current callback that can be overridden.
* @param $field
* The term reference field info array.
* @param $vocabulary
* The vocabulary object for which the term list should be retrieved. One
* field can have multiple vocabularies attached, which leads to multiple
* invocations of this function.
*/
function hook_content_taxonomy_tree_callback_alter(&$tree_callback, $field, $vocabulary) {
if ($vocabulary->machine_name == 'my_voc') {
$tree_callback = 'my_tree_callback';
}
}
/**
* @} End of "addtogroup hooks".
*/

View File

@@ -8,9 +8,9 @@ dependencies[] = taxonomy
; Information added by drupal.org packaging script on 2013-02-13
version = "7.x-1.0-beta2"
; Information added by Drupal.org packaging script on 2016-03-22
version = "7.x-1.0-rc1"
core = "7.x"
project = "content_taxonomy"
datestamp = "1360767812"
datestamp = "1458667740"

View File

@@ -0,0 +1,94 @@
<?php
/**
* @file
* (Un-) installation tasks for content taxonomy.
*/
/**
* Implements hook_disable().
*
* Allow uninstall of content taxonomy by removing the callback in field
* configuration. Re-enabling requires to save the field configs to re-insert
* the callback.
*/
function content_taxonomy_disable() {
$fields = field_read_fields();
foreach ($fields as $field) {
if (isset($field['settings']['options_list_callback']) && $field['settings']['options_list_callback'] == 'content_taxonomy_allowed_values') {
// We cannot unset this value, because field_update_field() merges in
// prior settings before saving. Setting it to NULL works.
$field['settings']['options_list_callback'] = NULL;
}
field_update_field($field);
}
}
/**
* Implementations of hook_update_N().
*/
/**
* Fix the default values converted from D6. These values had an empty 'value'
* value which could cause errors on D7.
*/
function content_taxonomy_update_7100() {
$params = array(
'type' => 'taxonomy_term_reference',
);
foreach (field_read_fields($params) as $field) {
foreach (field_read_instances(array('field_name' => $field['field_name'])) as $instance) {
// If the 'default_value' item doesn't exist there's no point in
// continuing.
if (!isset($instance['default_value'])) {
continue;
}
// Keep track of whether fields are actually changed.
$updated = FALSE;
// Fix each of the default values.
foreach ($instance['default_value'] as $key => $defaults) {
// Need to check isset() and is_null() because the value could be NULL.
if (isset($instance['default_value'][$key]['value']) || is_null($instance['default_value'][$key]['value'])) {
// Remove any empty 'value' strings.
if (empty($instance['default_value'][$key]['value'])) {
unset($instance['default_value'][$key]['value']);
$updated = TRUE;
}
// Rename the 'value' string to 'tid'.
elseif (!isset($instance_value['default_value'][$key]['tid'])) {
$instance_value['default_value'][$key]['tid'] = $instance_value['default_value'][$key]['value'];
unset($instance_value['default_value'][$key]['value']);
$updated = TRUE;
}
// Look for a junk value carried over from D6.
if (isset($instance['default_value'][$key]['_error_element'])) {
unset($instance['default_value'][$key]['_error_element']);
$updated = TRUE;
}
// If the array is empty, just remove it.
if (empty($instance['default_value'][$key])) {
unset($instance['default_value'][$key]);
$updated = TRUE;
}
}
}
// If there are no default values left, just remove it.
if (empty($instance['default_value'])) {
unset($instance['default_value']);
$updated = TRUE;
}
// If the field's definition was changed, save it.
if ($updated) {
field_update_instance($instance);
drupal_set_message(t('Fixed configuration of the "@field_name" field ("@type" content type).', array('@field_name' => $instance['field_name'], '@type' => $instance['bundle'])));
}
}
}
}

View File

@@ -7,12 +7,14 @@ function content_taxonomy_form_field_ui_field_edit_form_alter(&$form, &$form_sta
$field = $form['#field'];
$instance = $form['#instance'];
// Add parent selector to term reference fields,
// except to the autocomplete widget, as it ignores the parent setting.
// Add parent selector to term reference fields, except to the autocomplete
// widget, as it ignores the parent setting.
if ($field['type'] == 'taxonomy_term_reference'
&& !($instance['widget']['type'] == 'taxonomy_autocomplete' || $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy')) {
// add parent form.
&& $instance['widget']['type'] != 'taxonomy_autocomplete'
&& $instance['widget']['type'] != 'autocomplete_deluxe_taxonomy'
&& $instance['widget']['type'] != 'entityreference_autocomplete'
&& $instance['widget']['type'] != 'entityreference_autocomplete_tags') {
// Add parent form.
foreach ($field['settings']['allowed_values'] as $delta => $tree) {
$options[0] = '---';
// todo this might break with huge vocs
@@ -76,7 +78,8 @@ function content_taxonomy_allowed_values($field) {
foreach ($field['settings']['allowed_values'] as $tree) {
if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
$max_depth = (isset($tree['depth']) && !empty($tree['depth'])) ? $tree['depth'] : NULL;
if ($terms = taxonomy_get_tree($vocabulary->vid, $tree['parent'], $max_depth)) {
$terms = content_taxonomy_get_terms($field, $vocabulary, $tree['parent'], $max_depth);
if (!empty($terms) && is_array($terms)) {
foreach ($terms as $term) {
$options[$term->tid] = str_repeat('- ', $term->depth) . $term->name;
}
@@ -86,6 +89,44 @@ function content_taxonomy_allowed_values($field) {
return $options;
}
/**
* Returns an array of terms that can be used in an options list.
*
* By default taxonomy_get_tree is used to retrieve the list of terms, but an
* alteration via hook_content_taxonomy_tree_callback_alter() is possible. It
* is important that any provided tree callback must have the same function
* signature as hook_content_taxonomy_tree_callback_alter().
* For example this hook can be used to exchange the callback with a language
* specific tree function.
*
* Although we could change the options list callback via the field definitions,
* it is easier to do this via the alteration hook provided by this function.
*
* @param $field
* The term reference field info array.
* @param $vocabulary
* The vocabulary object for which the term list should be retrieved. One
* field can have multiple vocabularies attached, which leads to multiple
* invocations of this function.
* @param $parent
* The parent term id. Use 0 for the root level.
* @param $max_depth
* The maximum depth. Use NULL for non limitation.
*
* @return array
*/
function content_taxonomy_get_terms($field, $vocabulary, $parent, $max_depth) {
$terms = array();
$tree_callback = 'taxonomy_get_tree';
drupal_alter('content_taxonomy_tree_callback', $tree_callback, $field, $vocabulary);
if (function_exists($tree_callback)) {
$terms = $tree_callback($vocabulary->vid, $parent, $max_depth, FALSE);
}
return $terms;
}
/**
* Implements hook_field_widget_info_alter().
*/
@@ -126,7 +167,8 @@ function content_taxonomy_allowed_values_opt_groups($field) {
$options = array();
foreach ($field['settings']['allowed_values'] as $tree) {
if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
if ($terms = taxonomy_get_tree($vocabulary->vid, 0, 2)) {
$terms = content_taxonomy_get_terms($field, $vocabulary, 0, 2);
if (!empty($terms) && is_array($terms)) {
$current_group_term = NULL;
foreach ($terms as $term) {
if ($term->depth == 0) {

View File

@@ -10,9 +10,9 @@ files[] = includes/content_taxonomy_autocomplete_moderated_terms.inc
; Information added by drupal.org packaging script on 2013-02-13
version = "7.x-1.0-beta2"
; Information added by Drupal.org packaging script on 2016-03-22
version = "7.x-1.0-rc1"
core = "7.x"
project = "content_taxonomy"
datestamp = "1360767812"
datestamp = "1458667740"

View File

@@ -10,10 +10,25 @@ function content_taxonomy_autocomplete_field_widget_info_alter(&$info) {
);
$info['taxonomy_autocomplete']['settings'] += $ct_settings;
// Add this to the Active Tags as well, if enabled.
if (isset($info['active_tags']['settings'])) {
$info['active_tags']['settings'] += $ct_settings;
}
// Add this to the autocomplete deluxe as well, if enabled.
if (isset($info['autocomplete_deluxe_taxonomy']['settings'])) {
$info['autocomplete_deluxe_taxonomy']['settings'] += $ct_settings;
}
// Add this to the entityreference autocomplete as well, if enabled.
if (isset($info['entityreference_autocomplete']['settings'])) {
$info['entityreference_autocomplete']['settings'] += $ct_settings;
}
// Add this to the entityreference autocomplete (tags) as well, if enabled.
if (isset($info['entityreference_autocomplete_tags']['settings'])) {
$info['entityreference_autocomplete_tags']['settings'] += $ct_settings;
}
}
/**
@@ -22,7 +37,11 @@ function content_taxonomy_autocomplete_field_widget_info_alter(&$info) {
function content_taxonomy_autocomplete_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
$field = $form['#field'];
$instance = $form['#instance'];
if ($instance['widget']['type'] == 'taxonomy_autocomplete' || $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy') {
if ($instance['widget']['type'] == 'taxonomy_autocomplete'
|| $instance['widget']['type'] == 'active_tags_taxonomy_autocomplete'
|| $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy'
|| $instance['widget']['type'] == 'entityreference_autocomplete'
|| $instance['widget']['type'] == 'entityreference_autocomplete_tags') {
// Add a setting form for validating new terms.
$options = array(
'allow' => t('Allow and insert new terms'),
@@ -39,7 +58,14 @@ function content_taxonomy_autocomplete_form_field_ui_field_edit_form_alter(&$for
}
// Show form for second vocabulary.
if (isset($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms']) && $instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'] == 'moderate') {
if (($instance['widget']['type'] == 'taxonomy_autocomplete'
|| $instance['widget']['type'] == 'active_tags_taxonomy_autocomplete'
|| $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy'
|| $instance['widget']['type'] == 'entityreference_autocomplete'
|| $instance['widget']['type'] == 'entityreference_autocomplete_tags')
&& isset($form[$instance['field_name']])
&& isset($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'])) {
// Initialize settings, if not set.
if (!isset($field['settings']['allowed_values'][1])) {
$field['settings']['allowed_values'][1] = array(
@@ -83,8 +109,11 @@ function content_taxonomy_autocomplete_field_attach_form($entity_type, $entity,
// Add validation function to taxonomy_autocompletes, if necessary.
$instances = field_info_instances($form['#entity_type'], $form['#bundle']);
foreach ($instances as $instance) {
if (($instance['widget']['type'] == 'taxonomy_autocomplete' || $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy')
&& isset($form[$instance['field_name']])
if (($instance['widget']['type'] == 'taxonomy_autocomplete'
|| $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy'
|| $instance['widget']['type'] == 'entityreference_autocomplete'
|| $instance['widget']['type'] == 'entityreference_autocomplete_tags')
&& isset($form[$instance['field_name']])
&& isset($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'])) {
// Use the language that is used in this form (which doesn't necessarily
@@ -105,12 +134,14 @@ function content_taxonomy_autocomplete_field_attach_form($entity_type, $entity,
*/
function content_taxonomy_autocomplete_validate_deny_new_terms($element, &$form_state, $form) {
$values = $form_state['values'];
foreach ($element['#array_parents'] as $parent) {
$values = $values[$parent];
if (!empty($element['#array_parents'])) {
foreach ($element['#array_parents'] as $parent) {
$values = $values[$parent];
}
}
foreach ($values as $delta => $value) {
if ($value['tid'] == 'autocreate') {
form_error($element, t('%name: new terms are not allowed. Please choose from the given list.', array('%name' => $element['#title'])));
if (isset($value['tid']) && $value['tid'] == 'autocreate') {
form_error($element, t('%name: new terms are not allowed. Please choose from the suggested options.', array('%name' => $element['#title'])));
}
}
}

View File

@@ -0,0 +1,15 @@
name = Content Taxonomy Entity Translations
description = Adds support for terms that are translated via the Entity Translation and Title module.
core = 7.x
package = Fields
dependencies[] = content_taxonomy
dependencies[] = entity_translation
dependencies[] = title
; Information added by Drupal.org packaging script on 2016-03-22
version = "7.x-1.0-rc1"
core = "7.x"
project = "content_taxonomy"
datestamp = "1458667740"

View File

@@ -0,0 +1,404 @@
<?php
/**
* @file
* Entity Translation integration for taxonomy terms.
*/
/**
* Implements hook_content_taxonomy_tree_callback_alter().
*/
function content_taxonomy_et_content_taxonomy_tree_callback_alter(&$tree_callback, $field, $vocabulary) {
// Checks whether the Entity Translation mode with the title field is enabled,
// if so, replace the tree callback with our custom language specific
// implementation.
if (title_field_replacement_enabled('taxonomy_term', $vocabulary->machine_name, 'name')) {
$tree_callback = 'content_taxonomy_et_get_tree';
}
}
/**
* Implements hook_menu_alter().
*/
function content_taxonomy_et_menu_alter(&$items) {
// Localize autocompletes.
$items['taxonomy/autocomplete']['page callback'] = 'content_taxonomy_et_autocomplete';
if (isset($items['autocomplete_deluxe/taxonomy'])) {
$items['autocomplete_deluxe/taxonomy']['page callback'] = 'content_taxonomy_et_autocomplete_deluxe';
}
}
/**
* Implements hook_field_widget_form_alter().
*/
function content_taxonomy_et_field_widget_form_alter(&$element, &$form_state, $context) {
// Change validation callback for autocompletes in order to fix the
// retrieving of terms in the right language.
if (in_array($context['instance']['widget']['type'], array('taxonomy_autocomplete', 'autocomplete_deluxe_taxonomy'))) {
foreach ($element['#element_validate'] as $key => $validate_callback) {
if ($validate_callback == 'taxonomy_autocomplete_validate') {
$element['#element_validate'][$key] = 'content_taxonomy_et_autocomplete_validate';
break;
}
}
}
}
/**
* Replacement for taxonomy_get_tree().
*
* Exchanges the term name property with the title field value in the current
* language.
*/
function content_taxonomy_et_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE) {
global $language;
$children = &drupal_static(__FUNCTION__, array());
$parents = &drupal_static(__FUNCTION__ . ':parents', array());
$terms = &drupal_static(__FUNCTION__ . ':terms', array());
// We cache trees, so it's not CPU-intensive to call taxonomy_get_tree() on a
// term and its children, too.
if (!isset($children[$vid])) {
$children[$vid] = array();
$parents[$vid] = array();
$terms[$vid] = array();
$query = db_select('taxonomy_term_data', 't');
$query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
$query->leftJoin('field_data_name_field', 'fd', 'fd.entity_id = t.tid AND fd.entity_type = :type AND fd.language = :language',
array(':type' => 'taxonomy_term', ':language' => $language->language));
$result = $query
->addTag('translatable')
->addTag('term_access')
->fields('t')
->fields('h', array('parent'))
->fields('fd', array('name_field_value'))
->condition('t.vid', $vid)
->orderBy('t.weight')
->orderBy('t.name')
->execute();
foreach ($result as $term) {
$children[$vid][$term->parent][] = $term->tid;
$parents[$vid][$term->tid][] = $term->parent;
$terms[$vid][$term->tid] = $term;
}
}
// Load full entities, if necessary. The entity controller statically
// caches the results.
if ($load_entities) {
$term_entities = taxonomy_term_load_multiple(array_keys($terms[$vid]));
}
$max_depth = (!isset($max_depth)) ? count($children[$vid]) : $max_depth;
$tree = array();
// Keeps track of the parents we have to process, the last entry is used
// for the next processing step.
$process_parents = array();
$process_parents[] = $parent;
// Loops over the parent terms and adds its children to the tree array.
// Uses a loop instead of a recursion, because it's more efficient.
while (count($process_parents)) {
$parent = array_pop($process_parents);
// The number of parents determines the current depth.
$depth = count($process_parents);
if ($max_depth > $depth && !empty($children[$vid][$parent])) {
$has_children = FALSE;
$child = current($children[$vid][$parent]);
do {
if (empty($child)) {
break;
}
$term = $load_entities ? $term_entities[$child] : $terms[$vid][$child];
if (isset($parents[$vid][$term->tid])) {
// Clone the term so that the depth attribute remains correct
// in the event of multiple parents.
$term = clone $term;
}
// Use translation if it exists in the name property.
if (!empty($term->name_field_value)) {
$term->name = $term->name_field_value;
}
$term->depth = $depth;
unset($term->parent);
$term->parents = $parents[$vid][$term->tid];
$tree[] = $term;
if (!empty($children[$vid][$term->tid])) {
$has_children = TRUE;
// We have to continue with this parent later.
$process_parents[] = $parent;
// Use the current term as parent for the next iteration.
$process_parents[] = $term->tid;
// Reset pointers for child lists because we step in there more often
// with multi parents.
reset($children[$vid][$term->tid]);
// Move pointer so that we get the correct term the next time.
next($children[$vid][$parent]);
break;
}
} while ($child = next($children[$vid][$parent]));
if (!$has_children) {
// We processed all terms in this hierarchy-level, reset pointer
// so that this function works the next time it gets called.
reset($children[$vid][$parent]);
}
}
}
return $tree;
}
/**
* Replacement for form validate handler taxonomy_autocomplete_validate().
*
* Uses content_taxonomy_et_get_first_possible_term() to retrieve the right term
* in the right language, instead of term_load_multiple().
*/
function content_taxonomy_et_autocomplete_validate($element, &$form_state) {
// Autocomplete widgets do not send their tids in the form, so we must detect
// them here and process them independently.
$value = array();
if ($tags = $element['#value']) {
// Collect candidate vocabularies.
$field = field_widget_field($element, $form_state);
$vocabularies = array();
foreach ($field['settings']['allowed_values'] as $tree) {
if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
$vocabularies[$vocabulary->vid] = $vocabulary;
}
}
// Translate term names into actual terms.
$typed_terms = drupal_explode_tags($tags);
foreach ($typed_terms as $typed_term) {
// See if the term exists in the chosen vocabulary and return the tid;
// otherwise, create a new 'autocreate' term for insert/update.
$term = content_taxonomy_et_get_first_possible_term(trim($typed_term), array_keys($vocabularies));
if (!$term) {
$vocabulary = reset($vocabularies);
$term = array(
'tid' => 'autocreate',
'vid' => $vocabulary->vid,
'name' => $typed_term,
'vocabulary_machine_name' => $vocabulary->machine_name,
);
}
$value[] = (array)$term;
}
}
form_set_value($element, $value, $form_state);
}
/**
* Replacement for taxonomy_autocomplete().
*
* Adds an additional left join to the translatable title field.
*/
function content_taxonomy_et_autocomplete($field_name = '', $tags_typed = '') {
global $language;
// If the request has a '/' in the search text, then the menu system will have
// split it into multiple arguments, recover the intended $tags_typed.
$args = func_get_args();
// Shift off the $field_name argument.
array_shift($args);
$tags_typed = implode('/', $args);
// Make sure the field exists and is a taxonomy field.
if (!($field = field_info_field($field_name)) || $field['type'] !== 'taxonomy_term_reference') {
// Error string. The JavaScript handler will realize this is not JSON and
// will display it as debugging information.
print t('Taxonomy field @field_name not found.', array('@field_name' => $field_name));
exit;
}
// The user enters a comma-separated list of tags. We only autocomplete the last tag.
$tags_typed = drupal_explode_tags($tags_typed);
$tag_last = drupal_strtolower(array_pop($tags_typed));
$term_matches = array();
if ($tag_last != '') {
// Part of the criteria for the query come from the field's own settings.
$vids = array();
$vocabularies = taxonomy_vocabulary_get_names();
foreach ($field['settings']['allowed_values'] as $tree) {
$vids[] = $vocabularies[$tree['vocabulary']]->vid;
}
$query = db_select('taxonomy_term_data', 't');
$query->addTag('translatable');
$query->addTag('term_access');
$query->leftJoin('field_data_name_field', 'fd', 'fd.entity_id = t.tid AND fd.entity_type = :type AND fd.language = :language',
array(':type' => 'taxonomy_term', ':language' => $language->language));
// Do not select already entered terms.
if (!empty($tags_typed)) {
$query->condition('t.name', $tags_typed, 'NOT IN');
}
// Select rows that match by term name.
$tags_return = $query
->fields('t', array('tid', 'name'))
->fields('fd', array('name_field_value'))
->condition('t.vid', $vids)
->condition(db_or()->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')->condition('fd.name_field_value', '%' . db_like($tag_last) . '%', 'LIKE'))
->range(0, 10)
->execute();
$prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : '';
foreach ($tags_return as $record) {
$name = !empty($record->name_field_value) ? $record->name_field_value : $record->name;
$n = $name;
// Term names containing commas or quotes must be wrapped in quotes.
if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
$n = '"' . str_replace('"', '""', $name) . '"';
}
$term_matches[$prefix . $n] = check_plain($name);
}
}
drupal_json_output($term_matches);
}
/**
* Replacement for taxonomy_autocomplete_deluxe().
*
* Adds an additional left join to the translatable title field.
*
* @todo
* Merge with content_taxonomy_et_autocomplete().
*/
function content_taxonomy_et_autocomplete_deluxe($field_name, $tags_typed = '', $limit = 10) {
global $language;
$field = field_info_field($field_name);
$use_synonyms = !empty($_GET['synonyms']);
// The user enters a comma-separated list of tags. We only autocomplete the last tag.
$tags_typed = drupal_explode_tags($tags_typed);
$tag_last = drupal_strtolower(array_pop($tags_typed));
$matches = array();
// Part of the criteria for the query come from the field's own settings.
$vids = array();
$vocabularies = taxonomy_vocabulary_get_names();
foreach ($field['settings']['allowed_values'] as $tree) {
// If the content taxonomy setting content_taxonomy_ignore_in_suggestions
// is set, then the vocabulary is ignored.
if (empty($tree['content_taxonomy_ignore_in_suggestions'])) {
$vids[] = $vocabularies[$tree['vocabulary']]->vid;
}
}
$query = db_select('taxonomy_term_data', 't');
$query->addTag('translatable');
$query->addTag('term_access');
$query->leftJoin('field_data_name_field', 'fd', 'fd.entity_id = t.tid AND fd.entity_type = :type AND fd.language = :language',
array(':type' => 'taxonomy_term', ':language' => $language->language));
if (module_exists('synonyms') && !empty($use_synonyms)) {
$query->leftJoin('field_data_synonyms_synonym', 'fdss', 'fdss.entity_id = t.tid');
}
if ($tag_last != '') {
// Do not select already entered terms.
if (!empty($tags_typed)) {
$query->condition('t.name', $tags_typed, 'NOT IN');
}
// Select rows that match by term name.
$query
->fields('t', array('tid', 'name'))
->fields('fd', array('name_field_value'))
->condition('t.vid', $vids);
if (module_exists('synonyms') && !empty($use_synonyms)) {
$or = db_or();
$or->condition('fdss.synonyms_synonym_value', '%' . db_like($tag_last) . '%', 'LIKE');
$or->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE');
$or->condition('fd.name_field_value', '%' . db_like($tag_last) . '%', 'LIKE');
$query->condition($or);
}
else {
$query->condition(db_or()->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')->condition('fd.name_field_value', '%' . db_like($tag_last) . '%', 'LIKE'));
}
if (isset($limit) && $limit > 0) {
$query->range(0, $limit);
}
$tags_return = $query->execute();
}
else {
$query
->fields('t', array('tid', 'name'))
->fields('fd', array('name_field_value'))
->condition('t.vid', $vids);
if (isset($limit) && $limit > 0) {
$query->range(0, $limit);
}
$tags_return = $query->execute();
}
$prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : '';
$term_matches = array();
foreach ($tags_return as $record) {
$name = !empty($record->name_field_value) ? $record->name_field_value : $record->name;
$n = $name;
// Term names containing commas or quotes must be wrapped in quotes.
if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
$n = '"' . str_replace('"', '""', $name) . '"';
}
$term_matches[$prefix . $n] = check_plain($name);
}
drupal_json_output($term_matches);
}
/**
* Helper function that retrieves the first possible term object for a given
* term name and and array of vocabulary ids.
*
* Used in content_taxonomy_et_autocomplete_validate().
*/
function content_taxonomy_et_get_first_possible_term($term_name, $vids) {
global $language;
// EFQ does not work here, as we do not have OR condition possibilities.
$query = db_select('taxonomy_term_data', 't');
$query->addTag('translatable');
$query->addTag('term_access');
$query->leftJoin('field_data_name_field', 'fd', 'fd.entity_id = t.tid AND fd.entity_type = :type AND fd.language = :language',
array(':type' => 'taxonomy_term', ':language' => $language->language));
$query->fields('t', array('tid'))
->condition('t.vid', $vids, 'IN')
->condition(db_or()->condition('t.name', $term_name)->condition('fd.name_field_value', $term_name))
->orderBy('t.tid', 'ASC')
->execute();
$first_tid = $query->execute()->fetchColumn();
if (!empty($first_tid)) {
$term = taxonomy_term_load($first_tid);
return $term;
}
return FALSE;
}

View File

@@ -1,5 +1,5 @@
name = Content Taxonomy Migrate
description = Migration from Content Taxonomy to Term Reference Fields
description = Migration from Content Taxonomy to Term Reference fields.
core = 7.x
package = Fields
@@ -7,11 +7,9 @@ package = Fields
dependencies[] = taxonomy
dependencies[] = content_migrate
; Information added by drupal.org packaging script on 2013-02-13
version = "7.x-1.0-beta2"
; Information added by Drupal.org packaging script on 2016-03-22
version = "7.x-1.0-rc1"
core = "7.x"
project = "content_taxonomy"
datestamp = "1360767812"
datestamp = "1458667740"

View File

@@ -1,11 +1,18 @@
<?php
/**
* @file
*
*/
/**
* Implements hook_content_migrate_field_alter().
*/
function content_taxonomy_migrate_content_migrate_field_alter(&$field_value, $instance_value) {
if ($field_value['type'] == 'content_taxonomy') {
$field_value['type'] = 'taxonomy_term_reference';
$field_value['module'] = 'taxonomy';
// transform field settings
// Transform field settings.
$old_settings = $field_value['settings'];
$vocabulary = taxonomy_vocabulary_load($old_settings['vid']);
$field_value['settings'] = array();
@@ -14,38 +21,102 @@ function content_taxonomy_migrate_content_migrate_field_alter(&$field_value, $in
$field_value['settings']['allowed_values'][0]['parent'] = $old_settings['parent'];
}
}
/**
* Implements hook_content_migrate_instance_alter().
*/
function content_taxonomy_migrate_content_migrate_instance_alter(&$instance_value, $field_value) {
// Only work on content_taxonomy fields.
if ($field_value['type'] != 'content_taxonomy') {
return;
}
// Track whether fields are managed by this module.
$fix_this_instance = FALSE;
// Fix the widget.
if ($instance_value['widget_type'] == "content_taxonomy_autocomplete") {
$fix_this_instance = TRUE;
$instance_value['widget_type'] = 'taxonomy_autocomplete';
$instance_value['widget']['type'] = 'taxonomy_autocomplete';
$instance_value['widget']['module'] = 'taxonomy';
}
else if ($instance_value['widget_type'] == "content_taxonomy_options" || $instance_value['widget_type'] == "content_taxonomy_tree") {
elseif ($instance_value['widget_type'] == "content_taxonomy_options" || $instance_value['widget_type'] == "content_taxonomy_tree") {
$fix_this_instance = TRUE;
$instance_value['widget_type'] = 'options_buttons';
$instance_value['widget']['type'] = 'options_buttons';
$instance_value['widget']['module'] = 'options';
}
else if ($instance_value['widget_type'] == "content_taxonomy_select" || $instance_value['widget_type'] == 'content_taxonomy_hs') {
elseif ($instance_value['widget_type'] == "content_taxonomy_select" || $instance_value['widget_type'] == 'content_taxonomy_hs') {
$fix_this_instance = TRUE;
$instance_value['widget_type'] = 'options_select';
$instance_value['widget']['type'] = 'options_select';
$instance_value['widget']['module'] = 'options';
}
// fix formatter
// Fix the formatter.
foreach ($instance_value['display'] as $context => $settings) {
if ($instance_value['display'][$context]['type'] == 'default') {
$fix_this_instance = TRUE;
$instance_value['display'][$context]['type'] = 'taxonomy_term_reference_plain';
}
else if ($instance_value['display'][$context]['type'] == 'link') {
elseif ($instance_value['display'][$context]['type'] == 'link') {
$fix_this_instance = TRUE;
$instance_value['display'][$context]['type'] = 'taxonomy_term_reference_link';
}
if ($instance_value['display'][$context]['module'] == 'content_taxonomy_options') {
$fix_this_instance = TRUE;
$instance_value['display'][$context]['module'] = 'options';
}
}
// Fix the defaults.
if ($fix_this_instance && !empty($instance_value['default_value'])) {
foreach ($instance_value['default_value'] as $key => $default) {
// Need to check isset() and is_null() because the value could be NULL.
if (isset($instance_value['default_value'][$key]['value']) || is_null($instance_value['default_value'][$key]['value'])) {
// Remove any empty 'value' strings.
if (empty($instance_value['default_value'][$key]['value'])) {
unset($instance_value['default_value'][$key]['value']);
}
// Rename the 'value' string as 'tid'.
else {
$instance_value['default_value'][$key]['tid'] = $instance_value['default_value'][$key]['value'];
unset($instance_value['default_value'][$key]['value']);
}
// Remove a junk value carried over from D6.
if (isset($instance_value['default_value'][$key]['_error_element'])) {
unset($instance_value['default_value'][$key]['_error_element']);
$updated = TRUE;
}
// If the array is empty, just remove it.
if (empty($instance_value['default_value'][$key])) {
unset($instance_value['default_value'][$key]);
}
}
// There are no default values left.
if (empty($instance_value['default_value'])) {
$instance_value['default_value'] = NULL;
}
}
}
}
/**
* Implements hook_content_migrate_data_record_alter().
*/
function content_taxonomy_migrate_content_migrate_data_record_alter(&$record, $field) {
// fill the taxonomy_index
if ($field['type'] == 'taxonomy_term_reference') {
// Copy field_FIELD_NAME_value (D6) to field_FIELD_NAME_tid (D7).
if (isset($record[$field['field_name'] . '_value']) && !isset($record[$field['field_name'] . '_tid'])) {
$record[$field['field_name'] . '_tid'] = $record[$field['field_name'] . '_value'];
}
// Fill the taxonomy_index.
if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $record['entity_type'] == 'node') {
if (isset($record[$field['field_name'] . "_tid"]) && $record[$field['field_name'] . "_tid"]) {
$entity = node_load($record['entity_id']);
@@ -61,4 +132,4 @@ function content_taxonomy_migrate_content_migrate_data_record_alter(&$record, $f
}
}
}
}
}