updated webform, webform_localization, profile2, term_merge, search_api_saved_pages, rules, redirect, overide_node_options

This commit is contained in:
2019-05-13 18:47:27 +02:00
parent 58cd990c8c
commit 9adc940a67
281 changed files with 28658 additions and 7138 deletions

View File

@@ -23,11 +23,11 @@ Currently, the module only acts on:
The term merging may happen in 2 flavors. You can either manually indicate what
terms should be merged or you can use duplicate suggestion tool for this
purpose. This tool intends to scan your vocabulary and detect such terms that
purpose. This tool intends to scan your vocabulary and to detect such terms that
are likely to be duplicates. You will then only review the list of suggested
duplicates and will schedule for merging only those that actually are
duplicates. The heuristics through which duplicate tool determines potential
synonymous terms are made to be extendible by other modules. Refer to Term Merge
synonymous terms are made to be extensible by other modules. Refer to Term Merge
advanced help if you want to write a custom one, though the module itself ships
with the following heuristics:
* search by the same name

View File

@@ -1,4 +1,4 @@
Terme merge module, as its title well implies it, allows administrators to merge terms one into another.
Term merge module, as its title well implies it, allows administrators to merge terms one into another.
When using taxonomy for free tagging purposes, it's easy to end up with several terms having the same meaning. This may be due to spelling errors, or different users simply making up synonymous terms as they go.

View File

@@ -1,8 +1,8 @@
If you want to define your own custom logic of what terms are to be considered possible duplicates and then to plug this custom logic into all Term Merge machinnery, then this page is for you.
If you want to define your own custom logic of what terms are to be considered possible duplicates and then to plug this custom logic into all Term Merge machinery, then this page is for you.
Duplicate detection heuristics are implemented through cTools plugins. If you have not worked with cTools plugins before, we highly recommend you to read documentation about them, such as <a href="&topic:ctools/plugins-implementing&">this one</a>.
Term Merge module defines the cTools plugin type of <em>duplicate_suggestion</em>. This plugin type expects the following properties: <ul>
Term Merge module defines the cTools plugin type of <em>duplicate_suggestion</em>. This plugin type contains the following properties: <ul>
<li><b>title</b>: (string) Human readable translated title of your duplicate suggestion logic. The title will be inserted into the UI of duplicate tool whereafter you can enable it for duplicate detection</li>
<li><b>description</b>: (string) [optional] Human readable translated description of how your duplicate suggestion functions. Try including here description of the logic.</li>
<li><b>hash callback</b>: (string) Name of a function that hashes terms. Terms with the same hash will be considered possible duplicates. The function will receive the following input arguments: <ol>
@@ -11,6 +11,6 @@ Term Merge module defines the cTools plugin type of <em>duplicate_suggestion</em
<li><b>weight</b>: (int) [optional] Weight of your duplicate suggestion. On the duplicate tool UI the duplicate suggestions are displayed in the order according to their weights.</li>
</ul>
Having that said, core of your duplicate suggestion plugin should be the hash function. You can look at the exaples of hash function inside of Term Merge module, just study the <em>term_merge/plugins/duplicate_suggestion/*.inc</em> files. In fact your hash function does not necessarily have to be complicated to yield reasonable duplicate suggestions.
Having that said, core of your duplicate suggestion plugin should be the hash function. You can look at the examples of hash function inside of Term Merge module, just study the <em>term_merge/plugins/duplicate_suggestion/*.inc</em> files. In fact your hash function does not necessarily have to be complicated to yield reasonable duplicate suggestions.
Good luck coding! And if you feel like you have coded a duplicate suggestion that others might benefit from, please, be kind to open an issue against Term Merge module and share your duplicate suggestion there. I thank you beforehand on behalf of all the community!

View File

@@ -0,0 +1,50 @@
<?php
/**
* @file
* Definition of EntityReferenceTermMergeSynonymsBehavior class.
*/
/**
* Synonyms "term_merge" behavior for 'entityreference' field type.
*/
class EntityReferenceTermMergeSynonymsBehavior extends EntityReferenceSynonymsBehavior implements TermMergeSynonymsBehavior {
/**
* Add an entity as a synonym into another entity.
*
* Basically this method should be called when you want to add some entity as
* a synonym to another entity (for example when you merge one entity into
* another and besides merging want to add synonym of the merged entity into
* the trunk entity). You should update $trunk_entity in such a way that it
* holds $synonym_entity as a synonym (it all depends on how data is stored in
* your behavior implementation, but probably you will store entity label or
* its ID as you cannot literally store an entity inside of another entity).
* If entity of type $synonym_entity_type cannot be converted into a format
* expected by your behavior implementation, just do nothing.
*
* @param object $trunk_entity
* Entity into which another one should be added as synonym
* @param object $synonym_entity
* Fully loaded entity object which has to be added as synonym
* @param string $synonym_entity_type
* Entity type of $synonym_entity
*/
public function mergeTerm($trunk_entity, $synonym_entity, $synonym_entity_type) {
// Firstly validating that this entity reference is able to reference that
// type of entity.
$expected_synonym_entity_type = $this->field['settings']['target_type'];
$items = $this->entityItems($trunk_entity);
if ($expected_synonym_entity_type != $synonym_entity_type) {
return;
}
$synonym_entity_id = entity_extract_ids($synonym_entity_type, $synonym_entity);
$synonym_entity_id = $synonym_entity_id[0];
$items[] = array(
'target_id' => $synonym_entity_id,
);
$trunk_entity->{$this->field['field_name']}[LANGUAGE_NONE] = $this->uniqueItems($items, array('target_id'));
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* @file
* Definition of TaxonomyTermReferenceTermMergeSynonymsBehavior class.
*/
/**
* Synonyms "term_merge" behavior for 'taxonomy term reference' field type.
*/
class TaxonomyTermReferenceTermMergeSynonymsBehavior extends TaxonomySynonymsBehavior implements TermMergeSynonymsBehavior {
/**
* Add an entity as a synonym into another entity.
*
* Basically this method should be called when you want to add some entity as
* a synonym to another entity (for example when you merge one entity into
* another and besides merging want to add synonym of the merged entity into
* the trunk entity). You should update $trunk_entity in such a way that it
* holds $synonym_entity as a synonym (it all depends on how data is stored in
* your behavior implementation, but probably you will store entity label or
* its ID as you cannot literally store an entity inside of another entity).
* If entity of type $synonym_entity_type cannot be converted into a format
* expected by your behavior implementation, just do nothing.
*
* @param object $trunk_entity
* Entity into which another one should be added as synonym
* @param object $synonym_entity
* Fully loaded entity object which has to be added as synonym
* @param string $synonym_entity_type
* Entity type of $synonym_entity
*/
public function mergeTerm($trunk_entity, $synonym_entity, $synonym_entity_type) {
// Taxonomy term reference supports only referencing of entity types
// 'taxonomy_term'.. duh.
if ($synonym_entity_type != 'taxonomy_term') {
return;
}
$items = $this->entityItems($trunk_entity);
// Checking that $field is configured to reference the vocabulary of
// $synonym_entity term.
$is_allowed = FALSE;
foreach ($this->field['settings']['allowed_values'] as $setting) {
if ($synonym_entity->vocabulary_machine_name == $setting['vocabulary']) {
if ($setting['parent'] == 0) {
// No need to check parent property as there is no limitation on it.
$is_allowed = TRUE;
break;
}
else {
foreach (taxonomy_get_parents_all($synonym_entity->tid) as $parent) {
if ($parent->tid == $setting['parent']) {
$is_allowed = TRUE;
break(2);
}
}
}
}
}
if (!$is_allowed) {
// Synonym term is from a vocabulary that is not expected by this field,
// or under unexpected parent.
return;
}
$items[] = array(
'tid' => $synonym_entity->tid,
);
$trunk_entity->{$this->field['field_name']}[LANGUAGE_NONE] = $this->uniqueItems($items, array('tid'));
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* @file
* Interface of synonyms behaviors for merging terms.
*/
/**
* Interface for merging one term into another.
*/
interface TermMergeSynonymsBehavior extends SynonymsBehavior {
/**
* Add an entity as a synonym into another entity.
*
* Basically this method should be called when you want to add some entity as
* a synonym to another entity (for example when you merge one entity into
* another and besides merging want to add synonym of the merged entity into
* the trunk entity). You should update $trunk_entity in such a way that it
* holds $synonym_entity as a synonym (it all depends on how data is stored in
* your behavior implementation, but probably you will store entity label or
* its ID as you cannot literally store an entity inside of another entity).
* If entity of type $synonym_entity_type cannot be converted into a format
* expected by your behavior implementation, just do nothing.
*
* @param object $trunk_entity
* Entity into which another one should be added as synonym
* @param object $synonym_entity
* Fully loaded entity object which has to be added as synonym
* @param string $synonym_entity_type
* Entity type of $synonym_entity
*/
public function mergeTerm($trunk_entity, $synonym_entity, $synonym_entity_type);
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* @file
* Definition of TextTermMergeSynonymsBehavior class.
*/
/**
* Synonyms "term_merge" behavior for 'text' field type.
*/
class TextTermMergeSynonymsBehavior extends TextSynonymsBehavior implements TermMergeSynonymsBehavior {
/**
* Add an entity as a synonym into another entity.
*
* Basically this method should be called when you want to add some entity as
* a synonym to another entity (for example when you merge one entity into
* another and besides merging want to add synonym of the merged entity into
* the trunk entity). You should update $trunk_entity in such a way that it
* holds $synonym_entity as a synonym (it all depends on how data is stored in
* your behavior implementation, but probably you will store entity label or
* its ID as you cannot literally store an entity inside of another entity).
* If entity of type $synonym_entity_type cannot be converted into a format
* expected by your behavior implementation, just do nothing.
*
* @param object $trunk_entity
* Entity into which another one should be added as synonym
* @param object $synonym_entity
* Fully loaded entity object which has to be added as synonym
* @param string $synonym_entity_type
* Entity type of $synonym_entity
*/
public function mergeTerm($trunk_entity, $synonym_entity, $synonym_entity_type) {
$synonym = entity_label($synonym_entity_type, $synonym_entity);
switch ($this->field['type']) {
case 'text':
break;
// We add synonyms for numbers only if $synonym is a number.
case 'number_integer':
case 'number_float':
case 'number_decimal':
if (!is_numeric($synonym)) {
return;
}
break;
}
$items = $this->entityItems($trunk_entity);
$items[] = array(
'value' => $synonym,
);
$trunk_entity->{$this->field['field_name']}[LANGUAGE_NONE] = $this->uniqueItems($items, array('value'));
}
}

View File

@@ -0,0 +1,12 @@
<?php
/**
* @file
* Plugin definition for term merge synonyms behavior.
*/
$plugin = array(
'title' => t('Term merge'),
'description' => t('Merge a term into a field of another.'),
'interface' => 'TermMergeSynonymsBehavior',
);

View File

@@ -23,6 +23,6 @@ function hook_term_merge($term_trunk, $term_branch, $context) {
// UPDATE {my_table}
// SET term_tid = $term_trunk->tid
// WHERE term_tid = $term_branch->tid
// Or do anything else that you own logic requires when merging of 2 terms
// Or do anything else that your own logic requires when merging of 2 terms
// happens.
}

View File

@@ -35,8 +35,8 @@
* module. Use constant TERM_MERGE_NO_REDIRECT to denote not creating any
* HTTP redirect. Note: this parameter requires Redirect module enabled,
* otherwise it will be disregarded
* - synonyms: (array) Array of field names of trunk term into which branch
* terms should be added as synonyms (until each field's cardinality limit
* - synonyms: (string) Optional field name of trunk term into which branch
* terms should be added as synonyms (until field's cardinality limit
* is reached). Note: this parameter requires Synonyms module enabled,
* otherwise it will be disregarded
* - step: (int) How many term branches to merge per script run in batch. If
@@ -56,7 +56,7 @@ function _term_merge_batch_process($term_branch, $term_trunk, $merge_settings, &
'merge_fields' => array(),
'keep_only_unique' => TRUE,
'redirect' => TERM_MERGE_NO_REDIRECT,
'synonyms' => array(),
'synonyms' => NULL,
'step' => 40,
);

View File

@@ -5,13 +5,23 @@ core = 7.x
files[] = term_merge.test
files[] = includes/TermMergeSynonymsBehavior.interface.inc
files[] = includes/TextTermMergeSynonymsBehavior.class.inc
files[] = includes/TaxonomyTermReferenceTermMergeSynonymsBehavior.class.inc
files[] = includes/EntityReferenceTermMergeSynonymsBehavior.class.inc
dependencies[] = taxonomy
dependencies[] = entity
dependencies[] = ctools
; Information added by Drupal.org packaging script on 2015-11-29
version = "7.x-1.3"
test_dependencies[] = synonyms:synonyms
test_dependencies[] = entityreference:entityreference
test_dependencies[] = views:views
test_dependencies[] = redirect:redirect
; Information added by Drupal.org packaging script on 2017-03-30
version = "7.x-1.4"
core = "7.x"
project = "term_merge"
datestamp = "1448826550"
datestamp = "1490837287"

View File

@@ -119,10 +119,11 @@ function term_merge_permission() {
function term_merge_action_info() {
return array(
'term_merge_action' => array(
'type' => 'taxonomy',
'type' => 'taxonomy_term',
'label' => t('Merge term'),
'configurable' => TRUE,
'behavior' => array('changes_property'),
'behavior' => array('view_property'),
'pass rows' => TRUE,
),
);
}
@@ -168,9 +169,35 @@ function term_merge_ctools_plugin_directory($owner, $plugin_type) {
return 'plugins/' . $plugin_type;
}
break;
case 'synonyms':
switch ($plugin_type) {
case 'behavior':
return 'plugins/' . $plugin_type;
}
break;
}
}
/**
* Implements hook_synonyms_provider_field_behavior_implementation_info().
*/
function term_merge_synonyms_provider_field_behavior_implementation_info($behavior) {
switch ($behavior) {
case 'term_merge':
return array(
'number_integer' => 'TextTermMergeSynonymsBehavior',
'number_decimal' => 'TextTermMergeSynonymsBehavior',
'number_float' => 'TextTermMergeSynonymsBehavior',
'text' => 'TextTermMergeSynonymsBehavior',
'taxonomy_term_reference' => 'TaxonomyTermMergeSynonymsBehavior',
'entityreference' => 'EntityReferenceTermMergeSynonymsBehavior',
);
break;
}
return array();
}
/**
* Access callback for term merge action.
*
@@ -215,12 +242,32 @@ function term_merge_access($vocabulary = NULL, $term = NULL, $account = NULL) {
/**
* Generate the configuration form for action "Term merge".
*/
function term_merge_action_form($context) {
$form = array();
$form['displaimer'] = array(
'#markup' => '<b>' . t('Sorry, currently Term Merge action is not supported via user interface. Please, contact the maintainers at the official website if you need it enabled via user interface.') . '</b>',
);
function term_merge_action_form($context, &$form_state) {
$term_branch_value = isset($form_state['selection']) && is_array($form_state['selection']) ? $form_state['selection'] : array();
$vocabulary = FALSE;
if (!empty($term_branch_value)) {
$vocabulary = db_select('taxonomy_term_data', 't')
->fields('t', array('vid'))
->condition('tid', reset($term_branch_value))
->execute()
->fetchField();
$vocabulary = taxonomy_vocabulary_load($vocabulary);
}
if ($vocabulary) {
$form = array();
module_load_include('inc', 'term_merge', 'term_merge.pages');
term_merge_form_base($form, $form_state, $vocabulary, $term_branch_value);
// The "step" merge parameter does not make sense here, since the batch will
// be invoked out of Term Merge scope.
$form['step']['#access'] = FALSE;
}
else {
$form['vocabulary_missing'] = array(
'#markup' => '<b>' . t('Oups, something does not seem to go right. Term merge module cannot determine within which vocabulary merge is about to happen. You might want to report it to the <a href="@url">Term Merge issue queue</a>.', array(
'@url' => 'https://www.drupal.org/project/issues/term_merge',
)) . '</b>',
);
}
return $form;
}
@@ -231,8 +278,9 @@ function term_merge_action_form($context) {
* Store information about configurable action.
*/
function term_merge_action_submit($form, &$form_state) {
// We don't have enabled UI for this action. It's just a dummy function.
return array();
return array(
'term_trunk' => $form_state['values']['term_trunk']['tid'],
) + term_merge_merge_options_submit($form, $form_state, $form);
}
/**
@@ -289,7 +337,7 @@ function term_merge_action($object, $context) {
}
if (!isset($context['synonyms']) || !module_exists('synonyms')) {
// This behavior requires Synonyms module installed and enabled.
$context['synonyms'] = array();
$context['synonyms'] = NULL;
}
// Calling a hook, this way we let whoever else to react and do his own extra
@@ -407,8 +455,8 @@ function term_merge_action($object, $context) {
}
// Adding term branch as synonym (Synonyms module integration).
foreach ($context['synonyms'] as $synonym_field) {
synonyms_add_entity_as_synonym($term_trunk, 'taxonomy_term', $synonym_field, $term_branch, 'taxonomy_term');
if ($context['synonyms']) {
term_merge_add_entity_as_synonym($term_trunk, 'taxonomy_term', $context['synonyms'], $term_branch, 'taxonomy_term');
}
// It turned out we gotta go tricky with the Redirect module. If we create
@@ -557,8 +605,8 @@ function term_merge_action($object, $context) {
* module. Use constant TERM_MERGE_NO_REDIRECT to denote not creating any
* HTTP redirect. Note: this parameter requires Redirect module enabled,
* otherwise it will be disregarded
* - synonyms: (array) Array of field names of trunk term into which branch
* terms should be added as synonyms (until each field's cardinality limit
* - synonyms: (string) Optional field name of trunk term into which branch
* terms should be added as synonyms (until field's cardinality limit
* is reached). Note: this parameter requires Synonyms module enabled,
* otherwise it will be disregarded
* - step: (int) How many term branches to merge per script run in batch. If
@@ -698,15 +746,26 @@ function term_merge_merge_options_elements($vocabulary) {
}
if (module_exists('synonyms')) {
$options = array();
foreach (synonyms_synonyms_fields($vocabulary) as $field_name) {
$options[$field_name] = $instances[$field_name]['label'];
$options = array('' => t('None'));
if (function_exists('synonyms_behavior_get')) {
// We are in Synonyms 7.x-1.5 and above.
foreach (synonyms_behavior_get('term_merge', 'taxonomy_term', $vocabulary->machine_name, TRUE) as $behavior_implementation) {
$options[$behavior_implementation['provider']] = $behavior_implementation['label'];
}
}
else {
// This is how we used to retrieve possible synonyms field prior to
// Synonyms 7.x-1.5. TODO: this should be removed at some point.
foreach (synonyms_synonyms_fields($vocabulary) as $field_name) {
$options[$field_name] = $instances[$field_name]['label'];
}
}
$form['synonyms'] = array(
'#type' => 'checkboxes',
'#type' => 'radios',
'#title' => t('Add as Synonyms'),
'#description' => t('Synonyms module allows you to add branch terms as synonyms into any of fields, enabled as sources of synonyms in vocabulary. Check the fields into which you would like to add branch terms as synonyms. <b>Important note:</b> the values will be added until the cardinality limit for the selected fields is reached.'),
'#description' => t('Synonyms module allows you to add branch terms as synonyms into any of fields, enabled as sources of synonyms in vocabulary. Check the field into which you would like to add branch terms as synonym. <b>Important note:</b> the values will be added until the cardinality limit for the selected field is reached.'),
'#options' => $options,
'#default_value' => '',
);
}
else {
@@ -756,7 +815,7 @@ function term_merge_merge_options_submit($merge_settings_element, &$form_state,
'merge_fields' => isset($merge_settings_element['merge_fields']['#value']) ? array_values(array_filter($merge_settings_element['merge_fields']['#value'])) : array(),
'keep_only_unique' => (bool) $merge_settings_element['keep_only_unique']['#value'],
'redirect' => isset($merge_settings_element['redirect']['#value']) ? $merge_settings_element['redirect']['#value'] : TERM_MERGE_NO_REDIRECT,
'synonyms' => isset($merge_settings_element['synonyms']['#value']) ? array_values(array_filter($merge_settings_element['synonyms']['#value'])) : array(),
'synonyms' => isset($merge_settings_element['synonyms']['#value']) ? $merge_settings_element['synonyms']['#value'] : NULL,
'step' => (int) $merge_settings_element['step']['#value'],
);
return $merge_settings;
@@ -794,3 +853,225 @@ function term_merge_fields_with_foreign_key($foreign_table, $foreign_column) {
return $result;
}
/**
* Allow to merge $synonym_entity as a synonym into $trunk_entity.
*
* Helpful function during various merging operations. It allows you to add a
* synonym (where possible) into one entity, which will represent another entity
* in the format expected by the field in which the synonym is being added.
*
* @param object $trunk_entity
* Fully loaded entity object in which the synonym is being added
* @param string $trunk_entity_type
* Entity type of $trunk_entity
* @param string $behavior_provider
* Machine name of behavior implementation into which the synonym entity
* should be merged
* @param object $synonym_entity
* Fully loaded entity object which will be added as a synonym
* @param string $synonym_entity_type
* Entity type of $synonym_entity
*
* @return bool
* Whether synonym has been successfully added
*/
function term_merge_add_entity_as_synonym($trunk_entity, $trunk_entity_type, $behavior_provider, $synonym_entity, $synonym_entity_type) {
if ($trunk_entity_type != 'taxonomy_term') {
// So far we only work with taxonomy terms.
return FALSE;
}
$bundle = entity_extract_ids($trunk_entity_type, $trunk_entity);
$bundle = $bundle[2];
$behavior_implementations = synonyms_behavior_get_all_enabled($trunk_entity_type, $bundle, $behavior_provider);
foreach ($behavior_implementations as $behavior_implementation) {
if ($behavior_implementation['behavior'] == 'term_merge') {
$behavior_implementation['object']->mergeTerm($trunk_entity, $synonym_entity, $synonym_entity_type);
taxonomy_term_save($trunk_entity);
return TRUE;
}
}
return FALSE;
}
/**
* Form API element validate function.
*
* Make sure term trunk is not among the selected term branches or their
* children.
*/
function term_merge_form_base_term_trunk_validate($element, &$form_state, $form) {
$prohibited_trunks = array();
foreach ($form['#term_merge_term_branch'] as $term_branch) {
$children = taxonomy_get_tree($form['#vocabulary']->vid, $term_branch);
$prohibited_trunks[] = $term_branch;
foreach ($children as $child) {
$prohibited_trunks[] = $child->tid;
}
}
$value = drupal_array_get_nested_value($form_state['values'], $element['#parents']);
if (in_array($value['tid'], $prohibited_trunks)) {
form_error($element['tid'], t('Trunk term cannot be one of the selected branch terms or their children.'));
}
}
/**
* Supportive function.
*
* Generate form elements for select widget for term trunk element of the term
* merge form.
*
* @param object $vocabulary
* Fully loaded taxonomy vocabulary object
* @param array $term_branch_value
* Array of Taxonomy term IDs that are nominated as branch terms.
*/
function term_merge_form_term_trunk_widget_select(&$form, &$form_state, $vocabulary, $term_branch_value) {
$tree = taxonomy_get_tree($vocabulary->vid);
$options = array();
foreach ($tree as $v) {
$options[$v->tid] = str_repeat('-', $v->depth) . $v->name . ' [tid: ' . $v->tid . ']';
}
if (!empty($term_branch_value)) {
// We have to make sure among term_trunk there is no term_branch or any of
// their children.
foreach ($term_branch_value as $v) {
unset($options[$v]);
foreach (taxonomy_get_tree($vocabulary->vid, $v) as $child) {
unset($options[$child->tid]);
}
}
}
else {
// Term branch has not been selected yet.
$options = array();
}
$form['term_trunk']['tid'] = array(
'#type' => 'select',
'#required' => TRUE,
'#description' => t('Choose into what term you want to merge.'),
'#options' => $options,
);
}
/**
* Supportive function.
*
* Generate form element for hierarchical select widget for term trunk element
* of the term merge form.
*
* @param object $vocabulary
* Fully loaded taxonomy vocabulary object
* @param array $term_branch_value
* Array of Taxonomy term IDs that are nominated as branch terms.
*/
function term_merge_form_term_trunk_widget_hs_taxonomy(&$form, &$form_state, $vocabulary, $term_branch_value) {
$form['term_trunk']['tid'] = array(
'#type' => 'hierarchical_select',
'#description' => t('Please select a term to merge into.'),
'#required' => TRUE,
'#element_validate' => array('term_merge_form_trunk_term_widget_hs_taxonomy_validate'),
'#config' => array(
'module' => 'hs_taxonomy',
'params' => array(
'vid' => $vocabulary->vid,
'exclude_tid' => NULL,
'root_term' => FALSE,
),
'enforce_deepest' => 0,
'entity_count' => 0,
'require_entity' => 0,
'save_lineage' => 0,
'level_labels' => array(
'status' => 0,
),
'dropbox' => array(
'status' => 0,
),
'editability' => array(
'status' => 0,
),
'resizable' => TRUE,
'render_flat_select' => 0,
),
);
}
/**
* Supportive function.
*
* Generate form elements for autocomplete widget for term trunk element of the
* term merge form.
*
* @param object $vocabulary
* Fully loaded taxonomy vocabulary object
* @param array $term_branch_value
* Array of Taxonomy term IDs that are nominated as branch terms.
*/
function term_merge_form_term_trunk_widget_autocomplete(&$form, &$form_state, $vocabulary, $term_branch_value) {
$form['term_trunk']['tid'] = array(
'#type' => 'textfield',
'#description' => t("Start typing in a term's name in order to get some suggestions."),
'#required' => TRUE,
'#autocomplete_path' => 'term-merge/autocomplete/term-trunk/' . $vocabulary->machine_name,
'#element_validate' => array('term_merge_form_trunk_term_widget_autocomplete_validate'),
);
}
/**
* Supportive function.
*
* Validate form element of the autocomplete widget of term trunk element of the
* term merge form. Make sure the entered string is a name of one of the
* existing terms in the vocabulary where the merge occurs. If term is found the
* function substitutes the name with its {taxonomy_term_data}.tid as it is what
* is expected from a term trunk widget to provide in its value.
*/
function term_merge_form_trunk_term_widget_autocomplete_validate($element, &$form_state, $form) {
// Field value is "name (tid)", match the tid from parenthesis.
if (preg_match("/.+\((\d+)\)$/", $element['#value'], $matches)) {
$term = taxonomy_term_load($matches[1]);
}
else {
// Assume that the user didn't use the autocomplete but filled in a tid
// manually.
$term = taxonomy_get_term_by_name($element['#value'], $form['#vocabulary']->machine_name);
$term = reset($term);
}
if (empty($term)) {
// Seems like the user has entered a non existing name or tid in the
// autocomplete textfield.
form_error($element, t('There are no terms matching %value in the %vocabulary vocabulary.', array(
'%value' => $element['#value'],
'%vocabulary' => $form['#vocabulary']->name,
)));
}
else {
// We have to substitute the field value the term tid in order to make this
// widget consistent with the interface.
form_set_value($element, $term->tid, $form_state);
}
}
/**
* Supportive function.
*
* Validate form element of the Hierarchical Select widget of term trunk element
* of the term merge form. Convert the value from array to a single tid integer
* value.
*/
function term_merge_form_trunk_term_widget_hs_taxonomy_validate($element, &$form_state, $form) {
$tid = 0;
if (is_array($element['#value']) && !empty($element['#value'])) {
$tid = (int) array_pop($element['#value']);
}
form_set_value($element, $tid, $form_state);
}

View File

@@ -5,6 +5,90 @@
* Menu page callbacks for Term Merge module.
*/
/**
* Base of the term merge action form.
*
* It is extracted into a separate function to better internal code reuse.
*
* @param object $vocabulary
* Fully loaded Taxonomy vocabulary where the merge should occur
* @param array $term_branch_value
* Array of Taxonomy term IDs that are nominated as branch terms.
*/
function term_merge_form_base(&$form, &$form_state, $vocabulary, $term_branch_value) {
$form['#vocabulary'] = $vocabulary;
$form['#term_merge_term_branch'] = $term_branch_value;
$tree = taxonomy_get_tree($vocabulary->vid);
$form['term_trunk'] = array(
'#type' => 'fieldset',
'#title' => t('Merge Into'),
'#prefix' => '<div id="term-merge-form-term-trunk">',
'#suffix' => '</div>',
'#tree' => TRUE,
'#element_validate' => array('term_merge_form_base_term_trunk_validate'),
);
// Array of currently available widgets for choosing term trunk.
$term_trunk_widget_options = array(
'autocomplete' => 'Autocomplete',
);
if (variable_get('taxonomy_override_selector', FALSE) && module_exists('hs_taxonomy')) {
$term_trunk_widget_options['hs_taxonomy'] = t('Hierarchical Select');
$term_trunk_widget = 'hs_taxonomy';
}
else {
$term_trunk_widget_options['select'] = t('Select');
$term_trunk_widget = 'select';
}
// If the vocabulary is too big, by default we want the trunk term widget to
// be autocomplete instead of select or hs_taxonomy.
if (count($tree) > 200) {
$term_trunk_widget = 'autocomplete';
}
// Override the term trunk widget if settings are found in $form_state.
if (isset($form_state['values']['term_trunk']['widget']) && in_array($form_state['values']['term_trunk']['widget'], array_keys($term_trunk_widget_options))) {
$term_trunk_widget = $form_state['values']['term_trunk']['widget'];
}
// TODO: the trunk term widgets should be implemented as cTools plugins.
$form['term_trunk']['widget'] = array(
'#type' => 'radios',
'#title' => t('Widget'),
'#required' => TRUE,
'#options' => $term_trunk_widget_options,
'#default_value' => $term_trunk_widget,
'#description' => t('Choose what widget you prefer for entering the term trunk.'),
'#ajax' => array(
'callback' => 'term_merge_form_term_trunk',
'wrapper' => 'term-merge-form-term-trunk',
'method' => 'replace',
'effect' => 'fade',
),
);
// @todo:
// There is a known bug, if user has selected something in one widget, and
// then changes the widget, $form_states['values'] will hold the value for
// term trunk form element in the format that is used in one widget, while
// this value will be passed to another widget. This triggers different
// unpleasant effects like showing tid instead of term's name or vice-versa.
// I think we should just empty $form_state['values'] for the term trunk
// form element when widget changes. Better ideas are welcome!
$function = 'term_merge_form_term_trunk_widget_' . $term_trunk_widget;
$function($form, $form_state, $vocabulary, $term_branch_value);
// Ensuring the Merge Into form element has the same title no matter what
// widget has been used.
$form['term_trunk']['tid']['#title'] = t('Merge into');
// Adding necessary options of merging.
$form += term_merge_merge_options_elements($vocabulary);
}
/**
* Menu callback.
*
@@ -20,21 +104,21 @@
*
* @return array
* Array of the form in Form API format
*
* TODO: accidentally this function happens to implement hook_form() which is
* definitely not my intention. This function must be renamed to a safer name.
*/
function term_merge_form($form, $form_state, $vocabulary = NULL, $term = NULL) {
if (is_null($vocabulary)) {
$vocabulary = taxonomy_vocabulary_load($term->vid);
}
// It's always handy to have the vocabulary by hand.
$form['#vocabulary'] = $vocabulary;
if (!isset($form_state['storage']['confirm'])) {
// We are at the set up step.
$tree = taxonomy_get_tree($vocabulary->vid);
$term_branch_value = is_null($term) ? NULL : array($term->tid);
$term_branch_value = is_null($term) ? array() : array($term->tid);
if (variable_get('taxonomy_override_selector', FALSE) && module_exists('hs_taxonomy')) {
// We use Hierarchical Select module if it's available and configured to
// be used for taxonomy selects.
@@ -96,74 +180,14 @@ function term_merge_form($form, $form_state, $vocabulary = NULL, $term = NULL) {
),
'#default_value' => $term_branch_value,
) + $form['term_branch'];
if (is_null($form['term_branch']['#default_value'])) {
unset($form['term_branch']['#default_value']);
// We overwrite term branch value with the one from $form_state, if there is
// something there.
if (isset($form_state['values']['term_branch']) && is_array($form_state['values']['term_branch'])) {
$term_branch_value = $form_state['values']['term_branch'];
}
$form['term_trunk'] = array(
'#type' => 'fieldset',
'#title' => t('Merge Into'),
'#prefix' => '<div id="term-merge-form-term-trunk">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
// Array of currently available widgets for choosing term trunk.
$term_trunk_widget_options = array(
'autocomplete' => 'Autocomplete',
);
if (variable_get('taxonomy_override_selector', FALSE) && module_exists('hs_taxonomy')) {
$term_trunk_widget_options['hs_taxonomy'] = t('Hierarchical Select');
$term_trunk_widget = 'hs_taxonomy';
}
else {
$term_trunk_widget_options['select'] = t('Select');
$term_trunk_widget = 'select';
}
// If the vocabulary is too big, by default we want the trunk term widget to
// be autocomplete instead of select or hs_taxonomy.
if (count($tree) > 200) {
$term_trunk_widget = 'autocomplete';
}
// Override the term trunk widget if settings are found in $form_state.
if (isset($form_state['values']['term_trunk']['widget']) && in_array($form_state['values']['term_trunk']['widget'], array_keys($term_trunk_widget_options))) {
$term_trunk_widget = $form_state['values']['term_trunk']['widget'];
}
$form['term_trunk']['widget'] = array(
'#type' => 'radios',
'#title' => t('Widget'),
'#required' => TRUE,
'#options' => $term_trunk_widget_options,
'#default_value' => $term_trunk_widget,
'#description' => t('Choose what widget you prefer for entering the term trunk.'),
'#ajax' => array(
'callback' => 'term_merge_form_term_trunk',
'wrapper' => 'term-merge-form-term-trunk',
'method' => 'replace',
'effect' => 'fade',
),
);
// @todo:
// There is a known bug, if user has selected something in one widget, and
// then changes the widget, $form_states['values'] will hold the value for
// term trunk form element in the format that is used in one widget, while
// this value will be passed to another widget. This triggers different
// unpleasant effects like showing tid instead of term's name or vice-versa.
// I think we should just empty $form_state['values'] for the term trunk
// form element when widget changes. Better ideas are welcome!
$function = 'term_merge_form_term_trunk_widget_' . $term_trunk_widget;
$function($form, $form_state, $vocabulary);
// Ensuring the Merge Into form element has the same title no matter what
// widget has been used.
$form['term_trunk']['tid']['#title'] = t('Merge into');
// Adding necessary options of merging.
$form += term_merge_merge_options_elements($vocabulary);
term_merge_form_base($form, $form_state, $vocabulary, $term_branch_value);
$form['actions'] = array(
'#type' => 'actions',
@@ -184,29 +208,6 @@ function term_merge_form($form, $form_state, $vocabulary = NULL, $term = NULL) {
return $form;
}
/**
* Supportive function.
*
* Validate the term_merge_form(). Make sure term trunk is not among the
* selected term branches or their children.
*/
function term_merge_form_validate($form, &$form_state) {
if (!isset($form_state['storage']['confirm'])) {
// We only validate the 1st step of the form.
$prohibited_trunks = array();
foreach ($form_state['values']['term_branch'] as $term_branch) {
$children = taxonomy_get_tree($form['#vocabulary']->vid, $term_branch);
$prohibited_trunks[] = $term_branch;
foreach ($children as $child) {
$prohibited_trunks[] = $child->tid;
}
}
if (in_array($form_state['values']['term_trunk']['tid'], $prohibited_trunks)) {
form_error($form['term_trunk']['tid'], t('Trunk term cannot be one of the selected branch terms or their children.'));
}
}
}
/**
* Submit handler for term_merge_form(). Merge terms one into another.
*/
@@ -230,157 +231,6 @@ function term_merge_form_submit($form, &$form_state) {
}
}
/**
* Supportive function.
*
* Generate form elements for select widget for term trunk element of the
* term_merge_form().
*
* @param object $vocabulary
* Fully loaded taxonomy vocabulary object
*/
function term_merge_form_term_trunk_widget_select(&$form, &$form_state, $vocabulary) {
$tree = taxonomy_get_tree($vocabulary->vid);
$options = array();
foreach ($tree as $v) {
$options[$v->tid] = str_repeat('-', $v->depth) . $v->name . ' [tid: ' . $v->tid . ']';
}
$term_branch_value = array();
// Firstly trying to look up selected term branches in the default value of
// term branch form element.
if (isset($form['term_branch']['#default_value']) && is_array($form['term_branch']['#default_value'])) {
$term_branch_value = $form['term_branch']['#default_value'];
}
if (isset($form_state['values']['term_branch']) && is_array($form_state['values']['term_branch'])) {
$term_branch_value = $form_state['values']['term_branch'];
}
if (!empty($term_branch_value)) {
// We have to make sure among term_trunk there is no term_branch or any of
// their children.
foreach ($term_branch_value as $v) {
unset($options[$v]);
foreach (taxonomy_get_tree($vocabulary->vid, $v) as $child) {
unset($options[$child->tid]);
}
}
}
else {
// Term branch has not been selected yet.
$options = array();
}
$form['term_trunk']['tid'] = array(
'#type' => 'select',
'#required' => TRUE,
'#description' => t('Choose into what term you want to merge.'),
'#options' => $options,
);
}
/**
* Supportive function.
*
* Generate form element for hierarchical select widget for term trunk element
* of the term_merge_form().
*
* @param object $vocabulary
* Fully loaded taxonomy vocabulary object
*/
function term_merge_form_term_trunk_widget_hs_taxonomy(&$form, &$form_state, $vocabulary) {
$form['term_trunk']['tid'] = array(
'#type' => 'hierarchical_select',
'#description' => t('Please select a term to merge into.'),
'#required' => TRUE,
'#element_validate' => array('term_merge_form_trunk_term_widget_hs_taxonomy_validate'),
'#config' => array(
'module' => 'hs_taxonomy',
'params' => array(
'vid' => $vocabulary->vid,
'exclude_tid' => NULL,
'root_term' => FALSE,
),
'enforce_deepest' => 0,
'entity_count' => 0,
'require_entity' => 0,
'save_lineage' => 0,
'level_labels' => array(
'status' => 0,
),
'dropbox' => array(
'status' => 0,
),
'editability' => array(
'status' => 0,
),
'resizable' => TRUE,
'render_flat_select' => 0,
),
);
}
/**
* Supportive function.
*
* Generate form elements for autocomplete widget for term trunk element of the
* term_merge_form().
*
* @param object $vocabulary
* Fully loaded taxonomy vocabulary object
*/
function term_merge_form_term_trunk_widget_autocomplete(&$form, &$form_state, $vocabulary) {
$form['term_trunk']['tid'] = array(
'#type' => 'textfield',
'#description' => t("Start typing in a term's name in order to get some suggestions."),
'#required' => TRUE,
'#autocomplete_path' => 'term-merge/autocomplete/term-trunk/' . $vocabulary->machine_name,
'#element_validate' => array('term_merge_form_trunk_term_widget_autocomplete_validate'),
);
}
/**
* Supportive function.
*
* Validate form element of the autocomplete widget of term trunk element of
* the form term_merge_form(). Make sure the entered string is a name of one of
* the existing terms in the vocabulary where the merge occurs. If term is found
* the function substitutes the name with its {taxonomy_term_data}.tid as it is
* what is expected from a term trunk widget to provide in its value.
*/
function term_merge_form_trunk_term_widget_autocomplete_validate($element, &$form_state, $form) {
$term = taxonomy_get_term_by_name($element['#value'], $form['#vocabulary']->machine_name);
if (!is_array($term) || empty($term)) {
// Seems like the user has entered a non existing name in the autocomplete
// textfield.
form_error($element, t('There are no terms with name %name in the %vocabulary vocabulary.', array(
'%name' => $element['#value'],
'%vocabulary' => $form['#vocabulary']->name,
)));
}
else {
// We have to substitute the term's name with its tid in order to make this
// widget consistent with the interface.
$term = array_pop($term);
form_set_value($element, $term->tid, $form_state);
}
}
/**
* Supportive function.
*
* Validate form element of the Hierarchical Select widget of term trunk element
* of the form term_merge_form(). Convert the value from array to a single tid
* integer value.
*/
function term_merge_form_trunk_term_widget_hs_taxonomy_validate($element, &$form_state, $form) {
$tid = 0;
if (is_array($element['#value']) && !empty($element['#value'])) {
$tid = (int) array_pop($element['#value']);
}
form_set_value($element, $tid, $form_state);
}
/**
* Menu page callback function.
*
@@ -413,12 +263,14 @@ function term_merge_form_term_trunk_widget_autocomplete_autocomplete($vocabulary
$term_matches = array();
foreach ($tags_return as $tid => $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) . '"';
// Add both term name and tid to array key in order to allow multiple terms
// with same name to be displayed.
$key = "$name ($tid)";
// Names containing commas or quotes must be wrapped in quotes.
if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
$key = '"' . str_replace('"', '""', $key) . '"';
}
$term_matches[$n] = check_plain($name . ' [tid: ' . $tid . ']');
$term_matches[$key] = check_plain($name . ' [tid: ' . $tid . ']');
}
drupal_json_output($term_matches);
@@ -818,13 +670,13 @@ function term_merge_duplicates_fieldset_preprocess($element) {
foreach ($options as $tid => $row) {
$element['trunk_tid'][$tid]['#title_display'] = 'invisible';
$options[$tid] = array(
'trunk' => drupal_render($element['trunk_tid'][$tid]),
) + $options[$tid];
'trunk' => drupal_render($element['trunk_tid'][$tid]),
) + $options[$tid];
}
$element['trunk_tid']['#title_display'] = 'invisible';
$element['duplicates']['#header'] = array(
'trunk' => $element['trunk_tid']['#title'],
) + $element['duplicates']['#header'];
'trunk' => $element['trunk_tid']['#title'],
) + $element['duplicates']['#header'];
return $element;
}
@@ -858,7 +710,7 @@ function term_merge_duplicates_form_settings($form, &$form_state) {
/**
* Supportive array_filter() callback function.
*
* Eliminate all array elements, whose dimension is less than 1.
* Eliminate all array elements, whose length is less than 1.
*/
function term_merge_duplicates_form_filter($array_element) {
return count($array_element) > 1;

View File

@@ -27,11 +27,9 @@ class TermMergeWebTestCase extends DrupalWebTestCase {
/**
* SetUp method.
*
* @param array $modules
* Array of modules that need to be enabled for test case
*/
public function setUp(array $modules = array()) {
public function setUp() {
$modules = $this->normalizeSetUpArguments(func_get_args());
$modules[] = 'term_merge';
parent::setUp($modules);
@@ -79,6 +77,24 @@ class TermMergeWebTestCase extends DrupalWebTestCase {
$term = entity_load_unchanged('taxonomy_term', $term->tid);
return $term;
}
/**
* Normalize the input arguments of ::setUp() method.
*
* The arguments of ::setUp() method can either be a single argument (array of
* modules) or a set of input arguments where each single argument is a module
* name.
*
* @param array $args
* Array of input arguments given to a ::setUp() method
*
* @return array
* Array of modules that are given to a ::setUp() method.
*/
protected function normalizeSetUpArguments($args) {
return (isset($args[0]) && is_array($args[0])) ? $args[0] : $args;
}
}
/**
@@ -534,6 +550,7 @@ class TermMergeTermMergeWebTestCase extends TermMergeWebTestCase {
'taxonomy_term_tab',
'via_term_trunk_widget_select',
'via_term_trunk_widget_autocomplete',
'via_term_trunk_widget_autocomplete_without_tid',
'merge_fields',
'do_not_merge_fields',
);
@@ -627,7 +644,34 @@ class TermMergeTermMergeWebTestCase extends TermMergeWebTestCase {
// with valid suggestions.
$response = $this->drupalGet('term-merge/autocomplete/term-trunk/' . $this->vocabulary->machine_name . '/' . drupal_strtoupper($terms['term_trunk']->name));
$response = drupal_json_decode($response);
$this->assertTrue(isset($response[$terms['term_trunk']->name]), 'Autocomplete menu path replies with valid suggestions for term trunk autocomplete widget.');
$autocomplete_key = $terms['term_trunk']->name . ' (' . $terms['term_trunk']->tid . ')';
$this->assertTrue(isset($response[$autocomplete_key]), 'Autocomplete menu path replies with valid suggestions for term trunk autocomplete widget.');
// Making sure for the term trunk autocomplete widget doesn't allow to
// submit any of the selected term branches nor their children.
$prohibited_terms = array(
'parent' => 'Merging into the same term is not allowed in autocomplete widget for term trunk.',
'child' => 'Merging into any of child of selected branch terms is not allowed in autocomplete widget for term trunk.',
);
foreach ($prohibited_terms as $term => $assert_message) {
$term = $terms[$term];
$this->drupalGet($init_url);
$this->drupalPostAJAX(NULL, array(
'term_branch[]' => array($terms['parent']->tid),
'term_trunk[widget]' => $term_trunk_widget,
), 'term_trunk[widget]');
$this->drupalPost(NULL, array(
'term_branch[]' => array($terms['parent']->tid),
'term_trunk[widget]' => $term_trunk_widget,
'term_trunk[tid]' => $term->name . ' (' . $term->tid . ')',
), 'Submit');
$this->assertText('Trunk term cannot be one of the selected branch terms or their children', $assert_message);
}
break;
case 'via_term_trunk_widget_autocomplete_without_tid':
$init_url = 'admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/merge';
$term_trunk_widget = 'autocomplete';
// Making sure for the term trunk autocomplete widget doesn't allow to
// submit any of the selected term branches nor their children.
@@ -704,7 +748,7 @@ class TermMergeTermMergeWebTestCase extends TermMergeWebTestCase {
break;
case 'autocomplete':
$term_trunk_edit += array('term_trunk[tid]' => $terms['term_trunk']->name);
$term_trunk_edit += array('term_trunk[tid]' => $terms['term_trunk']->name . ' (' . $terms['term_trunk']->tid . ')');
break;
}
@@ -1044,7 +1088,8 @@ class RedirectTermMergeWebTestCase extends TermMergeWebTestCase {
/**
* SetUp method.
*/
public function setUp(array $modules = array()) {
public function setUp() {
$modules = $this->normalizeSetUpArguments(func_get_args());
$modules[] = 'redirect';
$modules[] = 'path';
parent::setUp($modules);
@@ -1261,12 +1306,22 @@ class SynonymsTermMergeWebTestCase extends TermMergeWebTestCase {
'type' => 'text',
);
/**
* Synonyms behavior implementation that undergoes testing.
*
* @var array
*/
protected $behavior_implementation;
/**
* SetUp method.
*/
public function setUp(array $modules = array()) {
public function setUp() {
$modules = $this->normalizeSetUpArguments(func_get_args());
$modules[] = 'synonyms';
$modules[] = 'synonyms_provider_field';
parent::setUp($modules);
// Additionally we enable default synonyms field in the vocabulary.
$this->field = field_create_field($this->field);
$instance = array(
@@ -1278,11 +1333,21 @@ class SynonymsTermMergeWebTestCase extends TermMergeWebTestCase {
);
$instance = field_create_instance($instance);
$instance = field_info_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
synonyms_behavior_settings_save(array(
'instance_id' => $instance['id'],
'behavior' => 'synonyms',
$this->behavior_implementation = array(
'entity_type' => $instance['entity_type'],
'bundle' => $instance['bundle'],
'provider' => synonyms_provider_field_provider_name($this->field),
'behavior' => 'term_merge',
'settings' => array(),
));
);
synonyms_behavior_implementation_save($this->behavior_implementation);
foreach (synonyms_behavior_get($this->behavior_implementation['behavior'], $this->behavior_implementation['entity_type'], $this->behavior_implementation['bundle'], TRUE) as $behavior_implementation) {
if ($behavior_implementation['provider'] == $this->behavior_implementation['provider']) {
$this->behavior_implementation = $behavior_implementation;
break;
}
}
}
/**
@@ -1325,14 +1390,14 @@ class SynonymsTermMergeWebTestCase extends TermMergeWebTestCase {
actions_do('term_merge_action', $terms['branch'], array(
'term_trunk' => $terms['trunk']->tid,
'term_branch_keep' => TRUE,
'synonyms' => array(),
'synonyms' => NULL,
));
$this->assertSynonymsIntegration($terms, 'No synonyms are added, if action is not instructed to make ones.');
// Testing adding as a synonym.
actions_do('term_merge_action', $terms['branch'], array(
'term_trunk' => $terms['trunk']->tid,
'synonyms' => array($this->field['field_name']),
'synonyms' => $this->behavior_implementation['provider'],
));
$terms['trunk']->synonyms = array($terms['branch']->name);
@@ -1350,7 +1415,7 @@ class SynonymsTermMergeWebTestCase extends TermMergeWebTestCase {
'term_trunk[widget]' => 'select',
'term_trunk[tid]' => $terms['trunk']->tid,
'term_branch_keep' => TRUE,
'synonyms[' . $this->field['field_name'] . ']' => FALSE,
'synonyms' => '',
), 'Submit');
$this->drupalPost(NULL, array(), 'Confirm');
$this->assertSynonymsIntegration($terms, 'No synonyms are added after running merge batch when not instructed to add synonyms.');
@@ -1361,7 +1426,7 @@ class SynonymsTermMergeWebTestCase extends TermMergeWebTestCase {
'term_trunk[widget]' => 'select',
'term_trunk[tid]' => $terms['trunk']->tid,
'term_branch_keep' => TRUE,
'synonyms[' . $this->field['field_name'] . ']' => TRUE,
'synonyms' => $this->behavior_implementation['provider'],
), 'Submit');
$terms['trunk']->synonyms = array($terms['branch']->name);
$this->drupalPost(NULL, array(), 'Confirm');
@@ -1382,10 +1447,10 @@ class SynonymsTermMergeWebTestCase extends TermMergeWebTestCase {
* Assert message to be shown on test results page
*/
protected function assertSynonymsIntegration($terms, $message) {
drupal_static_reset();
foreach ($terms as $term) {
// Getting an array of synonyms according to Synonyms module.
$synonyms = synonyms_get_raw(taxonomy_term_load($term->tid));
$context = array();
$synonyms = synonyms_get_raw(entity_load_unchanged('taxonomy_term', $term->tid), array(), 'synonyms', 'taxonomy_term', $context);
$expected_synonyms = isset($term->synonyms) ? $term->synonyms : array();
// Comparing $synonyms to $expected_synonyms.
@@ -1439,7 +1504,8 @@ class ViewsTermMergeWebTestCase extends TermMergeWebTestCase {
/**
* SetUp method.
*/
public function setUp(array $modules = array()) {
public function setUp() {
$modules = $this->normalizeSetUpArguments(func_get_args());
$modules[] = 'views';
parent::setUp($modules);
// Additionally we create a view.
@@ -1599,7 +1665,8 @@ class EntityReferenceTermMergeWebTestCase extends TermMergeWebTestCase {
);
}
public function setUp(array $modules = array()) {
public function setUp() {
$modules = $this->normalizeSetUpArguments(func_get_args());
$modules[] = 'entityreference';
parent::setUp($modules);