4

Within a plugin I need to add and populate (data is available inside my plugin) a column to com_menus&view=menus view in administration.

enter image description here

my_plugin.php

...
public function onAfterInitialise()
{
    $input = JFactory::getApplication()->input;
    if (JFactory::getApplication()->isAdmin()
        && $input->getCmd('option') == 'com_menus'
        && $input->getCmd('view') == 'menus')
    {
        JRequest::setVar('view', 'menusextra');
        JLoader::register('MenusViewMenusextra', __DIR__ . '/views/menus/view.html.php');
    }
}
...

view.html.php

...
JLoader::register('MenusViewMenus', JPATH_ADMINISTRATOR . '/components/com_menus/views/menus/view.html.php');
JLoader::register('MenusModelMenus', JPATH_ADMINISTRATOR . '/components/com_menus/models/menus.php');

class MenusViewMenusextra extends MenusViewMenus
{
    public function display($tpl = null)
    {
        $this->items         = $this->get('Items');
        $this->pagination    = $this->get('Pagination');
        $this->state         = $this->get('State');
        $this->filterForm    = $this->get('FilterForm');
        $this->activeFilters = $this->get('ActiveFilters');
        $this->canDo         = JHelperContent::getActions('com_menus');
        $this->db            = JFactory::getDbo();

        $this->addTemplatePath(__DIR__ . '/tmpl/');
        parent::display($tpl);
    }
}

class MenusModelMenusextra extends MenusModelMenus {}
...

Now, I am getting the error "JForm::getInstance could not load file". Think this is due because it is not being able to load the filter_menusextra.xml, the original (core) filter_menus.xml that is located \administrator\components\com_menus\models\forms. Is it because it uses the JLayout search tools and need to load the xml file?

Made the following test: renamed filter_menus.xml to filter_menusextra.xml in \administrator\components\com_menus\models\forms and it worked. But as I am overriding it I should be able to make it inside my plugin, not the core one?! What am I doing wrong?

Could someone help me please on this? Thank you.

2 Answers 2

1

Short answer

You can't. You can only try to process system output (via application output buffer or Java Script) or changing system files.

Long answer

Menu component would have to support custom plugin events but it does not. Modifying system files is a really bad idea and I advice you to avoid it. You can try to create a system plugin that will modify application output buffer but it would be vulnerable for code changes. More bulletproof would be to do it with JavaScript/jQuery. That way small changes in code will not affect your plugin functionality. Of course it has its downsides. You can't make this column sortable and you can't search its contents.

1

To load a different filter form, override $filterFormName property in the model:

class MenusModelMenusextra extends MenusModelMenus
{
    public function __construct($config = array())
    {
        $this->filterFormName = 'filter_menus';

        parent::__construct($config);
    }
}
2
  • Modifying system models, controllers etc is THE LAST thing you want to do on Joomla! You would need either stop updating your website or bring modification back after each update. Commented Jun 5, 2019 at 23:02
  • @ArturStępień OP is doing this with a plugin, not by modifying core files.
    – Sharky
    Commented Jun 6, 2019 at 5:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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