You are here

public function AbstractPropertySynonymsBehavior::synonymsFind in Synonyms 7

Look up entities by their synonyms within a behavior implementation.

You are provided with a SQL condition that you should apply to the storage of synonyms within the provided behavior implementation. And then return result: what entities match by the provided condition through what synonyms.

Parameters

QueryConditionInterface $condition: Condition that defines what to search for. Apart from normal SQL conditions as known in Drupal, it may contain the following placeholders:

For ease of work with these placeholders, you may extend the AbstractSynonymsBehavior class and then just invoke the AbstractSynonymsBehavior->synonymsFindProcessCondition() method, so you won't have to worry much about it. Important note: if you plan on re-using the same $condition object for multiple invocations of this method you must pass in here a clone of your condition object, since the internal implementation of this method will change the condition (will swap the aforementioned placeholders with actual column names)

Return value

Traversable Traversable result set of found synonyms and entity IDs to which those belong. Each element in the result set should be an object and will have the following structure:

  • synonym: (string) Synonym that was found and which satisfies the provided condition
  • entity_id: (int) ID of the entity to which the found synonym belongs

Overrides SynonymsBehavior::synonymsFind

File

synonyms_provider_property/includes/AbstractPropertySynonymsBehavior.class.inc, line 47
Abstract class for enabling entity properties to be source of synonyms.

Class

AbstractPropertySynonymsBehavior
Definition of AbstractPropertySynonymsBehavior class.

Code

public function synonymsFind(QueryConditionInterface $condition) {
  $query = db_select($this->entity_info['base table'], 'base');
  $query
    ->addField('base', $this->entity_info['entity keys']['id'], 'entity_id');
  $query
    ->addField('base', $this->property, 'synonym');
  $this
    ->synonymsFindProcessCondition($condition, 'base.' . $this->property, 'base.' . $this->entity_info['entity keys']['id']);
  $query
    ->condition($condition);
  return $query
    ->execute();
}