bytesource Posted August 20, 2015 Share Posted August 20, 2015 Hi, I as part of an implementation that extracts the strings from all translatable language fields, the following code section retrieves the description value from all files and images: <?php $currentPage = $page; $currentPage->setOutputFormatting(false); $pageFields = $currentPage->fields; // iterate through all fields of a page foreach ($pageFields as $field) { $type = $field->type; // FieldtypeImage is a subclass of FieldtypeFile, // but for clarity we separate both types here. if ($type == "FieldtypeImage" || $type == "FieldtypeFile") { $fieldName = $field->name; // for all images, retrieve the text value from the 'description' field // From the file/image field type settings page: // "When output formatting is off, the value is always an array (WireArray)."" // So, with output formatting set to 'false' in getDefaultValues(), we can use // 'foreach' on all fields, even if the value for 'Maximum files allowed' was set to 1. foreach($currentPage->$fieldName as $file) $text = $file->description; // sample output echo $text; } // checking for other field types and extracting values } ?> The problem is, regardless of whether a description value was set or not, all that is returned is the string "original". I wonder if anyone might have an idea of what is going on here. Cheers, Stefan Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 20, 2015 Share Posted August 20, 2015 I suggest taking a look a these line: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/Pagefile.php#L209-L220 Link to comment Share on other sites More sharing options...
bytesource Posted August 20, 2015 Author Share Posted August 20, 2015 Thanks for pointing me to that piece of code. So, instead of $text = $file->description; I tried $text = $file->description(); as well as $text = $file->description($defaultLanguage, null); as well as $text = $file->description($defaultLanguage); But in each case I still only got the string "original" back. I also wonder where this string might come from. At least it does not appear in the Pagefile source code. Cheers, Stefan Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 20, 2015 Share Posted August 20, 2015 Which version of ProcessWire are we talking about? Link to comment Share on other sites More sharing options...
bytesource Posted August 20, 2015 Author Share Posted August 20, 2015 I have version 2.6.1 installed. Link to comment Share on other sites More sharing options...
bytesource Posted August 21, 2015 Author Share Posted August 21, 2015 I am sorry, but this was a false alarm. Only today did I realize that I was extracting the descriptions from another page than I thought. This other page is a dummy page whose image description fields were indeed all populated with the value "original". 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