1

I want to override the output of the select radiolist. I can hack the core, but I'm not really fond of doing that in relation to updates.

So i checked out a system plugin to override the JHTMLselect class. But I am stuck on how to implement it.

I found this topic: How to override core classes?

But it seems that it's not working properly anymore. Also I can't upload the plugin, I get an error. I have the exact code as the plugin above.

This is my code for the override:

<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  System.Overrides
 *
 * @copyright   Copyright (C) 2012 Don Gilbert. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE
 */

defined('JPATH_BASE') or die;

/**
 * System plugin to override core classes terms.
 *
 * @package     Joomla.Plugin
 * @subpackage  System.Overrides
 * @since       2.5
 */
class PlgSystemOverrides extends JPlugin
{
    /* We do our thing in the __construct method
     * so that our overridden classes will be
     * available everywhere
     */
    public function __construct(&$subject, $config)
    {
        parent::__construct($subject, $config);

        include_once 'config.php';
    }
}

That is my main php file. this is my config file

<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  System.Overrides
 *
 * @copyright   Copyright (C) 2012 Don Gilbert. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE
 */
define('OVERRIDES', dirname(__FILE__).'/overrides');

// Use JLoader to register all the classes you want to override
JLoader::register('JHtmlSelect', OVERRIDES.'/select.php', true);

My select.php file is basiscally the whole select.php file in /libraries/cms/html/select.php with a slight change in the radiolist

2

I got this working ok with just a little change from what you have above. If you can't install the plugin then maybe your filenames or folders aren't correct. Joomla is very fussy about those!

I put everything into a folder named plg_system_overrides and here are the files:

overrides.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.2" type="plugin" group="system" method="upgrade">
    <name>plg_system_overrides</name>
    <description>Plugin to override html radio select</description>
    <files>
        <filename plugin="overrides">overrides.php</filename>
        <filename>config.php</filename>
        <folder>overrides</folder>
    </files>
</extension>

overrides.php - here I think it's best to use onAfterInitialise, as described in those other answers

<?php
defined('JPATH_BASE') or die;
class PlgSystemOverrides extends JPlugin
{
    public function onAfterInitialise()
    {
        include_once 'config.php';
    }
}

My config.php is just the same as yours, and I copied the joomla libraryselect.php into an overrides folder and made a small change to the html output in the genericlist function which worked ok.

I zipped up the plg_system_overrides folder into plg_system_overrides.zip and installed this. It's worth checking that all the files you expect to see are in the Joomla plugins/system folder after you install your plugin.

Don't forget to enable your plugin via the admin / plugins page!

I tested it by inserting into a random site component layout file

<?php echo JHtml::_('select.genericlist', array('a', 'b', 'c'), 'testselect'); ?>

and I could see the change when I used the browser devtools to inspect the html.

|improve this answer|||||
  • Thanks for the answer, I'll check this out ASAP and mark it as solved if this actually works. Thanks again for your response! – Huub S Mar 22 at 14:52
  • Works great, thank you!!! – Huub S Mar 23 at 8:20
2

You can override specific methods using JHtml::register().

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\CMSPlugin;

class PlgSystemOverrides extends CMSPlugin
{
    public function onAfterInitialise()
    {
        if (!HTMLHelper::isRegistered('select.radiolist'))
        {
            HTMLHelper::register('select.radiolist', array(__CLASS__, 'radiolist'));
        }
    }

    public static function radiolist()
    {
        // Your custom function here.
    }
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.