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
Support a 'basedir' attribute in filelist and folderlist #20344
Support a 'basedir' attribute in filelist and folderlist #20344
Conversation
One thing I'm not so sure about here is I guess it could even be better than that. We could have |
By the way, this drone failure is nonsense. |
*/ | ||
protected function getBaseDir($basedir = '') | ||
{ | ||
// Basedir is any of the JPATH constants, resolve it |
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.
How about checking for empty value first?
if ($basedir === '')
{
return '';
}
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.
Right. I guess it couldn't hurt.
Yes better not introduced 2 hard coded cases for com media please add it as you suggested component:com_media:file_path, You can just add support for component parameters now if you add for plugin it should also include folder too
|
The filelist and folderlist fields do not have a connection to com_media and should not. If you want to make one which depends on com_media then you need to create your own mediafolderlist form field. |
I've removed any reference to any specific component and used the more generalized method as discussed. You can get a basedir value from the params of any component, plugin, library (I know, right?), or module (OK, this one is kinda funny). I also noticed that there are some standard joomla plugins that use this type of field with directory set to 'images'. This is obviously a problem if the user changes his images directory to something else. So those plugins are probably currently broken if you have a custom images directory. With this patch, we can fix them. |
* Method to resolve the optional base directory as one of several configuration-dependent values | ||
* The base dir can be any of the defined 'JPATH_' constants or one of the directories configured by com_media | ||
* | ||
* @param string $basedir The name of one of the 'JPATH_' constants, 'file_path', 'image_path', or empty |
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.
'file_path', 'image_path',
are no longer applicable.
It seems to me that these two classes are 90% identical code. Could be that they should both inherit from some abstract 'filesystemitemlist' class or something like that. In fact, maybe that's not even necessary. filelist could probably inherit from folderlist and just override two or three functions. Am I wrong? Traits could also be a solution except that they aren't available before php 5.4. |
Sorry that it took so long to respond. This is here is a nice feature, unfortunately it should be added to Joomla 4. Can you rebase the pr to the 4.2-dev branch, so we can test it properly. In the meantime I'm closing the pr, when ready please reopen again. Thanks for your contribution making Joomla better. |
Summary of Changes
Added support for a
basedir
attribute inJFormFieldList
andJFormFieldFolderList
andJFormFieldFileList
. This allows the field to be configured such that thedirectory
attribute is relative to one of several directories which can't be known ahead of time since their values can be changed by the user. Specifically, these are theJPATH_
constants and parameter values from various extension types.Testing Instructions
Add a
filelist
orfolderlist
type field to anyjform
. Notice what happens when the field has abasedir
attribute which may be set to any of:file_pathimage_pathcomponent:com_media:file_path
)library:joomla:param_name
, note: Joomla libraries do not actually have params)module:mod_menu:some_menu_title:param_name
)plugin:system:myplugin:param_name
)So, here's a pretty real test:
Go to the media manager and change the location of the files and images directories.
Go to the plugin settings for 'Fields - Imagelist' plugin.
This plugin is supposed to show a list of directories in the
images
directory but it will not be your new customimages
directory, it will always just list the contents of/images
which isn't very useful.With this patch, that field can be configured with
basedir="component:com_media:image_path"
anddirectory="/"
and it should show the correct contents.Expected result
Without any
basedir
attribute, thedirectory
attribute will be relative to the root of the Joomla intallation. With abasedir
, it will be relative to that directory.Actual result
All good.
Documentation Changes Required
Maybe a little.