Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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".

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...