bug PR-4.3-dev Pending

User tests: Successful: Unsuccessful:

avatar korenevskiy
korenevskiy
3 Apr 2022

When opening a user's page with an article and any custom field. This same field is rendered 2 times. I repeat. One field in the article is rendered 2 times. This issue has been studied. When the field is rendered 2 times, only 1 result is shown on the site, and 2 render result is meaningless. At the same time, All subscriptions of render events called by the dispatcher are also executed 2 times. Thus, it is not possible to write a user data handler without using crutches and props to avoid double processing of the field object.
For example, if you develop a new field with processing data from forms received from the user. Then such data processing needs to be subscribed to the plugin method

PlgFieldsNewForm->onCustomFieldsPrepareField($context, $item, $field)

But this method will be called 2 times.
My correction allows you to make 1 render for one field call. While maintaining backward compatibility.

This correction does not matter for static data output. But this amendment is of great importance for the output of dynamic data in user fields of articles. This can be useful when creating a complex graph field with a lot of data in one field. Or a feedback field. But in order for feedback to work in a complex field, it is required to render exactly as many times as it will be displayed on the site.

Rendering occurs when the method is called

FieldsHelper::getFields($context, $item);

When calling this method, dispatcher subscriptions are called

FieldsPlugin->onCustomFieldsBeforePrepareField($context, $item, &$field)
FieldsPlugin->onCustomFieldsPrepareField($context, $item, &$field)
FieldsPlugin->onCustomFieldsAfterPrepareField($context, $item, $field, &$value)

Accordingly, for one field, all these methods will be called twice.

However, this happens in the 2 places indicated below

PlgSystemFields->display($context, $item, $params, $displayType)
PlgSystemFields->onContentPrepare($context, $item)

This fix allows you to use the same render in both calls to these methods.

The text has been supplemented thanks to Richard's comments.
We need to create this plugin in the /plugins/fields/newmyfield folder with the class inherited from Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin.
In this plugin we create methods onCustomFieldsPrepareField($context, $item, &$field)

use Joomla\Component\Fields\Administrator\Plugin;
use Joomla\CMS\Factory;
class PlgFieldsNewMyField extends FieldsPlugin {
	public function onCustomFieldsPrepareField($context, $item, &$field){
		if($field->type!='newmyfield')
			return parent::onCustomFieldsPrepareField($context, $item, $field);
		static $counter;
		if(is_null($counter))
			$counter = 0;
		Factory::getApplication()->enqueueMessage('Counter Rendering field:'.$field->type.'  counter:'.++$counter );	

		return parent::onCustomFieldsPrepareField($context, $item, $field);
	}
}

Thanks to this test, it is clear that the new amendment calls this method once. Without new corrections, this method was previously called 2 times for one field. You can also place a counter for the test in the rendering file.
/plugins/fields/newmyfield/tmpl/newmyfield.php - this is the layout file for the field.
inside this file we will place a similar counter with a message call.
Factory::getApplication()->enqueueMessage('Counter Rendering field:'.$field->type.' counter:'.++$counter );

in the message call, you need to specify $counter. Since if the messages are completely identical, then 1 message will be displayed instead of 2x. In order to accurately see the number of message calls, we must specify a different text in the message each time. The sequence number in the message will change the text. and the message will be displayed to the number of calls.

Should I blow up all the plugin methods in a row to test the number of calls? But if it is required, we can prescribe a similar example of code for methods.

FieldsPlugin->onCustomFieldsBeforePrepareField($context, $item, &$field) 
FieldsPlugin->onCustomFieldsAfterPrepareField($context, $item, $field, &$value)

But I think one method is enough for the test.

Also at the end I added a plugin event call once without multiple calls in to FOREACH.

Factory::getApplication()->triggerEvent('onCustomFieldsContentPrepare', [$context, $item, &$item->jcfields]);

This will also allow you to change the value of the fields from the beginning of the list after passing all the results.

avatar korenevskiy korenevskiy - open - 3 Apr 2022
avatar korenevskiy korenevskiy - change - 3 Apr 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 3 Apr 2022
Category Front End Plugins
avatar korenevskiy korenevskiy - change - 3 Apr 2022
The description was changed
avatar korenevskiy korenevskiy - edited - 3 Apr 2022
avatar korenevskiy korenevskiy - change - 3 Apr 2022
The description was changed
avatar korenevskiy korenevskiy - edited - 3 Apr 2022
avatar korenevskiy korenevskiy - change - 3 Apr 2022
The description was changed
avatar korenevskiy korenevskiy - edited - 3 Apr 2022
avatar korenevskiy korenevskiy - change - 3 Apr 2022
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 3 Apr 2022
Category Front End Plugins Administration com_fields Front End Plugins
avatar richard67
richard67 - comment - 3 Apr 2022

I don’t see any testing instructions in the description of this PR.

avatar korenevskiy
korenevskiy - comment - 4 Apr 2022

Hello Richard. I have completed the description

avatar korenevskiy
korenevskiy - comment - 4 Apr 2022

I have little experience in writing tests. But it will take me a long time and I will need to study the test classes. Perhaps I will consult here. But so far I have managed to find the error and issue a correction.

avatar richard67
richard67 - comment - 4 Apr 2022

I did not mean to write unit test or something like that. I meant to write testing instructions for human testers in the description of this PR. There were the headings for these tests in the description template which you get when you create a new PR, but you have removed them. Do you think we had them there for nothing?

avatar korenevskiy
korenevskiy - comment - 4 Apr 2022

Do you think we had them there for nothing?

You are right, I am aware of the seriousness of these names. I am aware of the importance of the project for many participants. I was tired, and since I don't know the language well, I'm writing a description through a translator. I was wrong, I will definitely improve in the future.
I have completed the description

avatar korenevskiy korenevskiy - change - 4 Apr 2022
The description was changed
avatar korenevskiy korenevskiy - edited - 4 Apr 2022
avatar korenevskiy korenevskiy - change - 5 Apr 2022
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 5 Apr 2022
Category Front End Plugins Administration com_fields Front End Plugins
avatar korenevskiy korenevskiy - change - 24 Apr 2022
Labels Added: PBF
Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 24 Apr 2022
Category Front End Plugins Administration com_fields Front End Plugins
avatar korenevskiy
korenevskiy - comment - 25 Apr 2022

And what does the PBF hash tag mean?

avatar richard67
richard67 - comment - 25 Apr 2022

And what does the PBF hash tag mean?

Pizza, Bugs and Fun. At Joomls day USA there was such an event, and we flagged a bunch of PRs with that label so people test them. The label will be removed in a few days.

avatar korenevskiy
korenevskiy - comment - 8 May 2022

And how do I create another PR on the FieldsHelper.php file?
But the new PR is not related to the topic of this PR. But since the current PR will change the code of this FieldsHelper.php file and make a shift in the number of lines. That new PR may conflict with the current PR, due to the fact that the amendments affect the same code.

avatar richard67
richard67 - comment - 8 May 2022

@korenevskiy Normally you create a new branch for each PR, based on the target branch of the upstream repository (= this here)

avatar richard67
richard67 - comment - 8 May 2022

P.S. In case of this PR you have done it right and have created a separate branch. For the new PR just make another branch based on your 4.1-dev branch and not of the one from this PR here.

avatar HLeithner
HLeithner - comment - 27 Jun 2022

This pull requests has automatically rebased to 4.2-dev.

avatar joomla-bot
joomla-bot - comment - 27 Jun 2022

This pull requests has been automatically converted to the PSR-12 coding standard.

avatar korenevskiy korenevskiy - change - 1 Jul 2022
Labels Added: ?
avatar korenevskiy korenevskiy - change - 4 Jul 2022
Labels Added: ?
Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 8 Mar 2023
Category Front End Plugins Administration com_fields Administration com_admin SQL Postgresql com_config com_fields com_finder Language & Strings JavaScript Repository NPM Change Front End com_contact com_users Installation
avatar korenevskiy korenevskiy - change - 8 Mar 2023
Labels Removed: ?
avatar korenevskiy korenevskiy - change - 8 Mar 2023
Labels Added: Language Change NPM Resource Changed
Removed: PBF
avatar korenevskiy korenevskiy - change - 8 Mar 2023
Labels Added: PR-4.3-dev
avatar joomla-cms-bot joomla-cms-bot - change - 8 Mar 2023
Category Front End Administration com_fields com_admin SQL Postgresql com_config com_finder Language & Strings JavaScript Repository NPM Change com_contact com_users Installation Administration com_admin com_config com_fields com_finder Language & Strings JavaScript Repository NPM Change Front End com_contact com_users Installation
avatar joomla-cms-bot joomla-cms-bot - change - 8 Mar 2023
Category Front End Administration com_fields com_admin com_config com_finder Language & Strings JavaScript Repository NPM Change com_contact com_users Installation Administration com_admin com_fields com_finder Language & Strings JavaScript Repository NPM Change Front End com_contact com_users Installation
avatar joomla-cms-bot joomla-cms-bot - change - 8 Mar 2023
Category Front End Administration com_fields com_admin com_finder Language & Strings JavaScript Repository NPM Change com_contact com_users Installation Administration com_fields Language & Strings JavaScript Repository NPM Change Front End com_contact com_finder com_users Installation
avatar joomla-cms-bot joomla-cms-bot - change - 9 Mar 2023
Category Front End Administration com_fields com_finder Language & Strings JavaScript Repository NPM Change com_contact com_users Installation Administration com_fields JavaScript Repository NPM Change Front End com_contact com_users Installation Language & Strings
avatar joomla-cms-bot joomla-cms-bot - change - 9 Mar 2023
Category Front End Administration com_fields Language & Strings JavaScript Repository NPM Change com_contact com_users Installation Administration com_fields JavaScript Repository NPM Change Front End com_users Installation Language & Strings
avatar joomla-cms-bot joomla-cms-bot - change - 9 Mar 2023
Category Front End Administration com_fields Language & Strings JavaScript Repository NPM Change com_users Installation Administration com_fields JavaScript Repository NPM Change Front End com_users Installation Language & Strings Libraries Plugins
avatar joomla-cms-bot joomla-cms-bot - change - 9 Mar 2023
Category Front End Administration com_fields Language & Strings JavaScript Repository NPM Change com_users Installation Libraries Plugins Administration com_fields Front End com_users Installation Language & Strings Libraries Plugins
avatar korenevskiy korenevskiy - change - 9 Mar 2023
Labels Removed: NPM Resource Changed
avatar joomla-cms-bot joomla-cms-bot - change - 9 Mar 2023
Category Front End Administration com_fields Language & Strings com_users Installation Libraries Plugins Administration com_fields Installation Language & Strings Libraries Front End Plugins
avatar joomla-cms-bot joomla-cms-bot - change - 9 Mar 2023
Category Front End Administration com_fields Language & Strings Installation Libraries Plugins Administration com_fields Installation Language & Strings Front End Plugins
avatar joomla-cms-bot joomla-cms-bot - change - 9 Mar 2023
Category Front End Administration com_fields Language & Strings Installation Plugins Administration com_fields Front End Plugins
avatar korenevskiy
korenevskiy - comment - 9 Mar 2023

@laoneo Please check.

avatar korenevskiy korenevskiy - change - 9 Mar 2023
Labels Removed: Language Change
avatar korenevskiy korenevskiy - change - 9 Mar 2023
The description was changed
avatar korenevskiy korenevskiy - edited - 9 Mar 2023
avatar korenevskiy korenevskiy - change - 9 Mar 2023
The description was changed
avatar korenevskiy korenevskiy - edited - 9 Mar 2023
avatar obuisard obuisard - change - 2 Jun 2023
Title
Fix quantity times rendering for call one custom field
Fix multiple rendering calls on custom field
avatar obuisard obuisard - edited - 2 Jun 2023
avatar korenevskiy
korenevskiy - comment - 13 Jul 2023

@HLeithner Is it possible to transfer this PR to Joomla 5 ?

avatar korenevskiy korenevskiy - change - 24 Jul 2023
Labels Added: bug
Removed: ?
avatar HLeithner
HLeithner - comment - 30 Sep 2023

This pull request has been automatically rebased to 4.4-dev.

avatar korenevskiy
korenevskiy - comment - 3 Dec 2023

Transfer this PR to Joomla 5

avatar Septdir
Septdir - comment - 4 Jan 2024

It is not correct to do this in the dislpay plugin method.
In fact, an object without jcfields can get there;
Either incorrect for a given context or parameters. For example, they were changed before the trigger was called.

avatar korenevskiy korenevskiy - change - 5 Jan 2024
Title
Fix multiple rendering calls on custom field
[Draft] Fix multiple rendering calls on custom field
avatar korenevskiy korenevskiy - edited - 5 Jan 2024
avatar HLeithner HLeithner - change - 24 Apr 2024
Title
[Draft] Fix multiple rendering calls on custom field
[4.4] Fix multiple rendering calls on custom field
avatar HLeithner HLeithner - edited - 24 Apr 2024

Add a Comment

Login with GitHub to post a comment