You are here

abstract class AbstractSynonymsBehavior in Synonyms 7

Starting point for implementing SynonymsBehavior interface.

Hierarchy

Expanded class hierarchy of AbstractSynonymsBehavior

File

includes/SynonymsBehavior.interface.inc, line 107
Interfaces of synonyms behaviors that are shipped with Synonyms module.

View source
abstract class AbstractSynonymsBehavior implements SynonymsBehavior {

  /**
   * Constant which denotes placeholder of a synonym column.
   *
   * @var string
   */
  const COLUMN_SYNONYM_PLACEHOLDER = '***COLUMN***';

  /**
   * Constant which denotes placeholder of an entity ID column.
   *
   * @var string
   */
  const COLUMN_ENTITY_ID_PLACEHOLDER = '***ENTITY_ID***';

  /**
   * Behavior implementation on which this class was initialized.
   *
   * @var array
   */
  protected $behavior_implementation;
  public function __construct($behavior_implementation) {
    $this->behavior_implementation = $behavior_implementation;
  }
  public function featuresExportPipe() {
    return array();
  }

  /**
   * Process condition in 'synonymsFind' method.
   *
   * Process condition in 'synonymsFind' method replacing all references of
   * synonym and entity ID columns with the real names of those columns.
   *
   * @param QueryConditionInterface $condition
   *   Condition that should be processed
   * @param string $column_synonym
   *   Real name of the synonym column
   * @param string $column_entity_id
   *   Real name of the entity ID column
   */
  protected function synonymsFindProcessCondition(QueryConditionInterface $condition, $column_synonym, $column_entity_id) {
    $condition_array =& $condition
      ->conditions();
    foreach ($condition_array as &$v) {
      if (is_array($v) && isset($v['field'])) {
        if ($v['field'] instanceof QueryConditionInterface) {

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

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractSynonymsBehavior::$behavior_implementation protected property Behavior implementation on which this class was initialized.
AbstractSynonymsBehavior::COLUMN_ENTITY_ID_PLACEHOLDER constant Constant which denotes placeholder of an entity ID column.
AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER constant Constant which denotes placeholder of a synonym column.
AbstractSynonymsBehavior::featuresExportPipe public function Collect info on features pipe during invocation of hook_features_export(). Overrides SynonymsBehavior::featuresExportPipe 2
AbstractSynonymsBehavior::synonymsFindProcessCondition protected function Process condition in 'synonymsFind' method.
AbstractSynonymsBehavior::__construct public function 2
SynonymsBehavior::extractSynonyms public function Extract synonyms from an entity within a specific behavior implementation. 7
SynonymsBehavior::mergeEntityAsSynonym public function Add an entity as a synonym into another entity. 7
SynonymsBehavior::synonymsFind public function Look up entities by their synonyms within a behavior implementation. 7