/**
  * Return the revision id for a passed in id for the type stored from the constructor
  *
  * @param \StdClass $data
  *   and object with the following properties
  *   revision_id_key
  *   base_id_key
  *   base_table
  *   ids : the ids
  * @param \Drupal\sps\Plugins\OverrideControllerInterface $override_controller
  *   This is an override controller to use to find
  *   override data
  *
  * @return array|mixed
  *  array of revision ids;
  */
 public function react($data, \Drupal\sps\Plugins\OverrideControllerInterface $override_controller)
 {
     $had_overrides = FALSE;
     if (!empty($data->ids)) {
         $revision_id_query = db_select($data->base_table, 'b');
         $revision_id_query->fields('b', array($data->revision_id_key, $data->base_id_key));
         $revision_id_query->condition('b.' . $data->base_id_key, $data->ids);
         $revision_id_query->addTag(SPS_NO_ALTER_QUERY_TAG);
         $result = $revision_id_query->execute()->fetchAllAssoc($data->base_id_key);
         foreach ($result as $id => $row) {
             $override = $override_controller->getRevisionId($id, $data->type);
             $vids[] = $override['revision_id'] ?: $row->{$data->revision_id_key};
             $had_overrides = $had_overrides || $override;
         }
     }
     return $had_overrides ? $vids : array();
 }
 /**
  * Alter a query to use the overridden revision id as well as
  * revision fields.
  *
  * @param \SelectQueryInterface $data
  *   This expect a SelectQuery Object to alter
  * @param $override_controller
  *   This is an override controller to use to find
  *   override data
  *
  * @return \Drupal\sps\Plugins\Reaction\EntitySelectQueryAlterReaction
  *  Self
  */
 public function react($data, \Drupal\sps\Plugins\OverrideControllerInterface $override_controller)
 {
     $query = $data->query;
     $alias = $this->extractAlias($query);
     //exit prematurly if we ha a no alter tag
     if ($query->hasTag(SPS_NO_ALTER_QUERY_TAG)) {
         return;
     }
     $alias = $this->extractAlias($query);
     if ($alias) {
         $this->addRevisionTables($query);
         $alias = $this->extractAlias($query);
         $property_map = $override_controller->getPropertyMap();
         $this->addOverrideTable($query, $override_controller);
         $fields =& $query->getFields();
         $this->fieldsToExpressions($query, array_keys($property_map), $alias);
         $this->fieldReplace($fields, $alias, $property_map);
         $expressions =& $query->getExpressions();
         $this->recursiveReplace($expressions, $alias, $property_map);
         $tables =& $query->getTables();
         $this->recursiveReplace($tables, $alias, $property_map);
         $where =& $query->conditions();
         $this->encapCondition($where);
         $this->recursiveReplace($where, $alias, $property_map);
         $order =& $query->getOrderBy();
         $this->recursiveReplace($order, $alias, $property_map);
         $group =& $query->getGroupBy();
         $this->recursiveReplace($group, $alias, $property_map);
         $having =& $query->havingConditions();
         $this->recursiveReplace($having, $alias, $property_map);
         /*
               $this->recursiveReplace($fields);
         */
     }
     return $this;
 }
 /**
  *
  * @param int $data
  *   the entity id
  * @param $override_controller
  *   This is an override controller to use to find
  *   override data
  *
  * @return int | NULL
  *  the revision id;
  */
 public function react($data, \Drupal\sps\Plugins\OverrideControllerInterface $override_controller)
 {
     if ($override_controller->getRevisionId($data['id'], $data['type'])) {
         return 'sps-overridden';
     }
 }