class TextSynonymsBehavior in Synonyms 7
Definition of TextSynonymsBehavior class.
Hierarchy
- class \AbstractSynonymsBehavior implements SynonymsBehavior
- class \AbstractFieldSynonymsBehavior
- class \TextSynonymsBehavior implements AutocompleteSynonymsBehavior, SelectSynonymsBehavior
- class \AbstractFieldSynonymsBehavior
Expanded class hierarchy of TextSynonymsBehavior
2 string references to 'TextSynonymsBehavior'
- synonyms_provider_field_synonyms_provider_field_behavior_implementation_info in synonyms_provider_field/
synonyms_provider_field.module - Implements hook_synonyms_provider_field_behavior_implementation_info().
- TextSynonymsBehaviorWebTestCase::getInfo in synonyms_provider_field/
synonyms_provider_field.test - GetInfo method.
File
- synonyms_provider_field/
includes/ TextSynonymsBehavior.class.inc, line 11 - Enables text and number field types to be source of synonyms.
View source
class TextSynonymsBehavior extends AbstractFieldSynonymsBehavior implements AutocompleteSynonymsBehavior, SelectSynonymsBehavior {
public function extractSynonyms($entity, $langcode = NULL) {
$synonyms = array();
foreach ($this
->entityItems($entity, $langcode) as $item) {
$synonyms[] = $item['value'];
}
return $synonyms;
}
public function mergeEntityAsSynonym($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',
));
}
public function synonymsFind(QueryConditionInterface $condition) {
if ($this->field['storage']['type'] != 'field_sql_storage') {
throw new SynonymsBehaviorException(t('Not supported storage engine %type in @method() method.', array(
'%type' => $this->field['storage']['type'],
'@method' => __METHOD__,
)));
}
$table = array_keys($this->field['storage']['details']['sql'][FIELD_LOAD_CURRENT]);
$table = reset($table);
$column = $this->field['storage']['details']['sql'][FIELD_LOAD_CURRENT][$table]['value'];
$this
->synonymsFindProcessCondition($condition, $column, 'entity_id');
$query = db_select($table);
$query
->fields($table, array(
'entity_id',
));
$query
->addField($table, $column, 'synonym');
return $query
->condition($condition)
->condition('entity_type', $this->instance['entity_type'])
->condition('bundle', $this->instance['bundle'])
->execute();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractFieldSynonymsBehavior:: |
protected | property | Field definition array on which this provider was initialized. | |
AbstractFieldSynonymsBehavior:: |
protected | property | Field instance definition on which this provider was initialized. | |
AbstractFieldSynonymsBehavior:: |
protected | function | Retrieve items of the underlying field in this behavior implementation. | |
AbstractFieldSynonymsBehavior:: |
public | function |
Collect info on features pipe during invocation of hook_features_export(). Overrides AbstractSynonymsBehavior:: |
|
AbstractFieldSynonymsBehavior:: |
protected | function | Filter $items only to contain unique values. | |
AbstractFieldSynonymsBehavior:: |
public | function |
Overrides AbstractSynonymsBehavior:: |
|
AbstractSynonymsBehavior:: |
protected | property | Behavior implementation on which this class was initialized. | |
AbstractSynonymsBehavior:: |
constant | Constant which denotes placeholder of an entity ID column. | ||
AbstractSynonymsBehavior:: |
constant | Constant which denotes placeholder of a synonym column. | ||
AbstractSynonymsBehavior:: |
protected | function | Process condition in 'synonymsFind' method. | |
TextSynonymsBehavior:: |
public | function |
Extract synonyms from an entity within a specific behavior implementation. Overrides SynonymsBehavior:: |
|
TextSynonymsBehavior:: |
public | function |
Add an entity as a synonym into another entity. Overrides SynonymsBehavior:: |
|
TextSynonymsBehavior:: |
public | function |
Look up entities by their synonyms within a behavior implementation. Overrides SynonymsBehavior:: |