Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / entityqueue / plugins / entityreference / selection / EntityReference_SelectionHandler_EntityQueue.class.php
1 <?php
2
3 /**
4  * @file
5  * Definition of EntityReference_SelectionHandler_EntityQueue.
6  */
7
8 /**
9  * Defines a Entityreference selection handler for Entityqueue.
10  */
11 class EntityReference_SelectionHandler_EntityQueue extends EntityReference_SelectionHandler_Generic {
12
13   /**
14    * Overrides EntityReference_SelectionHandler_Generic::getInstance().
15    */
16   public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
17     return new EntityReference_SelectionHandler_EntityQueue($field, $instance, $entity_type, $entity);
18   }
19
20   /**
21    * Constructs the EntityQueue selection handler.
22    */
23   protected function __construct($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
24     parent::__construct($field, $instance, $entity_type, $entity);
25
26     $queue_name = NULL;
27     if (!empty($entity->queue)) {
28       $queue_name = $entity->queue;
29     }
30     elseif (!empty($instance['bundle'])) {
31       $queue_name = $instance['bundle'];
32     }
33     if (!empty($queue_name)) {
34       $this->queue = entityqueue_queue_load($queue_name);
35     }
36
37     // Override the entityreference settings with our own.
38     $this->field['settings']['handler_settings']['target_bundles'] = NULL;
39   }
40
41   /**
42    * Overrides EntityReference_SelectionHandler_Generic::buildEntityFieldQuery().
43    */
44   public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
45     $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance, $this->entity_type, $this->entity);
46     $query = $handler->buildEntityFieldQuery($match, $match_operator);
47
48     if (!empty($this->queue->settings['target_bundles'])) {
49       $query->entityCondition('bundle', $this->queue->settings['target_bundles'], 'IN');
50     }
51
52     return $query;
53   }
54
55   /**
56    * Implements EntityReferenceHandler::validateReferencableEntities().
57    */
58   public function validateReferencableEntities(array $ids) {
59     $referencable = parent::validateReferencableEntities($ids);
60     // Allow users to save the queue even if they don't have access to an
61     // existing entity in the queue. See https://www.drupal.org/node/2383903
62     $existing = $this->getCurrentlyReferencedEntityIds();
63
64     return array_unique(array_merge($referencable, $existing));
65   }
66
67   /**
68    * Gets ids of existing entities in the queue.
69    *
70    * @return array
71    *   Entity ids that are currently referenced by the entity.
72    */
73   public function getCurrentlyReferencedEntityIds() {
74     $ret = array();
75     if (isset($this->entity) && isset($this->field)) {
76       $entity_type = $this->entity_type;
77       $field_name = $this->field['field_name'];
78       $wrapper = entity_metadata_wrapper($entity_type, $this->entity);
79       $ret = $wrapper->{$field_name}->raw();
80     }
81
82     return $ret;
83   }
84
85 }