? Pending

User tests: Successful: Unsuccessful:

avatar laoneo
laoneo
22 Nov 2016

Pull Request for Issue #12732.

Summary of Changes

As we have different contexts between front end and back end for the same action, this PR introduces a callback functionality that a component can map contexts.

  • Additionally a potential BC break will be reverted where the form name for the contact form was changed.
  • An unnecessary DB query could be removed.

What can be discussed is to merge the *HelperFields classes in the basic *Helper classes as they mostly exist already.

Testing Instructions

  • Save users and articles on front and back end.
  • Create some custom fields for the contacts mail context
  • Make a contact form menu item and do the request

Expected results

All should work as without the patch. Fields should be saved and the contact mail should contain the custom fields.

avatar laoneo laoneo - open - 22 Nov 2016
avatar laoneo laoneo - change - 22 Nov 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 22 Nov 2016
Category Administration com_contact com_content com_fields com_users Front End Plugins
avatar laoneo laoneo - change - 22 Nov 2016
The description was changed
Labels Added: ?
avatar laoneo laoneo - edited - 22 Nov 2016
avatar Bakual
Bakual - comment - 22 Nov 2016

What can be discussed is to merge the *HelperFields classes in the basic *Helper classes as they mostly exist already.

I think that's a good idea. Especially since we have some fields related stuff there already anyway (the sidebar links).

What do you think about making sure we always return a valid context? Currently we return the passed section if we're in backend without looking at it. May be worth to sanitise that and return a default one if the passed-in section isn't know.
Like if (!in_array($section, array('article', 'category', 'form')) {return 'article';}?

avatar laoneo
laoneo - comment - 23 Nov 2016

What do you think about making sure we always return a valid context

I would not as there will be a reason why another context is returned.

avatar Bakual
Bakual - comment - 23 Nov 2016

I would not as there will be a reason why another context is returned.

It is basically a user input (from the URL) you take there. It could be anything.
Shouldn't the component know itself which contexts are valid? At least for my extension and for core I can't think of a case where there would be another context passed which should be allowed to be proceed.

avatar laoneo
laoneo - comment - 23 Nov 2016

But then should null being returned and not the default context?

avatar Bakual
Bakual - comment - 23 Nov 2016

But then should null being returned and not the default context?

Depends what your code does with it. Ideally, you would return false if the context isn't valid and the whole process gets cancelled with an error message.
But we can also take a route where we just assume the user wanted to do the default action instead and work with a default context. I don't care much here.

avatar laoneo
laoneo - comment - 25 Nov 2016

Moved the functions to the component helper classes and returning null when the section is not known. Any more concerns ;)

avatar Bakual
Bakual - comment - 25 Nov 2016

Looks good to me. Thanks ?

avatar laoneo
laoneo - comment - 29 Nov 2016

Could you test it?

avatar Bakual
Bakual - comment - 1 Dec 2016

I have tested this item successfully on 699974f


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

avatar Bakual Bakual - test_item - 1 Dec 2016 - Tested successfully
avatar Hackwar
Hackwar - comment - 14 Dec 2016

Can we PLEASE name the methods in a sane way? getRealSection() has no meaning for me at all. The comments are equally unhelpfull. We need method names (and attribute names) that are self-explanatory.

avatar Bakual
Bakual - comment - 14 Dec 2016

@Hackwar Any idea for a better name? The issue comes from the fact that frontend uses a different context for its form than the backend. So we need a way to map that context to the one used for fields (the backend one usually). Section means the second part of that context (taken from categories where it is component.section).

avatar Hackwar
Hackwar - comment - 14 Dec 2016

To begin with, the helper of the administration application should never be called in the frontend, so I don't see the reason for the check for the application in there. If you need to check both in front- and backend, create a helper in front- and backend. And then I would expect the forms to have the same context in front- and backend. Now that isn't the case right now, so we need a solution at least until we are at 4.0. I don't know the whole workflow of fields, but I would expect there to be a place somewhere in the model, where we can do a preprocess/postprocess step and where this can be implemented, instead of having such an extremely specific method. If you disagree completely here, at least name it something like "translateContext()" and hand in the full context. But as I said, rather drop the whole method and translate this somewhere in the respective model.

avatar Bakual
Bakual - comment - 14 Dec 2016

The way com_fields work, you can't use the model. It works using the various existing plugin events. The context of those events differ between front- and backend. If they should be the same or not isn't relevant here, fact is they are different and we need to map them.

One could argue indeed that this should be a frontend helper method, however there may also be cases where the context needs to be mapped in backend as well. Plus the plugin itself is the same for front- and backend. So the application check is either done in the plugin and the appropriate helper loaded or we do that check in the helper if it's needed. I think the check isn't really needed (but imho doesn't hurt) except for com_contact.
Personally as an extension developer I prefer having only one helper instead of doing duplicate work. It also keeps all fields specific code in said helper.

If you disagree completely here, at least name it something like "translateContext()" and hand in the full context.

What would be the purpose of the full context? The helper is called based on the first part of that context, so it will always be the helpers component. There is no point comparing the full context here, we only need the second part (section).
"translateContext" isn't appropriate either. At least myself I would expect it to translate something into another language. Imho, that method also could be useful for other extensions in future if they need to map the section between front and backend. So a name relating to com_fields would be wrong as well.

avatar Hackwar
Hackwar - comment - 15 Dec 2016

I'm still looking through the code of the fields feature, but right now I don't really understand why we are having these methods in there in the first place. To me it looks as if this could be done with a simple mapping array in the helper class of each component (where necessary) and one central method in the helper classes base class. All of that under the assumption that this is even a good way to solve the issue that you are trying to solve.

avatar Bakual
Bakual - comment - 15 Dec 2016

A method in the base class would likely work for most extensions I think. But especially com_contact is a beast as it has two different contexts (the contact and the mailform) and to make things interesting the frontendcontext "contact" relates to the mailform and in the backend it relates to the contact. That's why we need the check for the application in that specific case. I know, stupid context naming but we can't change that currently.

avatar Hackwar
Hackwar - comment - 15 Dec 2016

Again: Provide a class for the backend and one for the frontend and you don't have to do any checks here. It can simply be a mapping array instead.

avatar Bakual
Bakual - comment - 15 Dec 2016

What do you gain by having two helpermethods doing the same instead of one? Keep in mind that this check comes from a plugin, which means you just move the (optional) check for the application to the plugin to determine the correct helper. In the plugin it would be a required check.
For the developers it means creating a helper class with a (more or less) duplicated method.

The helper class itself is being used in frontend already anyway (eg for ACL stuff). So I don't see why you have an issue with it. And we several other instances where we load something from backend in frontend, that is not unusual.

avatar Bakual
Bakual - comment - 15 Dec 2016

It can simply be a mapping array instead.

What I do for my extension is like this:

$mapping = array(
	'sermon'         => 'sermon',
	'frontendupload' => 'sermon',
	'speaker'        => 'speaker',
	'speakerform'    => 'speaker',
	'serie'          => 'serie',
	'serieform'      => 'serie',
);
return isset($mapping[$section]) ? $mapping[$section] : null;

But it depends on the extension if it can be done that simple or not.

avatar laoneo
laoneo - comment - 15 Dec 2016

The code how it is now makes sense and is needed. What we can discus is the name and the documentation which should be improved. I'm up here for suggestions.

avatar laoneo
laoneo - comment - 23 Dec 2016

Any suggestions?

avatar Bakual
Bakual - comment - 23 Dec 2016

What about verifySection as function name instead of getRealSection?

avatar ggppdk
ggppdk - comment - 23 Dec 2016

What about:
getCustomFieldsSection()
or
getFieldsSection()

avatar Bakual
Bakual - comment - 23 Dec 2016

It may be useful for other cases as well in future. So I wouldn't tie it directly to com_fields.

avatar ggppdk
ggppdk - comment - 23 Dec 2016

The code how it is now makes sense and is needed.

yes it is needed , and i am happy to see it

It may be useful for other cases as well in future. So I wouldn't tie it directly to com_fields.

I was not aware of this, do you have an example ?

avatar Bakual
Bakual - comment - 23 Dec 2016

I was not aware of this, do you have an example ?

Each time you need to map the context used by frontend models to those used in backend you could need this method. I don't have a specific example in mind currently.

avatar laoneo
laoneo - comment - 23 Dec 2016
  • When I see verifySection, then I expect to get a boolean back.
  • getFieldsSection says for me not more than getRealSection.

Going a step back, what does the function do? It returns a section where fields are created for already. getMappedSection perhaps?

avatar Bakual
Bakual - comment - 23 Dec 2016

When I see verifySection, then I expect to get a boolean back.

Hmm, it's an argument.
JModelForm has a method validate() which returns the sanitised data. maybe we can use that term as it is already used for a smilar behavior? So validateSection?

avatar Bakual
Bakual - comment - 23 Dec 2016

getMappedSection could work as well.

avatar laoneo
laoneo - comment - 23 Dec 2016

validateSection sound's not too bad either.

avatar laoneo
laoneo - comment - 28 Dec 2016

Changed function name to validateSection.

avatar anibalsanchez
anibalsanchez - comment - 3 Jan 2017

I have tested this item ? unsuccessfully on 5117825

When I try to add a field:

Call to undefined method FieldsHelper::addSubmenu()


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

avatar anibalsanchez anibalsanchez - test_item - 3 Jan 2017 - Tested unsuccessfully
avatar Bakual
Bakual - comment - 3 Jan 2017

@anibalsanchez Can you try again? It may have been an outdated branch here. I've updated it now with staging.

avatar laoneo
laoneo - comment - 4 Jan 2017

I guess @anibalsanchez needs to update his Joomla installation to the latest staging.

avatar anibalsanchez
anibalsanchez - comment - 5 Jan 2017

I have tested this item successfully on 11f3770

It seems to be working OK.

But, it is showing a notice. It could be related to a different issue:

Notice: Undefined property: stdClass::$assigned_cat_ids in ..../administrator/components/com_fields/helpers/fields.php on line 471


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

avatar anibalsanchez anibalsanchez - test_item - 5 Jan 2017 - Tested successfully
avatar laoneo
laoneo - comment - 5 Jan 2017

@anibalsanchez this should be solved with pr #13334.

This one can be put on RTC as only function names have changed, nothing else. For that we have two successful tests.

avatar zero-24 zero-24 - change - 5 Jan 2017
Milestone Added:
Status Pending Ready to Commit
Labels Added: ?
avatar rdeutz rdeutz - change - 5 Jan 2017
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2017-01-05 19:43:14
Closed_By rdeutz
Labels
avatar rdeutz rdeutz - close - 5 Jan 2017
avatar rdeutz rdeutz - merge - 5 Jan 2017

Add a Comment

Login with GitHub to post a comment