/** * Sets the value of the source entity in the relationship * to contain $key pointing to the destination entity ID. * * @param array $relationship The relationship. * @param string $key The key to set (target_id, tid, fid, etc.) * @param array $value_overrides An array of values to override on the field value. * * @return bool * @throws \Exception */ protected function setValueWithKey(array $relationship, $key, array $value_overrides = array()) { $destination_entity_id = $this->getDestinationEntityID($relationship); $stub_entity = $this->getSourceStubEntity($relationship); if (!$destination_entity_id || !$stub_entity) { return false; } // Get all revisions on the stub entity. list($source_entity_id, , ) = entity_extract_ids($relationship['source_type'], $stub_entity); if (Entity::typeSupportsRevisions($relationship['source_type'])) { $source_entity_revisions = Entity::getAllRevisions($source_entity_id, $relationship['source_type']); if (!is_array($source_entity_revisions)) { throw new \Exception('No revisions were found for the entity that should support revisions.'); } $index = array_search($relationship['source_vuuid'], $source_entity_revisions); foreach (array_slice($source_entity_revisions, $index) as $revision_uuid) { $mock_relationship = $relationship; $mock_relationship['source_vuuid'] = $revision_uuid; $mock_stub_entity = $this->getSourceStubEntity($mock_relationship); $field_value = array($key => $destination_entity_id); $field_value = array_replace_recursive($field_value, $value_overrides); $this->setFieldValue($relationship['source_type'], $mock_stub_entity, $relationship['field_name'], $relationship['delta'], $field_value); } } // Finally, set the general value without revisions. $field_value = array($key => $destination_entity_id); $field_value = array_replace_recursive($field_value, $value_overrides); $this->setFieldValue($relationship['source_type'], $stub_entity, $relationship['field_name'], $relationship['delta'], $field_value); return true; }