Jump to content

image field bug


Soma
 Share

Recommended Posts

I clone an image field "header_image" and rename the clone to "header_image_en", add it below the original to the template…. suddenly the original image field can't be outputed anymore via API at all.

I remove the cloned image field from the template, the original imagefield works again...

Also when I rename the cloned image field to something else like "header_image_another" and it suddenly works again.

Link to comment
Share on other sites

It sounds like you are triggering the language alternate fields. Assuming you have the LanguageSupportFields module installed, it'll be looking for any field names that end with a language name, like "_en" in "header_image_en". If it finds another field that has the same name, but no language (like "header_image"), then it assumes your "header_image_en" field is a language alternate field. Meaning, it'll substitute that field for "header_image" when it sees that the user's language is "en".

Link to comment
Share on other sites

Ahh thanks, then it's more or less what I thought it could be.

If I understand you correctly, it thinks the "header_image" is a language field where "header_image_en" would be the "en" value? So the "header_image" would be the default? And because the image field is not really of type "LanguagesFieldtypeValue" it fails?

I solved it by naming the default (baselanguage) image field "header_images_default" so the conflict doesn't happen. So one have to be cautious when naming fields having language fields enabled. :)

Link to comment
Share on other sites

If I understand you correctly, it thinks the "header_image" is a language field where "header_image_en" would be the "en" value? So the "header_image" would be the default? And because the image field is not really of type "LanguagesFieldtypeValue" it fails?

That's correct. But note that these language alternate fields can be used with any fieldtype. So there's not really any reason to use them with TextLanguage, TextareaLanguage or PageTitleLanguage. They are an alternate way of doing multi-language fields.

Link to comment
Share on other sites

Now I'm very confused. Is this supposed to work like this for non and even text fields? How would I then use it, because in my case it wasn't working, the "header_image" wasn't returning anything?

EDIT: Now it dawns on me, reading the docu again I remember reading something about it but forgot. Hmm will have to make another test, maybe something else went wrong, because the language was set to the default, yet nothing was returned for the image... even though other fields were working normal.

Link to comment
Share on other sites

It seems to be working good in my local install so far.

Another question I wondered. How could I disable default language fallback when using in frontend? So I can output a field value as usual and it would return null if the current language field isn't populated, without setting outputformatting on an off.

Edit: now trying even the suggested way to use of(false) and getLanguageValue doesn't work on language fields (image in this case)

Error Exception: Method Pageimages::getLanguageValue does not exist or is not callable in this context (in /Applications/XAMPP/xamppfiles/htdocs/pw-dev/wire/core/Wire.php line 231)

with this code

$page->of(false);
$lang = $languages->get("de");
$img = $page->image->getLanguageValue($lang);
$page->of(true);
Link to comment
Share on other sites

The LanguagesPageFieldValue (and getLanguageValue function) are only applicable to multi-language fields. The only multi-language fieldtypes there are at present are TextareaLanguage, TextLanguage and PageTitleLanguage.

Language alternate fields are an entirely different thing. It is nothing more than one field substituted for the other. For instance, 'image_de' would be substituted for 'image' when the user's language is 'de' and 'image_de' is populated. That's all there is to it. There aren't any other classes or functions to think about behind the scenes with language alternate fields.

With language alternate fields 'image' and 'image_de', if you don't want fallback of 'image' to 'image_de' to occur when 'image_de' is populated and the user's language is 'de', then turn off output formatting, or retrieve the value with $page->getUnformatted('image');

Your example was trying to retrieve the value in 'de' regardless of the user's current language. So if that's what you are trying to do, then just access 'image_de' directly, i.e.

$img = $page->image_de;  

or a non-language specific version:

$img = $page->get('image_' . $user->language->name);
  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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