Supported hints are
- refresh: reload the fields from the database if set
- locale: use this locale instead of the one from the annotation or the default
- fallback: whether to try other languages or throw a not found
exception if the desired locale is not found. defaults to true if
not set and locale is not given either.
- prefetch: if set to false, do not attempt to prefetch related data.
(This makes sense when the caller already did this beforehand.)
/** * {@inheritDoc} */ public function findTranslation($className, $id, $locale, $fallback = true) { try { if (UUIDHelper::isUUID($id)) { try { $id = $this->session->getNodeByIdentifier($id)->getPath(); } catch (ItemNotFoundException $e) { return null; } } elseif (strpos($id, '/') !== 0) { $id = '/' . $id; } $document = $this->unitOfWork->getDocumentById($id); if ($document) { $this->unitOfWork->validateClassName($document, $className); $class = $this->getClassMetadata(get_class($document)); $this->unitOfWork->doLoadTranslation($document, $class, $locale, $fallback); return $document; } $node = $this->session->getNode($id); } catch (PathNotFoundException $e) { return null; } $hints = array('locale' => $locale, 'fallback' => $fallback); return $this->unitOfWork->getOrCreateDocument($className, $node, $hints); }
/** * @author Rob Graham * * Test the registering of a version of a document, state should be set to STATE_FROZEN */ public function testRegisterDocumentForVersion() { // create a node of type frozenNode (which is a version) $node = $this->createNode('/version/doc', 'foo', 'nt:frozenNode'); $document = $this->uow->getOrCreateDocument($this->type, $node); $this->uow->registerDocument($document, '/version/doc'); $this->assertEquals(UnitOfWork::STATE_FROZEN, $this->uow->getDocumentState($document), 'A version of a document is frozen as expected'); }
public function testGetDocumentById() { $user1 = $this->uow->getOrCreateDocument($this->type, $this->createNode('/somepath', 'foo')); $user2 = $this->uow->getDocumentById('/somepath', $this->type); $this->assertSame($user1, $user2); }