You are here

public function SynonymsFindTrait::synonymsFindProcessCondition in Synonyms 8

Supportive method to process $condition argument in synonymsFind().

This method will swap SynonymsFindProviderInterface::COLUMN_* to real column names in $condition for you, so you do not have to worry about internal processing of $condition object.

Parameters

\Drupal\Core\Database\Query\ConditionInterface $condition: Condition to be processed.

string $synonym_column: Actual name of the column where synonyms are kept in text.

string $entity_id_column: Actual name of the column where entity_ids are kept.

File

src/SynonymsProviderInterface/SynonymsFindTrait.php, line 26

Class

SynonymsFindTrait
Supportive trait to find synonyms.

Namespace

Drupal\synonyms\SynonymsProviderInterface

Code

public function synonymsFindProcessCondition(ConditionInterface $condition, $synonym_column, $entity_id_column) {
  $condition_array =& $condition
    ->conditions();
  foreach ($condition_array as &$v) {
    if (is_array($v) && isset($v['field'])) {
      if ($v['field'] instanceof ConditionInterface) {

        // Recursively process this condition too.
        $this
          ->synonymsFindProcessCondition($v['field'], $synonym_column, $entity_id_column);
      }
      else {
        $replace = [
          SynonymsFindProviderInterface::COLUMN_SYNONYM_PLACEHOLDER => $synonym_column,
          SynonymsFindProviderInterface::COLUMN_ENTITY_ID_PLACEHOLDER => $entity_id_column,
        ];
        $v['field'] = str_replace(array_keys($replace), array_values($replace), $v['field']);
      }
    }
  }
}