NavigationConfigForm: Ask the item form whether a parent is required
refs #5600
This commit is contained in:
parent
c657812b9c
commit
91601de398
|
@ -5,28 +5,19 @@ namespace Icinga\Forms\Navigation;
|
|||
|
||||
class MenuItemForm extends NavigationItemForm
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $requiresParentSelection = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
$availableParents = $this->getParent()->listAvailableParents('menu-item');
|
||||
$this->addElement(
|
||||
'select',
|
||||
'parent',
|
||||
array(
|
||||
'allowEmpty' => true,
|
||||
'label' => $this->translate('Parent'),
|
||||
'description' => $this->translate(
|
||||
'The parent menu to assign this menu entry to. Select "None" to make this a main menu entry'
|
||||
),
|
||||
'multiOptions' => array_merge(
|
||||
array('' => $this->translate('None', 'No parent for a navigation item')),
|
||||
empty($availableParents) ? array() : array_combine($availableParents, $availableParents)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
parent::createElements($formData);
|
||||
$this->getParent()->getElement('parent')->setDescription($this->translate(
|
||||
'The parent menu to assign this menu entry to. Select "None" to make this a main menu entry'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -431,6 +431,7 @@ class NavigationConfigForm extends ConfigForm
|
|||
{
|
||||
$itemTypes = $this->getItemTypes();
|
||||
$itemType = isset($formData['type']) ? $formData['type'] : key($itemTypes);
|
||||
$itemForm = $this->getItemForm($itemType);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
|
@ -444,7 +445,10 @@ class NavigationConfigForm extends ConfigForm
|
|||
)
|
||||
);
|
||||
|
||||
if ($this->getUser()->can('application/share/navigation')) {
|
||||
if (
|
||||
(! $itemForm->requiresParentSelection() || !isset($formData['parent']) || !$formData['parent'])
|
||||
&& $this->getUser()->can('application/share/navigation')
|
||||
) {
|
||||
$checked = isset($formData['shared']) ? null : (isset($formData['users']) || isset($formData['groups']));
|
||||
|
||||
$this->addElement(
|
||||
|
@ -495,9 +499,29 @@ class NavigationConfigForm extends ConfigForm
|
|||
)
|
||||
);
|
||||
|
||||
$itemForm = $this->getItemForm($itemType);
|
||||
if ($itemForm->requiresParentSelection()) {
|
||||
$availableParents = $this->listAvailableParents($itemType);
|
||||
$this->addElement(
|
||||
'select',
|
||||
'parent',
|
||||
array(
|
||||
'allowEmpty' => true,
|
||||
'autosubmit' => true,
|
||||
'label' => $this->translate('Parent'),
|
||||
'description' => $this->translate(
|
||||
'The parent item to assign this navigation item to. '
|
||||
. 'Select "None" to make this a main navigation item'
|
||||
),
|
||||
'multiOptions' => array_merge(
|
||||
array('' => $this->translate('None', 'No parent for a navigation item')),
|
||||
empty($availableParents) ? array() : array_combine($availableParents, $availableParents)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->addSubForm($itemForm, 'item_form');
|
||||
$itemForm->create($formData); // Requires a parent which gets set by addSubForm()
|
||||
$itemForm->create($formData); // May require a parent which gets set by addSubForm()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,23 @@ use Icinga\Web\Form;
|
|||
|
||||
class NavigationItemForm extends Form
|
||||
{
|
||||
/**
|
||||
* Whether to create a select input to choose a parent for a navigation item of a particular type
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $requiresParentSelection = false;
|
||||
|
||||
/**
|
||||
* Return whether to create a select input to choose a parent for a navigation item of a particular type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function requiresParentSelection()
|
||||
{
|
||||
return $this->requiresParentSelection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue