Skip to main content
2 of 2
Commonmark migration

Core Component Layout Override with Plugin

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.

n.h.
  • 871
  • 6
  • 17