1

I'm trying to do a "quick" fix to J3 components so they work in J4 until I can re-code in the new structure ready for J5. Now that I've set the scene, I'm stumbling on getting the Menu URL that was last selected before performing some updates to a record in the frontend.

Old J3 way I worked this in the controller was:

$menu = Factory::getApplication()->getMenu()->getActive();
$url  = (empty($menu->link) ? 'index.php?option=com_mycomponent&view=multiviews' : $menu->link);
$this->setRedirect(Route::_($url, false));

Now using this in an install of J4 keeps dumping me back to default home page. Any and all guidance appreciated. Glenn

3
  • Did you come across a better way to resolve this issue?
    – Irata
    Commented Oct 25, 2021 at 1:39
  • This may be the same issue that you struck, joomla.stackexchange.com/questions/31618/…
    – Irata
    Commented Oct 25, 2021 at 7:55
  • To be honest I don't understand some of the deep technicalities involved in J4 at this stage. What I've found is that if I just tweek my components, still using the MVC structure for a component in J4, then I definitely need to do as I'm doing in my answer below. However, if I restructure the full component into the new structure using namespaced files, then all works just as it use to in J3 regarding the steps used in the above question. Commented Oct 26, 2021 at 3:31

1 Answer 1

0

Ok, so a work around for me is to have the "collection" of the Menu id in the view template saved to session and then brought back in the controller where I need it (ie been over to another form view and submitted etc).

In the View:

$menu = Factory::getApplication()->getMenu()->getActive();
$Itemid = $menu->id;
Factory::getApplication()->setUserState('com_mycomponent.menu.Itemid', $menu->id);

In the Controller:

$Itemid = Factory::getApplication()->getUserState('com_mycomponent.menu.Itemid');
$this->setRedirect(Route::_('index.php?option=com_mycomponent&view=multiviews&Itemid='.$Itemid, false));

I'm sure there is a nicer way to do this, so if anyone can shed some light on it for me, much appreciated. I have converted a component into the new structure and there is no need for this, all handled within the CMS framework.

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.