? Pending

User tests: Successful: Unsuccessful:

avatar infograf768
infograf768
2 Nov 2017

Pull Request for Issue #18396
Issue: An item (article in that case) tagged to ALL languages is displaying all fields tagged to specific languages.

Summary of Changes

When an item is tagged to ALL languages, only display custom fields tagged to ALL languages.

Testing Instructions

Create a multilingual site. 2 Content languages are enough. Here for en-GB and fr-FR
Structure:
===>Categories
screen shot 2017-11-02 at 09 44 48
===>Articles set as Featured
screen shot 2017-11-02 at 09 46 07
===> Home menu as Featured Articles menu item for each language.
screen shot 2017-11-02 at 09 50 10
===> Create some articles custom fields and assign languages, including ALL
For the sake of this demo I added a Media field tagged to ALL and choose the same image for each article.
screen shot 2017-11-02 at 09 48 24

###Before patch
-----Back-end: when editing an article tagged to ALL languages, we also get the fields tagged to specific languages.
screen shot 2017-11-02 at 09 55 15
---- Which is also the case in frontend
==> Active language is fr-FR
screen shot 2017-11-02 at 09 57 08
==>Active language is en-GB
screen shot 2017-11-02 at 09 58 09

After patch

----- Backend: only fields tagged to ALL languages display in an article tagged to ALL languages.
screen shot 2017-11-02 at 10 03 48

-----Same in frontend
==> Active language is fr-FR
screen shot 2017-11-02 at 10 05 13
==>Active language is en-GB
screen shot 2017-11-02 at 10 06 01

@ajejebrazorf01
@AlexRed
@ggppdk

avatar infograf768 infograf768 - open - 2 Nov 2017
avatar infograf768 infograf768 - change - 2 Nov 2017
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 2 Nov 2017
Category Administration com_fields
avatar AlexRed AlexRed - test_item - 2 Nov 2017 - Tested successfully
avatar AlexRed
AlexRed - comment - 2 Nov 2017

I have tested this item successfully on 2ae0954

Patch ok for me


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/18474.

avatar ajejebrazorf01
ajejebrazorf01 - comment - 2 Nov 2017

A questions.

  1. Why in backend, the english and french tabs disappear? French and english languages are not a subset of All language?
  2. Why in frontend, when the active language is fr-FR, the Article ALL not shown the custom field fr-FR? French language is not a subset of All language?
avatar infograf768
infograf768 - comment - 2 Nov 2017

Why in backend, the english and french tabs disappear? French and english languages are not a subset of All language?

Nope, they are not.

Why in frontend, when the active language is fr-FR, the Article ALL not shown the custom field fr-FR? French language is not a subset of All language?

Nope.

Specific languages are not subset of All languages. Language ALL exists only for display.
Setting an item to ALL languages means that this item may display whatever the Active language.
Example: Modules or articles or categories, etc.

In the case of custom fields, their display should depend on the item language itself.
This is why a custom field tagged to ALL languages should display whatever the item language while custom fields tagged to a specific language should only display when the item language is tagged to the same specific language (which in that case corresponds to the active language).

avatar ajejebrazorf01
ajejebrazorf01 - comment - 2 Nov 2017

A specific language (A) is a subset of all lanuguages (B):

If this is the final change It means that I will continue to use module to filter custom fileds

avatar infograf768
infograf768 - comment - 2 Nov 2017

Do you want to rather get that?
screen shot 2017-11-02 at 11 58 16
screen shot 2017-11-02 at 11 58 30

avatar infograf768
infograf768 - comment - 2 Nov 2017

If this is what you want, it can be done. It will mean that fields will show depending on the active language and no more on the item language.
In backend, all fields would display when editing for example an article tagged to ALL.

avatar ajejebrazorf01
ajejebrazorf01 - comment - 2 Nov 2017

exactly, but it is only my opinion, I don't know if this is the right way.

avatar infograf768
infograf768 - comment - 2 Nov 2017

@AlexRed
@ggppdk
@laoneo

Please give your opinion here.
The code would change this way:
add $app = JFactory::getApplication(); and then further

		if ($app->isAdmin())
		{
			if (JLanguageMultilang::isEnabled() && isset($item->language) && $item->language != '*')
			{
				self::$fieldsCache->setState('filter.language', array('*', $item->language));
			}
		}
		elseif ($app->isSite())
		{
			if (JLanguageMultilang::isEnabled() && isset($item->language))
			{
				$lang = JFactory::getLanguage()->getTag();

				if ($item->language = $lang || $item->language = '*')
				{
					self::$fieldsCache->setState('filter.language', array('*', $lang));
				}
			}
		}
avatar rdeutz
rdeutz - comment - 2 Nov 2017

I think there are arguments for all ways of displaying custom fields, we should be careful and not change behaviour because this can break sites. This needs to be B/C

avatar ajejebrazorf01
ajejebrazorf01 - comment - 2 Nov 2017

Work for me

avatar laoneo
laoneo - comment - 2 Nov 2017

I would not filter the fields depending on of the language of this site. The problem is when you edit an article on the front which doesn't belong to the active language, the existing field data get erased of the fields which are not attached to the site language. Was that not the reason why #12656 was made? To have the same field on multiple languages with a translated label?

avatar infograf768
infograf768 - comment - 2 Nov 2017

@laoneo
That only concerned fields labels and not their content and multilang filtering was not present in code at the time.
Deciding to tag fields by language and then filtering them has changed the situation which is very well described by the original poster in #18396
Basically, in fields.php, filtering is done the same way for site and admin, which was an error.
That's why we get, for an item tagged to ALL, fields tagged to all other languages than the active one or ALL.

result: for example in an article tagged to ALL, one could add a bunch of text in French in a custom field tagged to French and it would still show in French when the article is displayed in the site when en-GB is the active language.

My first solution may not have been the right one but the second proposal solves precisely that issue.

avatar infograf768
infograf768 - comment - 2 Nov 2017

Also:
Using JText for labels is nevertheless extremely useful, and specially for fields tagged to ALL languages in frontend, but not only, because different languages may be available in backend (specially in multilang) which would require translation depending on the language used by the user.

avatar infograf768
infograf768 - comment - 2 Nov 2017

Also

The problem is when you edit an article on the front which doesn't belong to the active language, the existing field data get erased of the fields which are not attached to the site language.

I tested here by editing a field set to ALL, therefore unrelated to the Active site language, and I have no issue because the content of the field depends on content entered in the article itself.
Compare this edited with screenshot above

screen shot 2017-11-02 at 14 02 03

avatar laoneo
laoneo - comment - 3 Nov 2017

So when you edit on the front the article "French Demo" which has the language fr-FR but the site language is set to de-DE. Will then the fields which belong to fr-FR also appear?

avatar infograf768
infograf768 - comment - 3 Nov 2017

@laoneo
In native multilang, the French demo article tagged to fr-FR will just not display when site language (active language) is de-DE. This is the basics of multilang. One has to switch to fr-FR to edit it in frontend.
If is was tagged to "ALL" languages, it would display whatever the active language.

avatar infograf768
infograf768 - comment - 3 Nov 2017

@laoneo
Let me explain again:

This PR (the original code or the one that I also proposed above) does not change the display or not of the custom field tagged to a specific language or ALL when the item language (article as example) has the same language as the custom field.
In that case, a custom field tagged to All will also display for that article.
That is perfectly OK.

The issue concerns ONLY an item/article tagged to ALL.
first proposal (the PR code): only custom fields tagged to ALL will display for an item (article in our case) tagged to ALL.
Second proposal (in my second proposal above): Custom fields tagged to ALL as well as tagged to the same language as the active language ( site language) will display for an article tagged to ALL.

avatar infograf768
infograf768 - comment - 6 Nov 2017

@laoneo
Sorry to insist, but we do have a bug in multilang with custom fields and we should solve this.

We can't accept displaying in an article tagged to ALL the French tagged custom field when the Active language is English

screen shot 2017-11-06 at 17 56 23

avatar laoneo
laoneo - comment - 7 Nov 2017

If it belongs only for the automatic display events, then I would do the language filtering there. Where you have placed it affects all possible calls like getting them for the form, etc.
The display logic can be found here https://github.com/joomla/joomla-cms/blob/staging/plugins/system/fields/fields.php#L326.

avatar infograf768 infograf768 - change - 7 Nov 2017
Title
[fix] Multilanguage: correcting custom fields display in function of item language
[fix] [com_fields] Multilanguage: correcting custom fields display in function of item language
avatar infograf768 infograf768 - edited - 7 Nov 2017
avatar infograf768
infograf768 - comment - 7 Nov 2017

@laoneo
Got it. would this be OK for you?
Adding after https://github.com/joomla/joomla-cms/blob/staging/plugins/system/fields/fields.php#L326

		if ($fields)
		{
			$app = Factory::getApplication();

			if ($app->isClient('site') && Multilanguage::isEnabled() && $item->language == '*')
			{
				$lang = $app->getLanguage()->getTag();

				foreach ($fields as $key => $field)
				{
					if ($field->language == '*' || $field->language == $lang)
					{
						continue;
					}

					unset($fields[$key]);
				}
			}
		}

That would display fields tagged to ALL and fields tagged to the active language only when an item is tagged to ALL.

EDIT: also make sure $item has a language

avatar franz-wohlkoenig franz-wohlkoenig - change - 7 Nov 2017
Title
[fix] [com_fields] Multilanguage: correcting custom fields display in function of item language
[com_fields] Multilanguage: correcting custom fields display in function of item language
avatar joomla-cms-bot joomla-cms-bot - edited - 7 Nov 2017
avatar laoneo
laoneo - comment - 7 Nov 2017

Guess this should work. I'm not so much into the multilanguage stuff as you, but it is the better place to make the language filtering.

avatar infograf768
infograf768 - comment - 7 Nov 2017

OK. As I guess it is too late for 3.8.2 which is in code freeze, will make a new PR and close this one.
@AlexRed I think we are more inline with general multilang behavior this way than if we only display fields tagged to ALL in items also tagged to ALL.
It is quite easy to not fill the value of a field when editing an item tagged to ALL (which means to not set a default value in the field itself)
@ajejebrazorf01 please follow up. will call you both when PR is ready.

avatar infograf768
infograf768 - comment - 8 Nov 2017

@laoneo
while I was going to delete this PR and create a new one with the code above (which works fine for articles and contacts, I wanted to test how custom fields behave for user.

I found out that their display is independent of the display method in
https://github.com/joomla/joomla-cms/blob/staging/plugins/system/fields/fields.php#L304
as deleting the whole method there has no impact.

they do show (without language filtering, even after my patch which code is added in that method) in registration and site edit profile.

Values can be entered for edit profile in frontend, but NOT for a registration where inputs are greyed.

Where shall I look for the language filtering for these?
Why are they greyed but still display when registration?

Screenshot when editing profile in frontend
screen shot 2017-11-08 at 10 36 43
Screenshot when registration
screen shot 2017-11-08 at 10 37 44

avatar laoneo
laoneo - comment - 8 Nov 2017

The problem is with users, that it is based on the form and makes some weird stuff here https://github.com/joomla/joomla-cms/blob/staging/components/com_users/views/profile/tmpl/default_custom.php to display the form fields instead of rendering them as every other extension does. Probably here https://github.com/joomla/joomla-cms/blob/staging/components/com_users/models/profile.php#L126 or here https://github.com/joomla/joomla-cms/blob/staging/components/com_users/models/profile.php#L182 you can set the language of the user and then the form should only load the fields with the right language.

The fields are probably grayed out because of permissions.

avatar infograf768
infograf768 - comment - 8 Nov 2017

@laoneo Will look for lang filtering.

The fields are probably grayed out because of permissions.

Nope. Fields were set to Public. I changed that to Guest and same result.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 8 Nov 2017

@infograf768 if you set Permission of Field to "Allowed" it isn't greyed out anymore:
bildschirmfoto 2017-11-08 um 11 25 45
bildschirmfoto 2017-11-08 um 11 26 34

avatar infograf768
infograf768 - comment - 8 Nov 2017

Thanks @franz-wohlkoenig mixed permissions and access...

@laoneo
I can solve the issue for lang filtering User fields in frontend, but I have to do the patch in fields helper in the getFields() method.

		if ($context == 'com_users.user')
		{
			$app = JFactory::getApplication();

			if ($app->isClient('site') && JLanguageMultilang::isEnabled())
			{
				$lang = $app->getLanguage()->getTag();
				self::$fieldsCache->setState('filter.language', array('*', $lang));
			}
		}

this will work for registration as well as profile.
Could not find a simpler way.

avatar laoneo
laoneo - comment - 8 Nov 2017

@infograf768 didn't test it, but you should be able to set the language on the passed data and you should be fine, no need to do such a workaround.

avatar infograf768
infograf768 - comment - 8 Nov 2017

Indeed, I obtain the correct results if I add in models/profile.php
in the loadFormData() or getData() methods

		if (JLanguageMultilang::isEnabled() && empty($data->language))
		{
			$data->language = JFactory::getLanguage()->getTag();
		}

the problem is that it is OK when editing a profile but does not work for registration...

avatar laoneo
laoneo - comment - 8 Nov 2017

I can have a look on the profile issue when the rest is done. Lets try to do it in different steps.

avatar infograf768
infograf768 - comment - 8 Nov 2017

ok, will do.

avatar infograf768
infograf768 - comment - 9 Nov 2017

Closing this PR in favor of #18536

avatar infograf768 infograf768 - change - 9 Nov 2017
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2017-11-09 07:42:59
Closed_By infograf768
Labels Added: ?
avatar infograf768 infograf768 - close - 9 Nov 2017
avatar infograf768
infograf768 - comment - 9 Nov 2017

@@ajejebrazorf01
Please test #18536

avatar matiaio
matiaio - comment - 28 May 2018

Hello infograf768,

exactly this Problem persists on Custom-Fields for User-Registrations-Form:
I have 3x Languages on my Site and 3x Custom-Fields for each Language in Frontend, but all 3x Custom-Fields are showing on website on User-Registration Form.
It should shows just one Custom-Field for User-Registration per Language.
How can i fix this?

Best Regards

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 28 May 2018

@matiaio Comments on closed Issues didn't get much Notice. Please ask help on the forums. This repository concerns in first Place Joomla-Core coding, thanks.

avatar infograf768
infograf768 - comment - 28 May 2018

@matiaio
This is a known issue. See #18743 and why we closed that PR.

avatar matiaio
matiaio - comment - 28 May 2018

so this issue it will be included into a new Joomla! update? or should i modify some php files in my Website?

avatar matiaio
matiaio - comment - 28 May 2018
avatar matiaio
matiaio - comment - 28 May 2018

@infograf768 i am asking again, because i never used github. sorry

avatar infograf768
infograf768 - comment - 28 May 2018

#18743 was closed. It means that the specific code to solve your issue will not be included in Joomla.

Add a Comment

Login with GitHub to post a comment