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?