-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QueryBuilder::setLocale has no effect for HYDRATE_DOCUMENT #605
Comments
The locale is actually not even passed from the QueryBuilder to the Query, it is lost ... |
Not sure I understand. a PHPCR Why use the PHPCR query object instead of the ODM query builder? |
This suggest that you just use setLocale to get your content in a different language. But this does not work, the content is always returned in the current locale. Background: I want to allow my editors to edit foreign language without changing the language of the rest of the UI. This works in Sonata in the edit view since there I can call doLoadTranslation before showing the content. But for the list view I need to have the query return the content in the correct language. |
i fear you mixed up the phpcr-odm query builder and the phpcr query builder, could that be? on phpcr level, there is indeed nothing with locales.
i think what you want to do is getLocaleChooserStrategy()->setLocale('x'). btw, i think the feature you describe sounds a lot like sonata-project/SonataDoctrinePhpcrAdminBundle#328 - if you have some inputs there, that would be highly appreciated. |
@dbu this is exactly where i started from, but no, I do not mix ODM and PHPCR QueryBuilder. I will try to do a failing test ... |
ok, sorry. then that sounds like a bug, or a feature that we thought of but in the end did not finish to implement. glad if you can provide a functional test so we can start fixing this. |
See failing test in #607 |
see https://github.com/valiton-forks/phpcr-odm/tree/sd_fixes_1_2_2 for a minimal fix (not really tested yet) |
can you open a WIP pull request that we can comment on?
i think we should wrap
`$this->dm->getDocumentsByPhpcrQuery($this->query, $this->documentClass,
$this->primaryAlias);`
into a try-catch and change the default locale while fetching documents,
then change it back. otherwise we add quite some overhead i fear. and
possibly destroy lazy loading.
|
I don't like the idea of setting a rather global setting just for doing this, currently it might work but I can see scenarios where this could break. Rather create a equivalent to findMany that works with locales like findTranslation. |
yeah, i see that this is not exactly elegant. maybe the getDocumentsByPhpcrQuery could pass around a locale? the document manager has findTranslation, this should be all that is needed. findTranslation updates the already loaded document, it does not create duplicates (as documents have the same id regardless of the locale they are currently in) |
OK, checked findTranslation. But findTranslation uses the id of the document. If I already have a document, I need the meta class to extract the id before I'm able to use findTranslation. |
or maybe we could redefine findTranslation to accept the document instead of an id as well. there is no reason why a valid document should not represent the document just as well as the id. wdyt? |
Semantically that would seem strange. "loading" is more appropriate, also it would make the first argument redundant: $dm->findTranslation('SomeClassNameThatDoesntMatter', $document, 'de'); So I would vote for |
see also #616 - most DocumentManager methods depend on the locale returned by LocaleChooser, we should have a generic solution without exploding the number of methods. |
in DocumentManager::getDocumentsByPhpcrQuery the locale of the query is ignored.
The text was updated successfully, but these errors were encountered: