Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -2291,11 +2291,17 @@ public function getChildren($document, $filter = null, $fetchDepth = null, $igno
$node = $this->session->getNode($this->getDocumentId($document));
$this->setFetchDepth($oldFetchDepth);

if (method_exists($document, 'getLocale')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the proper way would be to get the locale via the ClassMetadata.

if ($class->localeMapping) {
    $childrenHints = array('locale' => $class->reflFields[$class->localeMapping]->getValue($document));
} else {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw a isDocumentTranslatable method which is not based on localeMapping but
return !empty($metadata->translator)
&& is_string($metadata->translator)
&& count($metadata->translatableFields) !== 0;

Shouldn't be cleaner to do this :
$metadata = $this->dm->getClassMetadata(get_class($document));
if ($this->isDocumentTranslatable($metadata)) {
}
?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think that this is necessary .. the hint is then passed to loadTranslations() which in turn calls isDocumentTranslatable()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the code i gave you is indeed wrong .. sine this will only work if the locale is mapped in the document

the better way to get the current locale would be:

$oid = spl_object_hash($document);
if (isset($this->documentLocales[$oid]['current'])) {
    $childrenHints = array('locale' => $this->documentLocales[$oid]['current']);
} else {

$childrenHints = array('locale' => $document->getLocale());
} else {
$childrenHints = array();
}

$childNodes = $node->getNodes($filter);
$childDocuments = array();
foreach ($childNodes as $name => $childNode) {
try {
$childDocuments[$name] = $this->createDocument(null, $childNode);
$childDocuments[$name] = $this->createDocument(null, $childNode, $childrenHints);
} catch (MissingTranslationException $e) {
if (!$ignoreUntranslated) {
throw $e;
Expand Down