protected function CerHandler::addReferenceFrom in Corresponding Entity References 7.2
Creates a reference to the local entity on the remote entity. Throws CerException if the local entity is already referenced by the remote entity, or if the remote field cannot hold any more values.
Parameters
object $entity: The remote entity.
1 call to CerHandler::addReferenceFrom()
- CerHandler::reference in ./
handler.inc - Implements CerHandlerInterface::reference().
File
- ./
handler.inc, line 326 - Contains base code for CER handlers, which are objects responsible for creating, updating and deleting corresponding references between entities.
Class
- CerHandler
- @class Generic CER handler with rudimentary language handling.
Code
protected function addReferenceFrom($entity) {
if ($this
->referencedBy($entity)) {
throw new CerException(t('Cannot create duplicate reference from remote entity.'));
}
elseif ($this
->filled($this
->getRemoteReferenceIDs($entity), $this->remote['field'])) {
throw new CerException(t('Remote field cannot support any more references.'));
}
else {
$languages = field_available_languages($this->remote['entity_type'], $this->remote['field']);
foreach ($languages as $language) {
$entity->{$this->remote['field_name']}[$language][] = array(
'target_id' => $this->id,
);
}
}
}