Layout Overrides of Config Options

56 views
Skip to first unread message

Alex Chartier

unread,
Feb 3, 2021, 5:20:30 PM2/3/21
to Joomla! General Development
There does not seem to be an easy way to override the layout of fields that are part of the component configuration, i.e. the options for the component via com_config.

Stepping through the code when the layout is processed the FileLayout.php (J4) gets the layout paths but the paths are relative to com_config, not the component you are setting the options for. (I have not stepped through the code for J3 but I suspect the process is the same).

It is possible to override the layout for a particular field by setting the layout= in the config.xml (again for J4), but, these layout overrides must be in the root layouts directory and I have not found a way to have them installed into that directory during component installation via the manifest xml file.

It would be possible to do so using a pre/post flight scripts to move them there but I am not sure this is the best/correct way to do it.

My reason for doing this is to handle the differences between J3 & J4 so I can use the same installation. J3 uses type radio in layouts/joomla/form/field/radio while J4 uses layouts/joomla/form/field/radiobasic or layouts/joomla/form/field/radio/switcher. My thought was to use an override file that checked the JVersion and include the correct one. I have run into this issue though.

Anyone have any ideas?

venomDev

unread,
Feb 4, 2021, 6:09:00 AM2/4/21
to Joomla! General Development
One option that might be useful is to create a custom field that detects the Joomla version number and defines the field type to extend based on v3 or v4.
Then you should also be able to do a layout over ride.

Alex Chartier

unread,
Feb 5, 2021, 9:58:36 AM2/5/21
to Joomla! General Development
OK, so a custom field would not do it as what I really wanted was the full radio class just with a different layout. The answer ended up being to use the file type of the manifest file. The info I needed for this was in this joomla stackexchange posting: https://joomla.stackexchange.com/questions/24157/how-to-add-a-cli-file-to-the-cli-directory-as-part-of-a-component-install/28857#28857

In my package I created a new zip install for the layout files and set the target=layouts/mycomponent and then added the filename radio.php as a file in the fileset.

In radio.php I tested for the joomla version and then included (could not do include/require once as then the output would not be generated for subsequent options) the appropriate layout. I had to then set the layout in the config.xml file to mycomponent.radio

Tested on J3.9 and J4.0 Beta 7. Works as intended.

Reply all
Reply to author
Forward
0 new messages