12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- class TaxonomySynonymsExtractor extends AbstractSynonymsExtractor {
- public static function fieldTypesSupported() {
- return array('taxonomy_term_reference');
- }
- public static function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
- $synonyms = array();
- $terms = array();
- foreach ($items as $item) {
- $terms[] = $item['tid'];
- }
- $terms = taxonomy_term_load_multiple($terms);
- foreach ($terms as $term) {
- $synonyms[] = entity_label('taxonomy_term', $term);
- }
- return $synonyms;
- }
- public static function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {
-
-
-
-
- $tids = array();
- foreach ($field['settings']['allowed_values'] as $settings) {
- $efd = new EntityFieldQuery();
- $efd->entityCondition('bundle', $settings['vocabulary'])
- ->entityCondition('entity_type', 'taxonomy_term')
- ->propertyCondition('name', '%' . $tag . '%', 'LIKE');
- $result = $efd->execute();
- if (isset($result['taxonomy_term'])) {
- foreach ($result['taxonomy_term'] as $tid) {
- $tids[] = $tid->tid;
- }
- }
- }
-
-
- if (empty($tids)) {
-
-
- self::emptyResultsCondition($query);
- return;
- }
- $query->fieldCondition($field, 'tid', $tids);
- }
- public static function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
-
-
- if ($synonym_entity_type != 'taxonomy_term') {
- return array();
- }
-
-
- $is_allowed = FALSE;
- foreach ($field['settings']['allowed_values'] as $setting) {
- if ($synonym_entity->vocabulary_machine_name == $setting['vocabulary']) {
- if ($setting['parent'] == 0) {
-
- $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) {
-
-
- return array();
- }
- return array(array(
- 'tid' => $synonym_entity->tid,
- ));
- }
- }
|