AbstractPropertySynonymsBehavior.class.inc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @file
  4. * Abstract class for enabling entity properties to be source of synonyms.
  5. */
  6. /**
  7. * Definition of AbstractPropertySynonymsBehavior class.
  8. */
  9. class AbstractPropertySynonymsBehavior extends AbstractSynonymsBehavior implements AutocompleteSynonymsBehavior, SelectSynonymsBehavior {
  10. /**
  11. * Name of the property on which this provider was initialized.
  12. *
  13. * @var string
  14. */
  15. protected $property;
  16. /**
  17. * Entity info of the entity type on which this provider was initialized.
  18. *
  19. * @var array
  20. */
  21. protected $entity_info;
  22. public function __construct($behavior_implementation) {
  23. parent::__construct($behavior_implementation);
  24. $this->property = synonyms_provider_property_name($this->behavior_implementation['provider']);
  25. $this->entity_info = entity_get_info($this->behavior_implementation['entity_type']);
  26. }
  27. public function extractSynonyms($entity, $langcode = NULL) {
  28. $synonyms = array();
  29. if (isset($entity->{$this->property}) && $entity->{$this->property}) {
  30. $synonyms[] = $entity->{$this->property};
  31. }
  32. return $synonyms;
  33. }
  34. public function mergeEntityAsSynonym($trunk_entity, $synonym_entity, $synonym_entity_type) {
  35. // TODO: what to do ???
  36. }
  37. public function synonymsFind(QueryConditionInterface $condition) {
  38. $query = db_select($this->entity_info['base table'], 'base');
  39. $query->addField('base', $this->entity_info['entity keys']['id'], 'entity_id');
  40. $query->addField('base', $this->property, 'synonym');
  41. $this->synonymsFindProcessCondition($condition, 'base.' . $this->property, 'base.' . $this->entity_info['entity keys']['id']);
  42. $query->condition($condition);
  43. return $query->execute();
  44. }
  45. }