more module updates
This commit is contained in:
@@ -14,7 +14,9 @@ abstract class AbstractSynonymsExtractor {
|
||||
* Array of Field API field types from which this class is able to extract
|
||||
* synonyms
|
||||
*/
|
||||
static public abstract function fieldTypesSupported();
|
||||
public static function fieldTypesSupported() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract synonyms from a field attached to an entity.
|
||||
@@ -38,7 +40,9 @@ abstract class AbstractSynonymsExtractor {
|
||||
* @return array
|
||||
* Array of synonyms extracted from $items
|
||||
*/
|
||||
static public abstract function synonymsExtract($items, $field, $instance, $entity, $entity_type);
|
||||
public static function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow you to hook in during autocomplete suggestions generation.
|
||||
@@ -58,7 +62,7 @@ abstract class AbstractSynonymsExtractor {
|
||||
* @param array $instance
|
||||
* Array of instance definition according to Field API
|
||||
*/
|
||||
static public abstract function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance);
|
||||
public static function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {}
|
||||
|
||||
/**
|
||||
* Add an entity as a synonym into a field of another entity.
|
||||
@@ -91,22 +95,22 @@ abstract class AbstractSynonymsExtractor {
|
||||
* Array of extra items to be merged into the items that already exist in
|
||||
* field values
|
||||
*/
|
||||
static public abstract function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type);
|
||||
public static function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Supportive method.
|
||||
*
|
||||
* Set such a condition on $query that it will always yield no results. Should
|
||||
* be called from $this->processEntityFieldQuery() when for whatever reason
|
||||
* the object can't alter $query to include matched synonyms. As a fallback
|
||||
* it should call this method to make sure it filtered everything out.
|
||||
* be called from $this->processEntityFieldQuery() when for whatever reason
|
||||
* the object can't alter $query to include matched synonyms. As a fallback it
|
||||
* should call this method to make sure it filtered everything out.
|
||||
*
|
||||
* @param EntityFieldQuery $query
|
||||
* Query object passed to $this->processEntityFieldQuery() method
|
||||
* @param array $field
|
||||
* Field array passed to $this->processEntityFieldQuery() method
|
||||
*/
|
||||
static protected function emptyResultsCondition(EntityFieldQuery $query) {
|
||||
$query->entityCondition('entity_id', -1);
|
||||
protected static function emptyResultsCondition(EntityFieldQuery $query) {
|
||||
$query->range(0, 0);
|
||||
}
|
||||
}
|
||||
|
@@ -7,11 +7,11 @@
|
||||
|
||||
class EntityReferenceSynonymsExtractor extends AbstractSynonymsExtractor {
|
||||
|
||||
static public function fieldTypesSupported() {
|
||||
public static function fieldTypesSupported() {
|
||||
return array('entityreference');
|
||||
}
|
||||
|
||||
static public function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
|
||||
public static function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
|
||||
$synonyms = array();
|
||||
|
||||
// For speading up loading all the entities at once.
|
||||
@@ -27,7 +27,7 @@ class EntityReferenceSynonymsExtractor extends AbstractSynonymsExtractor {
|
||||
return $synonyms;
|
||||
}
|
||||
|
||||
static public function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {
|
||||
public static function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {
|
||||
// Unfortunately EntityFieldQuery does not currently support INNER JOINing
|
||||
// referenced entities via any field type.
|
||||
// Thus, we use an ugly solution -- going through all entities that exist
|
||||
@@ -55,9 +55,9 @@ class EntityReferenceSynonymsExtractor extends AbstractSynonymsExtractor {
|
||||
$query->fieldCondition($field, 'target_id', array_keys($result));
|
||||
}
|
||||
|
||||
static public function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
|
||||
// Firstly validating that this entity refernce is able to reference to that
|
||||
// type of entity.
|
||||
public static function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
|
||||
// Firstly validating that this entity reference is able to reference to
|
||||
// that type of entity.
|
||||
$expected_synonym_entity_type = $field['settings']['target_type'];
|
||||
if ($expected_synonym_entity_type != $synonym_entity_type) {
|
||||
return array();
|
||||
@@ -67,5 +67,4 @@ class EntityReferenceSynonymsExtractor extends AbstractSynonymsExtractor {
|
||||
'target_id' => $synonym_entity_id,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,11 +7,11 @@
|
||||
|
||||
class SynonymsSynonymsExtractor extends AbstractSynonymsExtractor {
|
||||
|
||||
static public function fieldTypesSupported() {
|
||||
public static function fieldTypesSupported() {
|
||||
return array('text', 'number_integer', 'number_float', 'number_decimal');
|
||||
}
|
||||
|
||||
static public function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
|
||||
public static function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
|
||||
$synonyms = array();
|
||||
|
||||
foreach ($items as $item) {
|
||||
@@ -21,11 +21,11 @@ class SynonymsSynonymsExtractor extends AbstractSynonymsExtractor {
|
||||
return $synonyms;
|
||||
}
|
||||
|
||||
static public function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {
|
||||
public static function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {
|
||||
$query->fieldCondition($field, 'value', '%' . $tag . '%', 'LIKE');
|
||||
}
|
||||
|
||||
static public function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
|
||||
public static function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
|
||||
$synonym = entity_label($synonym_entity_type, $synonym_entity);
|
||||
switch ($field['type']) {
|
||||
case 'text':
|
||||
|
@@ -7,11 +7,11 @@
|
||||
|
||||
class TaxonomySynonymsExtractor extends AbstractSynonymsExtractor {
|
||||
|
||||
static public function fieldTypesSupported() {
|
||||
public static function fieldTypesSupported() {
|
||||
return array('taxonomy_term_reference');
|
||||
}
|
||||
|
||||
static public function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
|
||||
public static function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
|
||||
$synonyms = array();
|
||||
|
||||
$terms = array();
|
||||
@@ -25,7 +25,7 @@ class TaxonomySynonymsExtractor extends AbstractSynonymsExtractor {
|
||||
return $synonyms;
|
||||
}
|
||||
|
||||
static public function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {
|
||||
public static function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {
|
||||
// Unfortunately EntityFieldQuery does not currently support INNER JOINing
|
||||
// term entity that is referenced via taxonomy_term_reference field type.
|
||||
// Thus, we use an ugly solution -- going through all terms that exist in
|
||||
@@ -56,7 +56,7 @@ class TaxonomySynonymsExtractor extends AbstractSynonymsExtractor {
|
||||
$query->fieldCondition($field, 'tid', $tids);
|
||||
}
|
||||
|
||||
static public function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
|
||||
public static function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
|
||||
// Taxonomy term reference supports only referencing of entity types
|
||||
// 'taxonomy_term'.. duh.
|
||||
if ($synonym_entity_type != 'taxonomy_term') {
|
||||
|
Reference in New Issue
Block a user