CerPresetSelectionHandler.class.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. class CerPresetSelectionHandler implements EntityReference_SelectionHandler {
  3. private $entity;
  4. public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
  5. return new CerPresetSelectionHandler($entity_type, $entity);
  6. }
  7. public function __construct($entity_type, $entity) {
  8. if ($entity_type && $entity) {
  9. $this->entity = new EntityDrupalWrapper($entity_type, $entity);
  10. }
  11. }
  12. public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
  13. $options = array();
  14. if ($this->entity) {
  15. $finder = new CerPresetFinder($this->entity);
  16. $finder->execute();
  17. foreach ($finder->result['cer'] as $preset) {
  18. $options['cer'][$preset->pid] = $preset->label_variables['@right'];
  19. }
  20. foreach ($finder->result['cer__invert'] as $preset) {
  21. $options['cer'][$preset->pid] = $preset->label_variables['@left'];
  22. }
  23. }
  24. return $options;
  25. }
  26. public function countReferencableEntities($match = NULL, $match_operator = 'CONTAINS') {
  27. return sizeof($this->getReferencableEntities());
  28. }
  29. public function validateReferencableEntities(array $IDs) {
  30. // Don't bother validating preset IDs.
  31. return $IDs;
  32. }
  33. public function validateAutocompleteInput($input, &$element, &$form_state, $form) {
  34. return NULL;
  35. }
  36. public function entityFieldQueryAlter(SelectQueryInterface $query) {
  37. // NOP
  38. }
  39. public function getLabel($entity) {
  40. return entity_label('cer', $entity);
  41. }
  42. public static function settingsForm($field, $instance) {
  43. return array();
  44. }
  45. }