webaff Posted July 13, 2017 Share Posted July 13, 2017 Hi, I want to use language-alternate fields inside selectors for manipulating PageArrays, i.e. find(), sort() or filter(). I have set up a multi-lingual file upload with the file field "fileField" and its language alternate fields "fileField_lang1", "fileField_lang2", ... This works as expected: $matches->sort("-fileField.modified"); While this: $matches->sort("-fileFile_lang1.modified"); ...throws an error: "Recoverable Fatal Error: Argument 1 passed to ProcessWire\PageArray::getItemPropertyValue() must be an instance of ProcessWire\Wire, boolean given, called in ..." Maybe I have to turn off outputFormatting? But how would I do that in this context? Any help is well appreciated, thx. Link to comment Share on other sites More sharing options...
Zeka Posted July 13, 2017 Share Posted July 13, 2017 Hi @webaff Have you tried to switch user language to lang1? <?php $currentLanguage = $user -> language; // remember language $langauge = $languages-get('lang1'); $user -> language = $language; $matches->sort("-fileField.modified"); $user -> language = $currentLanguage; // restore language ?> Maybe there's a better way to do that. Link to comment Share on other sites More sharing options...
webaff Posted July 14, 2017 Author Share Posted July 14, 2017 @Zeka, thanks for your reply. I did try that already with no success. I will give some more insight into my setup: It's a multilingual site with the concept of _init.php/_func.php/template/_main.php Inside my template, I get my PageArray together... $matches = $pages->find("template=file"); $matches = $matches->sort("-fileField.modified"); $output = renderFileList($matches); and pass it on to _func.php, where the output ist generated and returned: function renderFileList(PageArray $items) { out = ''; foreach($items as $item) { $out .= $item->fileField->modified; } return $out; } This returns the timestamp of the language specific file. If user language is not default, this magically gets fileField_altlang, as expected from the concept of language-alternate fields. BUT: the results are not sorted by the timestamp of the fileField_altlang but are sorted by the timestamp of the default fileField, no matter what the current user language is. It seems to me, that the concept of language-alternate fields does not work inside Selectors. I hope that someone can follow, reproduce or disprove my findings. Thx. Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 14, 2017 Share Posted July 14, 2017 I'm not sure this will help, but try the following: $pages->find("template=file, sort=-fileField.modified") Especially if you plan on adding pagination to the whole thing sorting at runtime will bite you in the ass. 1 Link to comment Share on other sites More sharing options...
webaff Posted July 14, 2017 Author Share Posted July 14, 2017 @LostKobrakai, thats how I had it first, didn't work neither. Thank you for pointing out issues with pagination. Link to comment Share on other sites More sharing options...
Robin S Posted July 18, 2017 Share Posted July 18, 2017 On 14/07/2017 at 9:24 AM, webaff said: This works as expected: $matches->sort("-fileField.modified"); While this: $matches->sort("-fileFile_lang1.modified"); ...throws an error: "Recoverable Fatal Error: Argument 1 passed to ProcessWire\PageArray::getItemPropertyValue() must be an instance of ProcessWire\Wire, boolean given, called in ..." This error is likely caused by a page in your $matches PageArray having an empty file field. If there is no file then you cannot get the modified timestamp, hence the error. The issue is not related to language alternate fields and would also occur in your default file field if one was empty. Link to comment Share on other sites More sharing options...
webaff Posted July 18, 2017 Author Share Posted July 18, 2017 This issue was solved by two great community members in this thread: Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now