-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[5.3] Allow adding additional layout base path to form fields #44590
base: 5.3-dev
Are you sure you want to change the base?
Conversation
If I understand this correctly (and I'm not certain that I do) this will add a layout in a location that cannot be overriden by the template |
I am not sure what you trying to do, but when you need such thing you doing something wrong 😉 Developers already can set differemy layout per field with |
I guess the only missing area is the xml, so there a template call could be added. The other two options can be added by the plugin author.
Load a form via com_ajax and a plugin. There is no way to provide any layout via the plugin when you add a new field by your own, because Joomla looks into com_ajax and the template, that's it. |
A plugin author should not need to do anything in order for a template to create and use an override. There should be no dependence in the relationship |
For this case need to set Component and Client
However we cannot expose every possible options of the Layout Class to the Field class, it will be just bad. joomla-cms/libraries/src/Form/FormField.php Line 1387 in 689cde9
Which developer can overdie in its field class, and set required options. The approach suggested in the PR have other drawbacks and will not work in all cases, but that is to much to write :) |
To be honest, I have exactly this particular problem. It feels much cleaner to me personally to be able to insert my Web Component directly into renderField as a wrapper around the standard fields instead of having to inherit every single standard field and then just overwrite the layout path. I don't want to reinvent the wheel, but simply extend the existing one. But then I'm probably doing something wrong. @Fedik 😉 |
To solve the issue with renderField it better that way #42648 (comment) , or override the field layout. The Form Field class should only recieve the layout ID, nothing else. And how it going to be rendered is defined by renderer inside getRenderer method. (Would be nice to think a way to define a global renderer per form, but that another topic) Addittionaly, the getField() method always return new field instance, and so if you do |
Summary of Changes
Currently the usage of form field layouts is very encapsulated in the FormField class, which means that it's not possible to change/add additional layout include paths via e.g. plugins.
There are three ways to add an alternative path
->addLayoutPath($path)
method$option
attribute in the->renderField(...)
or->renderFieldset(...)
methodsTesting Instructions
There are several ways to test this PR, one would be to create a plugin and manipulate the form with the onContentPrepareForm event.
But to the test the raw functionality you can do the following:
joomla/form
to the "otherlayouts" folderlayouts/joomla/form/renderfield.php
to the new pathOption 1:
components/com_users/forms/registration.xml
layoutIncludePath="otherlayouts"
(it should be in the "name" field)Option 2:
components/com_users/tmpl/registration/default.php
<?php echo $this->form->renderFieldset($fieldset->name, ['layoutIncludePath' => JPATH_ROOT . '/otherlayouts/']); ?>
Option 3:
components/com_users/tmpl/registration/default.php
Actual result BEFORE applying this Pull Request
Expected result AFTER applying this Pull Request