/** * Hydrate the entity's owner. * * Assumes the owner can be set to NULL. By default, new entities are owned * by the current user. * * This diverges from the conventional hydration pattern for an update * operation. Normally the absence of [o:owner] would set the value to null. * In this case [o:owner][o:id] must explicitly be set to null. * * @param Request $request * @param EntityInterface $entity */ public function hydrateOwner(Request $request, EntityInterface $entity) { $data = $request->getContent(); $owner = $entity->getOwner(); if ($this->shouldHydrate($request, 'o:owner')) { if (array_key_exists('o:owner', $data) && is_array($data['o:owner']) && array_key_exists('o:id', $data['o:owner'])) { if (is_numeric($data['o:owner']['o:id'])) { $owner = $this->getAdapter('users')->findEntity($data['o:owner']['o:id']); } elseif (null === $data['o:owner']['o:id']) { $owner = null; } } } if (!$owner instanceof User && Request::CREATE == $request->getOperation()) { $owner = $this->getServiceLocator()->get('Omeka\\AuthenticationService')->getIdentity(); } $entity->setOwner($owner); }