J4 Menuitem params

378 views
Skip to first unread message

Harold Smith

unread,
Jul 15, 2023, 7:05:11 PM7/15/23
to Joomla! General Development
Updating J3 components to J4 and still can't seem to get the menu changes together.  My issue now is the error.. "Cannot access protected property Joomla\CMS\Menu\MenuItem::$params".  Hoping that someone could help with this.  I know it could be simple.

protected function populateState($ordering = null, $direction = null) {
// Initialize variables.
$app = Factory::getApplication('site');

// Load the parameters. Merge Global and Menu Item params into new object
$params = $app->getParams();
$menuParams = new Registry();

if ($menu = $app->getMenu()->getActive()) {
$menuParams->loadString($menu->params);
}

$mergedParams = clone $menuParams;
$mergedParams->merge($params);

$this->setState('params', $mergedParams);

// process show_noauth parameter
if (!$params->get('show_noauth')) {
$this->setState('filter.access', true);
} else {
$this->setState('filter.access', false);
}

Any help with this is Very Much Appreciated.



Hannes Papenberg

unread,
Jul 15, 2023, 10:22:54 PM7/15/23
to Joomla! General Development
$nenu->getParams()

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/fcf76212-fa05-4ccc-a697-1f4d2b9906f3n%40googlegroups.com.

Harold Smith

unread,
Jul 16, 2023, 5:53:32 PM7/16/23
to Joomla! General Development
Appreciate the suggestion, but it didn't  help me out much.

Could someone *please* help me with this small bit of code to get through this error?

Glenn Arkell

unread,
Jul 16, 2023, 7:56:43 PM7/16/23
to Joomla! General Development
$app = Factory::getApplication(); 
$menu = $app->getMenu()->getActive()
$itemId = $menu->id; 
$menuparams = $menu->getParams($itemId);

Hannes Papenberg

unread,
Jul 17, 2023, 12:16:18 AM7/17/23
to Joomla! General Development
You asked for the code to get the menu item parameters and I have that to you. $menuitem->getParams(), without any additional options. In fact, what you are trying to do there is pretty much unnecessary, because $app->getParams() has already done that for you.

Travis Risner

unread,
Jul 17, 2023, 6:52:29 AM7/17/23
to Joomla! General Development
I had some problems getting menu item params in my frontend component as well when migrating from Joomla 3 to 4. I found that swapping from getting the params off the menu object to getting params from the Application object itself seemed to work better. Like:

$app = Factory::getApplication();
$params = $app->getParams();

$param1 = $params->get('params1');
$meta_desc = $params->get('menu-meta_description');

Adam Melcher

unread,
Jul 17, 2023, 10:22:25 AM7/17/23
to joomla-de...@googlegroups.com
I have updated most of my larger sites from J3 to J4 and the code I use to grab the menu items the current page:
use \Joomla\CMS\Factory;

$menu = Factory::getApplication()->getMenu()->getActive();
if (is_object($menu)){
$menuparam1 = $menu->getParams()->get('custom-menu-param-1');
}


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.

Harold Smith

unread,
Jul 17, 2023, 1:49:19 PM7/17/23
to Joomla! General Development
Hannes,
I was not trying to be rude or offend.
What I am trying to do is get the url to send to my script.  It is a demo bar and it wants the urls to load the demos.  My problem is that the code in my model at line "$menuParams->loadString($activeMenu->getParams());" returns null "Call to a member function getParams() on null" so the script will not work to load the demos.

/**
 * Load a url into a page
 */
jQuery.fn.load = function( url, params, callback ) {
var selector, type, response,
self = this,
off = url.indexOf( " " );

Hannes Papenberg

unread,
Jul 17, 2023, 2:09:43 PM7/17/23
to Joomla! General Development
As I said before, you don't need all that loadString() stuff at all. Just do $app->getParams()->get(whatever) 
That already contains the current menu items parameters, it is already all merged and in an object. Even in the menu item, it isn't a string but an object since at least joomla 3.0.

Reply all
Reply to author
Forward
0 new messages