Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[com_fields] field layout called 4 times even though automatic display is set to 0 #16775

Closed
obuisard opened this issue Jun 19, 2017 · 11 comments

Comments

@obuisard
Copy link
Contributor

obuisard commented Jun 19, 2017

Steps to reproduce the issue

Instantiate any custom field (of type 'text' for instance), set the 'automatic display' to 'no'.
Set a value for this field in an article.
Create a menu item for that single article.
Load the page in the frontend for that menu item.

Expected result

The custom field value should not show.

Actual result

The custom field value does not show, yet the layout file /tmpl/the_custom_field.php has been called 4 times.

System information (as much as possible)

Joomla 3.7.3 beta, PHP 7.1.0

Additional comments

Preparing the values in getFields() from the helper file is the issue, I think. Fields are 'prepared' before being removed from the list of fields to display.
Therefore, any code that is used to 'prepare' the value in the layout of the field is called multiple times rather than being done only once (or not at all when dynamic display is set to 0).

That means, if you need lo load an external script library for your custom field, for instance, the library will be loaded on the page even though the field does not show.

@obuisard
Copy link
Contributor Author

onCustomFieldsPrepareDom tests the 'show_on' option. Why not onCustomFieldsPrepareField ? There is no point to prepare a field for the site if it is only meant to be seen in the admin console. That would already take away the multiple 'preparing' of layouts in the frontend that are not needed.

@ghost
Copy link

ghost commented Jun 20, 2017

@laoneo can you please have a Look on this?

@laoneo
Copy link
Member

laoneo commented Jun 22, 2017

Can you show me exactly which layout is called 4 times? There are layouts in use to create the HTML value for the field and layouts which are used for automatic display.

@obuisard
Copy link
Contributor Author

I don't understand the distinction you are making.

I am talking about
plugins -> fields -> [field name] -> tmpl -> [field name].php

I came upon this by creating my own plugin.
[field name].php being called several times although the field is automatically displayed to 'not show' (value of 0).

Thank you!

@laoneo
Copy link
Member

laoneo commented Jun 22, 2017

That's why I was asking. This layout is called to create the value parameter of the field itself. The layout which is called for automatic display is render.php.

@obuisard
Copy link
Contributor Author

I understand that.

What I don't understand is the fact that, when displaying fields on the site (frontend), all fields are selected, 'prepared' then removed if set to 'no show'. Even if they are only meant to be shown on the administrator side only.

When creating a new custom field, are we supposed to create 2 layouts then?
One in plugins -> fields -> [field name] -> tmpl -> [field name].php and one in ?

@obuisard
Copy link
Contributor Author

That is something I did not notice sooner, I just noticed it while creating a new field.
There may be something I am missing here :)

@Quy
Copy link
Contributor

Quy commented Oct 1, 2017

Is this a duplicate issue of #17889 with PR #17895?

@ggppdk
Copy link
Contributor

ggppdk commented Oct 1, 2017

Yes

@joomla-cms-bot
Copy link

Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/16775

@ghost
Copy link

ghost commented Oct 1, 2017

closed as duplicate Report #17889.

Thanks for Hint @Quy.


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants