4

I've been racking my brain how to add links to all the views of my component in the shiny new Joomla4 backend; I used to do it via JSubmenuHelper, but that, apparently being deprecated also before, has now been completely removed.

I've tried what's mentioned here: How do I apply JHtmlSidebar to add a sidebar to my admin view? , i.e., in the views, I call first the addSubmenu function of the helper (which in turn uses JHtmlSidebar::addEntry), then JHtmlSidebar::render in my view.html.php (in the display method of the JViewLegacy-derived class there).

But I don't get any menu entries for my component. The "default" view shows up fine, but I don't get submenu entries or tabs to link to the other views of my component. There are no errors in the browser or in the logs; I just don't get any indication of the submenu on the left. Edit: I don't get it to run with JHtmlSidebar in J3 as well. There must be something I'm missing. Here's my code: In the view.html.php:

class mycomponentViewblocklist extends JViewLegacy
{
  function display($tpl = null) {
    // other stuff...
    mycomponentHelper::addSubmenu('myview');
    $this->addToolBar();
    $this->sidebar = JHtmlSidebar::render();
    parent::display($tpl);
}

In helpers/mycomponent.php:

class mycomponentHelper extends JHelperContent
{
  public static function addSubmenu($vName)
  {
    JHtmlSidebar::addEntry(
        JText::_('COM_MYCOMPONENT_SUBMENU_MYVIEW'),
        'index.php?option=com_mycomponent&view=myview',
        $vName == 'myview'
    );
    // ...

This does not work in J3 and J4, while using JSubMenuHelper::addEntry instead of JHtmlSidebar::addEntry does work in J3. What else is required? Do I need to add something in my tmpl folder?

I can't see any obvious difference to what I'm doing in comparison to the com_banner component, which gets a nice submenu with all its four views as link entries (edit: see my answer below about the submenu; I misunderstood where that came from; but it also has a nice sidebar on the left in addition to the submenu).

For all the announcement of Joomla4, so far I have seen relatively little in terms of migration guides for J3 / J2 components, could anybody point me in some direction there maybe, if this could help the issue here?

  • The only source I found so far is this one: docs.joomla.org/… More input and descriptions of new implementation approaches are welcome. – Sven Bluege Feb 26 '18 at 21:42
2

Finally figured it out - my problem is a missing placeholder in the tmpl (which was not required for JSubMenuHelper). Added this to my tmpl/default.php, now it works:

<div id="j-sidebar-container" class="span2">
    <?php echo $this->sidebar; ?>
</div>

The submenu in banners I was wondering about is actually done via the manifest file, there are entries like this:

<administration>
  <menu img="class:banners">com_banners</menu>
  <submenu>
    <!--
      Note that all & must be escaped to &amp; for the file to be valid
      XML and be parsed by the installer
    -->
    <menu
      link="option=com_banners"
      view="banners"
      img="class:banners"
      alt="Banners/Banners"
      >
      com_banners_banners
    </menu>
    <menu
      link="option=com_categories&amp;extension=com_banners"
      view="categories"
      img="class:banners-cat"
      alt="Banners/Categories"
      >
      com_banners_categories
    </menu>
    ...

These are responsible for creating the submenu both in J3 and J4.

  • Note that in J4, you should use col-md-X instead of span2 as we don't use Bootstrap 2 anymore – Lodder Feb 27 '18 at 23:33
  • Thanks! Copied that bit from the banner component, so it should be changed there too :D – codeling Feb 28 '18 at 8:06
  • Definitely not in com_banners for Joomla 4 having migrated all the view myself :) – Lodder Feb 28 '18 at 8:39
  • could have been the J3 banners component as well, sorry for throwing around accusations before checking ;) – codeling Feb 28 '18 at 8:43
  • you're of course right. a quick side question on that maybe - this new type of extensions, since what Joomla version is it supported? Ideally I'd like to maintain just one version of my extensions... – codeling Feb 28 '18 at 8:45

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.