public function BaseField::synonymsFind in Synonyms 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Synonyms/Provider/BaseField.php \Drupal\synonyms\Plugin\Synonyms\Provider\BaseField::synonymsFind()
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 are matched by the provided condition through what synonyms.
Parameters
\Drupal\Core\Database\Query\ConditionInterface $condition: Condition that defines what to search for. Apart from normal SQL conditions as known in Drupal, it may contain the following placeholders:
- SynonymsFindProviderInterface::COLUMN_SYNONYM_PLACEHOLDER: to denote synonyms column which you should replace with the actual column name where the synonyms data for your provider is stored in plain text.
- SynonymsFindProviderInterface::COLUMN_ENTITY_ID_PLACEHOLDER: to denote column that holds entity ID. You are supposed to replace this placeholder with actual column name that holds entity ID in your case.
For ease of work with these placeholders, you may use the SynonymsFindTrait and then just invoke the $this->synonymsFindProcessCondition() method, so you won't have to worry much about it.
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 should 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 SynonymsFindProviderInterface::synonymsFind
File
- src/
Plugin/ Synonyms/ Provider/ BaseField.php, line 108
Class
- BaseField
- Provide synonyms from base fields.
Namespace
Drupal\synonyms\Plugin\Synonyms\ProviderCode
public function synonymsFind(ConditionInterface $condition) {
$entity_type_definition = $this->entityTypeManager
->getDefinition($this
->getPluginDefinition()['controlled_entity_type']);
$entity_keys = $entity_type_definition
->getKeys();
$query = $this->database
->select($entity_type_definition
->getDataTable(), 'base');
$query
->addField('base', $entity_keys['id'], 'entity_id');
$query
->addField('base', $this
->getPluginDefinition()['field'], 'synonym');
if ($this
->getPluginDefinition()['controlled_entity_type'] != $this
->getPluginDefinition()['controlled_bundle'] && isset($entity_keys['bundle']) && $entity_keys['bundle']) {
$query
->condition($entity_keys['bundle'], $this
->getPluginDefinition()['controlled_bundle']);
}
$this
->synonymsFindProcessCondition($condition, $this
->getPluginDefinition()['field'], $entity_keys['id']);
$query
->condition($condition);
return $query
->execute();
}