Get parent menu item object in pluginGet full link from menu item field typeMake a menu item, plugin or...

What happened to Captain America in Endgame?

Does a semiconductor follow Ohm's law?

How can the Zone of Truth spell be defeated without the caster knowing?

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

Why do games have consumables?

A ​Note ​on ​N!

Meaning of Bloch representation

Fizzy, soft, pop and still drinks

Why other Westeros houses don't use wildfire?

How would one muzzle a full grown polar bear in the 13th century?

Examples of non trivial equivalence relations , I mean equivalence relations without the expression " same ... as" in their definition?

What does the "ep" capability mean?

Don’t seats that recline flat defeat the purpose of having seatbelts?

Repelling Blast: Must targets always be pushed back?

How did Captain America manage to do this?

Exchange,swap or switch

simple conditions equation

How to type a section sign (§) into the Minecraft client

How to solve constants out of the internal energy equation?

Do I have an "anti-research" personality?

Does Gita support doctrine of eternal cycle of birth and death for evil people?

Was there a shared-world project before "Thieves World"?

Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?

What does KSP mean?



Get parent menu item object in plugin


Get full link from menu item field typeMake a menu item, plugin or component work as subdomainHow to keep parent menu item active for non-menu views?Menu getActive() method returns parent menu idGet the menu item variable using JinputJoomla menu item type issueParent menu item not marked if sub menu item is activeGet menu item by ID in Joomla 3Remove menu parent from urlcreate menu item independently













1















Problem



Working with a code variation from this tutorial I'm trying to get the parent menu item instance object of a given item (currently editing) and it always returns null.





/**
* Prepare form and add my field.
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since 0.0.1
*/
function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$menu = $app->getMenu();
$pid = $data->parent_id;
$parent = $menu->getItem($pid);
$items = $menu->getItems('menutype', $data->menutype);

var_dump($data->parent_id);
// returns the parent_id string of the currently edited menu item

var_dump($parent);
// returns null

var_dump($items);
// returns null as well
}


Questions:




  • Should I change the order of the plugins so mine executes last or hopefully after everything is initialized?

  • Should I use a different callback other than onContentPrepareForm?

  • Should I include/require anything from Joomla? If so, what is it?










share|improve this question







New contributor




thednp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Your last question isn't very clear. Can you elaborate or give some examples?

    – Sharky
    yesterday
















1















Problem



Working with a code variation from this tutorial I'm trying to get the parent menu item instance object of a given item (currently editing) and it always returns null.





/**
* Prepare form and add my field.
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since 0.0.1
*/
function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$menu = $app->getMenu();
$pid = $data->parent_id;
$parent = $menu->getItem($pid);
$items = $menu->getItems('menutype', $data->menutype);

var_dump($data->parent_id);
// returns the parent_id string of the currently edited menu item

var_dump($parent);
// returns null

var_dump($items);
// returns null as well
}


Questions:




  • Should I change the order of the plugins so mine executes last or hopefully after everything is initialized?

  • Should I use a different callback other than onContentPrepareForm?

  • Should I include/require anything from Joomla? If so, what is it?










share|improve this question







New contributor




thednp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Your last question isn't very clear. Can you elaborate or give some examples?

    – Sharky
    yesterday














1












1








1


1






Problem



Working with a code variation from this tutorial I'm trying to get the parent menu item instance object of a given item (currently editing) and it always returns null.





/**
* Prepare form and add my field.
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since 0.0.1
*/
function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$menu = $app->getMenu();
$pid = $data->parent_id;
$parent = $menu->getItem($pid);
$items = $menu->getItems('menutype', $data->menutype);

var_dump($data->parent_id);
// returns the parent_id string of the currently edited menu item

var_dump($parent);
// returns null

var_dump($items);
// returns null as well
}


Questions:




  • Should I change the order of the plugins so mine executes last or hopefully after everything is initialized?

  • Should I use a different callback other than onContentPrepareForm?

  • Should I include/require anything from Joomla? If so, what is it?










share|improve this question







New contributor




thednp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Problem



Working with a code variation from this tutorial I'm trying to get the parent menu item instance object of a given item (currently editing) and it always returns null.





/**
* Prepare form and add my field.
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since 0.0.1
*/
function onContentPrepareForm($form, $data)
{
$app = JFactory::getApplication();
$menu = $app->getMenu();
$pid = $data->parent_id;
$parent = $menu->getItem($pid);
$items = $menu->getItems('menutype', $data->menutype);

var_dump($data->parent_id);
// returns the parent_id string of the currently edited menu item

var_dump($parent);
// returns null

var_dump($items);
// returns null as well
}


Questions:




  • Should I change the order of the plugins so mine executes last or hopefully after everything is initialized?

  • Should I use a different callback other than onContentPrepareForm?

  • Should I include/require anything from Joomla? If so, what is it?







joomla-3.x menu-item custom-field






share|improve this question







New contributor




thednp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




thednp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




thednp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









thednpthednp

1084




1084




New contributor




thednp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





thednp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






thednp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Your last question isn't very clear. Can you elaborate or give some examples?

    – Sharky
    yesterday



















  • Your last question isn't very clear. Can you elaborate or give some examples?

    – Sharky
    yesterday

















Your last question isn't very clear. Can you elaborate or give some examples?

– Sharky
yesterday





Your last question isn't very clear. Can you elaborate or give some examples?

– Sharky
yesterday










1 Answer
1






active

oldest

votes


















2














Since you are editing from administrator section, $app->getMenu() returns administrator menu items. Pass client argument if you need site items:



$menu = $app->getMenu('site');



Should I change the order of the plugins so mine executes last or
hopefully after everything is initialized?




Probably not. Just note that plugin order does decide the order in which the form is altered. E.g. you might need to tweak the order in case you have multiple plugins modifying the same field. Or if you have dependencies on other plugins.




Should I use a different callback other than onContentPrepareForm?




No, if you want to modify a form, this is the event to use. But at the very least you should check that you are modifying the correct form (or multiple forms).



public function onContentPrepareForm($form, $data)
{
// Check that we are editing a menu item.
if ($form->getName() !== 'com_menus.item')
{
return true;
}

// Do our stuff.
}





share|improve this answer
























  • The $app->getMenu('site'); solved. Also thanks a million for the tips.

    – thednp
    yesterday












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "555"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






thednp is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fjoomla.stackexchange.com%2fquestions%2f24529%2fget-parent-menu-item-object-in-plugin%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Since you are editing from administrator section, $app->getMenu() returns administrator menu items. Pass client argument if you need site items:



$menu = $app->getMenu('site');



Should I change the order of the plugins so mine executes last or
hopefully after everything is initialized?




Probably not. Just note that plugin order does decide the order in which the form is altered. E.g. you might need to tweak the order in case you have multiple plugins modifying the same field. Or if you have dependencies on other plugins.




Should I use a different callback other than onContentPrepareForm?




No, if you want to modify a form, this is the event to use. But at the very least you should check that you are modifying the correct form (or multiple forms).



public function onContentPrepareForm($form, $data)
{
// Check that we are editing a menu item.
if ($form->getName() !== 'com_menus.item')
{
return true;
}

// Do our stuff.
}





share|improve this answer
























  • The $app->getMenu('site'); solved. Also thanks a million for the tips.

    – thednp
    yesterday
















2














Since you are editing from administrator section, $app->getMenu() returns administrator menu items. Pass client argument if you need site items:



$menu = $app->getMenu('site');



Should I change the order of the plugins so mine executes last or
hopefully after everything is initialized?




Probably not. Just note that plugin order does decide the order in which the form is altered. E.g. you might need to tweak the order in case you have multiple plugins modifying the same field. Or if you have dependencies on other plugins.




Should I use a different callback other than onContentPrepareForm?




No, if you want to modify a form, this is the event to use. But at the very least you should check that you are modifying the correct form (or multiple forms).



public function onContentPrepareForm($form, $data)
{
// Check that we are editing a menu item.
if ($form->getName() !== 'com_menus.item')
{
return true;
}

// Do our stuff.
}





share|improve this answer
























  • The $app->getMenu('site'); solved. Also thanks a million for the tips.

    – thednp
    yesterday














2












2








2







Since you are editing from administrator section, $app->getMenu() returns administrator menu items. Pass client argument if you need site items:



$menu = $app->getMenu('site');



Should I change the order of the plugins so mine executes last or
hopefully after everything is initialized?




Probably not. Just note that plugin order does decide the order in which the form is altered. E.g. you might need to tweak the order in case you have multiple plugins modifying the same field. Or if you have dependencies on other plugins.




Should I use a different callback other than onContentPrepareForm?




No, if you want to modify a form, this is the event to use. But at the very least you should check that you are modifying the correct form (or multiple forms).



public function onContentPrepareForm($form, $data)
{
// Check that we are editing a menu item.
if ($form->getName() !== 'com_menus.item')
{
return true;
}

// Do our stuff.
}





share|improve this answer













Since you are editing from administrator section, $app->getMenu() returns administrator menu items. Pass client argument if you need site items:



$menu = $app->getMenu('site');



Should I change the order of the plugins so mine executes last or
hopefully after everything is initialized?




Probably not. Just note that plugin order does decide the order in which the form is altered. E.g. you might need to tweak the order in case you have multiple plugins modifying the same field. Or if you have dependencies on other plugins.




Should I use a different callback other than onContentPrepareForm?




No, if you want to modify a form, this is the event to use. But at the very least you should check that you are modifying the correct form (or multiple forms).



public function onContentPrepareForm($form, $data)
{
// Check that we are editing a menu item.
if ($form->getName() !== 'com_menus.item')
{
return true;
}

// Do our stuff.
}






share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









SharkySharky

2,49117




2,49117













  • The $app->getMenu('site'); solved. Also thanks a million for the tips.

    – thednp
    yesterday



















  • The $app->getMenu('site'); solved. Also thanks a million for the tips.

    – thednp
    yesterday

















The $app->getMenu('site'); solved. Also thanks a million for the tips.

– thednp
yesterday





The $app->getMenu('site'); solved. Also thanks a million for the tips.

– thednp
yesterday










thednp is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















thednp is a new contributor. Be nice, and check out our Code of Conduct.













thednp is a new contributor. Be nice, and check out our Code of Conduct.












thednp is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Joomla Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fjoomla.stackexchange.com%2fquestions%2f24529%2fget-parent-menu-item-object-in-plugin%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...

Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...