-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Introduce predefined path in plugins, modules, templates for custom fields in the manifest file #4294
Conversation
Simple addition to allow plugins to use custom fileds in a directory named ```fields```. There shouldn't be any B/C breaks here.
I'm not sure what the purpose is. It's already possible to use custom fields by providing the addfieldpath to the XML. |
@Bakual three things are done with this simple line of code:
|
Hmm, so instead of "hardcoding" the path it in the XML, we hardcode it in the model.
Actually, you introduce a new way to do things. Now one could either use the predefined path or specify an own in the XML. But only in plugins and templates. Components and modules would need additional PRs to be in line with this change, right?
A tiny bit, yes. However I have to say it's very simple to add this attribute to the XML. This option needs to stay anyway, because extensions may have their fields in a library or other places. I'm not sure if I like it or not. It's only a tiny gain imho at the cost of adding a tiny bit of additional complexity to the system. Let's see what others think. Can you maybe adjust the title and description of the PR? Currently it's misleading as it has nothing to do with allowing custom fields for plugins (or templates). That is already possible without any issues by providing the addfieldpath attribute in the XML. |
I put it as a new more standardized workflow, but that maybe only my opinion 😃
And there is gonna be another predefined path
It’s not that complex, imho, the admin components just have a check if the The concept is simplicity, transparency and unification but to be honest I don’t know if the outcome justifies that. More options here are welcome |
Don't understand what you meant to say. Do see that you don't want to use JPATH_COMPONENT_ADMINISTRATOR for some reason. From a programming point of view consider your code wrong. The constant JPATH_COMPONENT_ADMINISTRATOR is declared a few lines up, you have a chance to use it, but choose to recalculate it. Apart from the fact it is inconsistent it is bad programming! |
No, use JPATH_COMPONENT_ADMINISTRATOR in both if and addFieldPath instead of calculating it twice! |
@sovainfo Honestly is late, you are right I PR the change |
tried to do that as well, can't pr your pr! |
@sovainfo Did I get it right now? 😕 |
Nice change 👍 |
@@ -322,6 +322,21 @@ public static function renderComponent($option, $params = array()) | |||
throw new Exception(JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'), 404); | |||
} | |||
|
|||
if (JPATH_COMPONENT == JPATH_COMPONENT_ADMINISTRATOR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't a simple
if (is_dir(JPATH_COMPONENT . '/models/fields'))
{
JForm::addFieldPath(JPATH_COMPONENT . '/models/fields');
}
do the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, would prefer that over the current lines 325/339
Some documentation updates needed if this gets approved. |
@@ -555,6 +555,8 @@ public function getForm($data = array(), $loadData = true) | |||
$id = JArrayHelper::getValue($data, 'id'); | |||
} | |||
|
|||
JForm::addFieldPath(JPATH_BASE . '/modules' . '/' . $module . '/fields'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't work that easy. JPATH_BASE will be pointing to admin when the module is edited in backend and to site when it is edited in frontend. At the same time we have both backend and frontend modules.
So what you need here is load the folder depending on the $clientId
:
$baseFolder = ($clientId) ? JPATH_ADMINISTRATOR : JPATH_SITE;
JForm::addFieldPath($baseFolder . '/modules' . '/' . $module . '/fields');
Disagree on removing the path existence check. Considering the amount of processing don't think it is a good idea to introduce a lot of paths that don't exist. It does take memory and cpu, why waste it? |
I'm sure you will not be able to measure the difference. It's only a single path added. We also do a lot more such path checks for our override system, class autoloading and many more. It's not something which uses lot of ressources to process. On the other hand, adding |
Can't take those arguments seriously. But have no interest to continue that discussion with someone I consider unreasonable. @dgt41 Apologize for assisting you, looks like my input is not appreciated and will cause it not to be implemented. Sorry, maybe there are others that do understand the importance. |
@sovainfo On the above argument I think what @Bakual says, and he is correct, is that if we do a path existence check here we are gonna repeat the procedure when we actually gonna add the fields. On the other hand the majority of modules, plugins and templates don’t use custom fields, so maybe it will be beneficial not to introduce them in the first place, and thus save some resources. Both ways are fine for me, because in either of them the harm of not doing it the other way is really marginal. |
Either way will work. On the other hand it makes the code harder to read if you have
instead of
On a sidenote: Performance is important for pages which are shown to visitors on a regular basis. Performance doesn't really matter that much if we're talking about administrator views like we're talking here. It's not like you're going to request a module edit view several times per second. For me, code readabilty wins hands down in this case. But it may be a personal preference. I don't care that much honestly. |
I guess I’ll better leave it as is right now, till we get some more input. And if it gets some attention and successful tests I will also provide the documentation changes needed as well. |
Should I apply only this PR to test it? |
I will break this to three PRs with some dummy template, module, plugin to make testing easier |
@dgt41 @Bakual @sovainfo Why don't we make the |
Sorry replied to wrong post |
@izharaazmi you got a point here! |
@izharaazmi Sounds good to me in this case. Normally not in favor of postponing things but it looks like that is the right place to avoid adding non-existing folders to the path. This should definitely be applied to J3, finally dealing with the inconsistency of suggesting the folder can be named different from administrator and hardcoding it in the rest of the software. |
@@ -555,6 +555,10 @@ public function getForm($data = array(), $loadData = true) | |||
$id = JArrayHelper::getValue($data, 'id'); | |||
} | |||
|
|||
// Add the default fields directory | |||
$baseFolder = ($clientId) ? JPATH_ADMINISTRATOR : JPATH_SITE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we use JPATH_BASE here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For modules and templates JPATH_BASE won't work as the com_modules and com_templates (in administrator) need to know if the module or template in question is front end or backend. Using JPATH_BASE will always fall back to administrator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, I missed that the clientId
comes from the data and not the current active client.
Simple addition to allow components, plugins, modules and templates to use custom fileds in a sub-directory named
fields
.This is an alternative way to use custom fields in these areas besides the classic hardcoding
addfieldpath=“wherever"
. Should make things a bit easier for devs without introducing complicated and slow procedures (only one directory check is actually used).Pros
Predefined workflow
Easier implementation
No need for hardcoded paths in xml
Unified method that works along the existing hand coded
addfieldpath=“wherever"
Against
Adds one more directory with predefined name
Adds some more calls for every template, module, plugin in the pile of execution code.
There shouldn't be any B/C breaks here.
How to test
For plugins:
apply this patch
apply also patch #4240
open /plugins/editors/tinymce/tinymce.xml and remove:
addfieldpath="/plugins/editors/tinymce/fields”
from the line:
<fieldset name="basic" addfieldpath="/plugins/editors/tinymce/fields”>
Go to admin and observe that the fields site skins and administrator skins are still functional.
For templates check the instructions at #4295
For modules repeat the instructions of plugins but for any module you choose. For a custom field code just use the one from the tinymce and it should work (you only need to see it rendering the functionality is not essential here). So for mod_breadcrumbs:
open mod_breadcrumbs.xml and paste
<field name="skin_admin" type="skins" description="PLG_TINY_FIELD_SKIN_ADMIN_DESC" label="PLG_TINY_FIELD_SKIN_ADMIN_LABEL" > </field>
under the fieldset=“basic”
copy the folder
fields
from the plugin tinimce [the plugin test abobe]check in the admin module breadcrumps for the new option
For components:
This is already the standard for components. Custom fields expected to be found at
com_name/models/fields
Also try that 3PD plugins, modules and templates don't misbehave!