? Failure

User tests: Successful: Unsuccessful:

avatar Spudley
Spudley
25 Nov 2016

Pull Request for Issue # .

Summary of Changes

This is a re-submission of a previous PR 12960. I am now providing the changes suggested in comments on that PR instead of my original changes.

The change here is that JFormField::getIncludePaths() now provides the default paths from the JLayoutFile rather than providing an empty array and allowing JLayoutFile to set the defaults for itself.

The motivation for this is that when creating a new form field type by extending JFormField (or one of its subclasses), if you need to override getIncludePaths(), then JLayoutFile will only take the paths you give it and will no longer load its defaults. This means that your class does not have the option of a fall-back path.

This caused me a problem when extending the subform field type, because the nested fields within the subform also inherit its layout, and thus do not get rendered unless you've created custom layout for them all.

Please see the original PR for further explanation.

Testing Instructions

  • Create a custom field type overriding subform and implementing its own getIncludePath() method. This method should array_merge() its custom path with any returned by its parent.
  • Also have the class load some fields of any standard field types into the subform.
  • Create a custom layout file for the custom subform field type in the path you defined above, but not for any of the standard field types within the subform.
  • Without this PR, the fields within the subform will not be rendered.
  • After the PR, the fields will be rendered correctly.

Documentation Changes Required

Documentation for creating custom field types and custom layouts is currently very weak.

The Custom field types page doesn't even mention being able to use custom layouts. I know this is a niche feature, but it would be good to at least mention it, and include the fact that if you override it you should merge the results with parent::getIncludePath() to provide a fallback.

avatar Spudley Spudley - open - 25 Nov 2016
avatar Spudley Spudley - change - 25 Nov 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 25 Nov 2016
Category Libraries
avatar Spudley Spudley - change - 28 Nov 2016
Title
Explicitly include default paths.
Explicitly include default layout paths in JFormField (redux of PR 12960).
Labels Removed: ?
avatar Spudley Spudley - edited - 28 Nov 2016
avatar Spudley Spudley - change - 28 Nov 2016
Title
Explicitly include default paths.
Explicitly include default layout paths in JFormField (redux of PR 12960).
avatar Spudley Spudley - change - 28 Nov 2016
The description was changed
avatar Spudley Spudley - edited - 28 Nov 2016
avatar phproberto
phproberto - comment - 4 Dec 2016

Finally got the time to review this. I still think it's wrong. getLayoutPaths() shouldn't know anything about the renderer so passing it as parameter is not ok.

It's better to call JLayoutFile inside getLayoutPaths() than tying it to a function in the renderer because that will force to change the renderer interface to at least cover it.

So I think that based in our requirements the best solution is to add a direct call to a dummy renderer inside getLayoutPaths():

	/**
	 * Allow to override renderer include paths in child fields
	 *
	 * @return  array
	 *
	 * @since   3.5
	 */
	protected function getLayoutPaths()
	{
                $renderer = new JLayoutFile;

		return $renderer->getDefaultIncludePaths();
	}

JLayoutFile is already used in the base getRenderer() so it's ok to also add a explicit renference there to get the paths from it. That way child classes can do something like:

	/**
	 * Allow to override renderer include paths in child fields
	 *
	 * @return  array
	 *
	 * @since   3.5
	 */
	protected function getLayoutPaths()
	{
                $paths = parent::getLayoutPaths();

                array_unshift(JPATH_ROOT . '/modules/mod_mymodule/layout/', $paths);

		return $paths;
	}

and it will always return what is expected in a B/C way. I think that's the best we can do until we use containers.

avatar Spudley
Spudley - comment - 5 Dec 2016

Hi @phproberto.

Thanks for the review. You probably realise this is my first contribution to Joomla core, so it's really helpful to get feedback like this as it will help me learn for future contributions. (as a user, it's also reassuring to see this process, because it gives a lot of confidence in the final product)

I am mildly worried that having getLayoutPaths() instantiate its own renderer will mean that it isn't guaranteed to return the same default paths as the actual renderer, which is why I elected to pass the object. But it works fine in my use-case with a dummy object and I think probably most other cases too, so I agree it's not something to worry about too much.

I was going to start asking you further questions to debate it, but on reflection I think I'm content to agree with you, and I've updated the PR per your suggested code.

avatar Spudley
Spudley - comment - 13 Feb 2017

Hi @phproberto.

I know I've left this for a long time, but I wonder whether you'd be able to review it again.

I made the changes that you suggested after the previous review, so I was hoping you'd have taken a look. But that was a couple of months ago now.

If you do have a chance to take a look, I'd really appreciate it. Thank you :)

avatar roland-d
roland-d - comment - 22 Jul 2018

@phproberto Could you follow up on this? Thank you.


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

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 26 Aug 2018

If this Issue get no Response, it will be closed at 22th September 2018.

avatar franz-wohlkoenig franz-wohlkoenig - change - 23 Sep 2018
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2018-09-23 05:18:34
Closed_By franz-wohlkoenig
avatar joomla-cms-bot joomla-cms-bot - change - 23 Sep 2018
Closed_Date 2018-09-23 05:18:34 2018-09-23 05:18:35
Closed_By franz-wohlkoenig joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 23 Sep 2018
avatar joomla-cms-bot
joomla-cms-bot - comment - 23 Sep 2018
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 23 Sep 2018

This has been closed due to lack of response to the requests above – it can always be reopened.


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

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 23 Sep 2018

This has been closed due to lack of response to the requests above – it can always be reopened.


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

avatar phproberto
phproberto - comment - 15 Oct 2018

Hey @Spudley I hope you still can read this. I just realised this has been blocked by me for 2 years which is the worst thing I could do with a new contributor.

I'm really sorry. I have refreshed this PR keeping you as author in:

#22645

And added some test to cover FormField::getLayoutPaths()

I know that's not enough but I hope it helps.

Sorry again mate!

avatar phproberto
phproberto - comment - 15 Oct 2018

And thanks @roland-d for trying to take care of my blocked stuff!

avatar Spudley
Spudley - comment - 15 Oct 2018

@phproberto -- no worries ? Thank you for picking it up again.

Add a Comment

Login with GitHub to post a comment