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
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
New contributor
add a comment |
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
New contributor
Your last question isn't very clear. Can you elaborate or give some examples?
– Sharky
yesterday
add a comment |
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
New contributor
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
joomla-3.x menu-item custom-field
New contributor
New contributor
New contributor
asked yesterday
thednpthednp
1084
1084
New contributor
New contributor
Your last question isn't very clear. Can you elaborate or give some examples?
– Sharky
yesterday
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
}
The$app->getMenu('site');
solved. Also thanks a million for the tips.
– thednp
yesterday
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
}
The$app->getMenu('site');
solved. Also thanks a million for the tips.
– thednp
yesterday
add a comment |
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.
}
The$app->getMenu('site');
solved. Also thanks a million for the tips.
– thednp
yesterday
add a comment |
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.
}
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.
}
answered yesterday
SharkySharky
2,49117
2,49117
The$app->getMenu('site');
solved. Also thanks a million for the tips.
– thednp
yesterday
add a comment |
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Your last question isn't very clear. Can you elaborate or give some examples?
– Sharky
yesterday