Page 1 of 1

Override module xml

Posted: Sun Oct 02, 2011 1:33 pm
by soundblab
Is there anyway to overrride a default module xml file?

I want to add some custom fields to mod_articles_news, but to avoid messing with the core I'd ideally like to store my customised mod_articles_news.xml within my template directory.

I tried storing it at the following location, but it doesn't appear to work:

templates/mytemplate/html/mod_articles_news/mod_articles_news.xml

Any pointers would be very helpful!

thanks

Re: Override module xml

Posted: Thu Oct 06, 2011 2:22 pm
by coquin
I broke my head over this question, but it seems it's not possible to override the xml.
I bypassed the problem cloning the module (mod_custom in my case): I'm quite satisfied with this solution, even if the procedure is a bit complicated and I have to pay attention to joomla upgrades.
if you are interested I can give you the procedure I followed.
bye
ruggero

Re: Override module xml

Posted: Sat Oct 08, 2011 8:27 pm
by soundblab
Thanks ruggero - I ended up doing the same

Re: Override module xml

Posted: Thu Oct 13, 2011 1:04 pm
by RedEye
This is sadly the only solution for this, what is a pain when you need an extra field to more than one module :(

Re: Override module xml

Posted: Thu Oct 13, 2011 2:17 pm
by coquin
yes it is! as regards mod_custom, the only arrangement is to create a custom module with many parameters, all that you think you may need in future, and then override it time by time. in Italy we say (literal translation): "in the more stays the less".

Re: Override mod_footer.xml

Posted: Wed Jun 18, 2014 6:30 pm
by jackrabbit
Just wanted to revive this topic in search of a solution to dynamically add fields to a specific module xml. Specifically add pretext and posttext textarea fields to collect content for frontend display in mod_footer.

I created a plugin which does what I need but does so for every installed module and I only want to target the mod_footer.

This is the plugin

Code: Select all

jimport('joomla.plugin.plugin');
jimport('joomla.html.parameter');
jimport( 'joomla.form.form' );

class plgSystemAdd_Xml_Fields extends JPlugin {
	var $_params;
	var $_pluginPath;

	public function __construct($subject, $config) {
		parent::__construct($subject, $config);
		$this->_plugin = JPluginHelper::getPlugin('system', 'add_xml_fields');
		$this->_params = new JParameter($this->_plugin->params);
	}

	public function onContentPrepareForm($form, $data) {
		if ($form->getName()=='com_advancedmodules.module' || $form->getName()=='com_modules.module') {
			JForm::addFormPath(JPATH_PLUGINS.'/system/add_xml_fields/');
			$form->loadFile('fieldlist', false);
		}

	}
}
Then to add textarea fields, the fieldlist.xml file included in the plugin directory is

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="params">
	<fieldset name="advanced">
	<field type="spacer" hr="true" />
		<field name="pretext" type="textarea" default="" cols="40" rows="5" label="Pre Text" filter="raw" description="Text before" />
		<field name="posttext" type="textarea" default="" cols="40" rows="5" label="Post Text" filter="raw" description="Text after" />
	</fieldset>
</fields>
</form>
What can I add to the function to make this add the fields only to mod_footer?

Re: Override module xml

Posted: Fri Jun 20, 2014 6:59 pm
by jackrabbit
Does anyone have any idea how to isolate a module for field insertion? The fields shown in the image appear in all modules but I want the post and pretext to be assigned to just mod_footer
added-fields.jpg

Re: Override module xml

Posted: Sun Apr 16, 2017 2:03 am
by usielalmeida
jackrabbit wrote:Does anyone have any idea how to isolate a module for field insertion? The fields shown in the image appear in all modules but I want the post and pretext to be assigned to just mod_footer added-fields.jpg
I was solved this:

In my case I put in XML option to choose the modules, the xml file names and the custom location of the XML

Code: Select all

<fields name="params">
            <fieldset name="basic">
             <field name="themodules" type="text" label="MODULES" description="MODULES_DESC" default="mod_articles_latest" />
             <field name="filenames" type="text" label="FILES" description="FILES_DESC" default="" />
             <field name="thepath" type="list" label="PATH" description="PATH_DESC" default="plugins">
             <option value="plugins">PLUGINS</option>
             <option value="template_override">TEMPLATE_OVERRIDE</option>
             </field>
		    </fieldset>
        </fields>
Then, in the php I put the conditions to load the module. In the case I use "if ($data->module==$themodule) " conditional. Like this:

Code: Select all

jimport('joomla.plugin.plugin');
jimport('joomla.html.parameter');
jimport('joomla.form.form');
class plgSystemAdd_xml_fields extends JPlugin
{
    var $_params;
    var $_pluginPath;
    public function _construct($subject, $config)
    {
        parent::_construct($subject, $config);
        $this->plugin = JPluginHelper::getPlugin('system', 'add_xml_fields');
        $this->params = new JParameter($this->plugin->params);
    }
    public function onContentPrepareForm($form, $data)
    {
        $app        = JFactory::getApplication();
        $pieces     = explode(",", $this->params->get('filenames'));
        $themodules = explode(",", $this->params->get('themodules'));
        if ((($form->getName() == 'com_advancedmodules.module') || $form->getName() == 'com_modules.module')) {
            if ($this->params->get('thepath') == 'plugins') {
                JForm::addFormPath(JPATH_PLUGINS . '/system/add_xml_fields/');
            }
            if ($this->params->get('thepath') == 'template_override') {
                foreach ($themodules as $key => $themodule) {
                    if ($data->module == $themodule) {
                        $db    = JFactory::getDBO();
                        $query = "SELECT template FROM #__template_styles WHERE client_id = 0 AND home = 1";
                        $db->setQuery($query);
                        $defaultemplate = $db->loadResult();
                        JForm::addFormPath(JPATH_SITE . '/templates/' . $defaultemplate . '/html/' . $themodule . '/');
                    }
                }
            }
            foreach ($themodules as $key => $themodule) {
                if ($data->module == $themodule) {
                    foreach ($pieces as $k => $piece) {
                        $form->loadFile($pieces[$key], false);
                    }
                }
            }
        }
    }
Using $data->module is possible to choose the module for use.
In my case, each module name separated by commas loads the respective xml file name separated by commas. On by One.

But, now I have a new problem. The module is not saving the params in the database.
Please, someone, have a solution.