diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 95fbc988..4118d4f6 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -16,6 +16,7 @@ use Icinga\Module\Director\Objects\IcingaTemplateChoice; use Icinga\Module\Director\Objects\IcingaCommand; use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Util; +use Icinga\Module\Director\Web\Form\Element\ExtensibleSet; use Icinga\Module\Director\Web\Form\Validate\NamePattern; use Zend_Form_Element as ZfElement; use Zend_Form_Element_Select as ZfSelect; @@ -623,6 +624,9 @@ abstract class DirectorObjectForm extends DirectorForm $multi[null] = $this->translate($this->translate('- inherited -')); } $el->setMultiOptions($multi); + } elseif ($el instanceof ExtensibleSet) { + $el->setAttrib('inherited', $inherited); + $el->setAttrib('inheritedFrom', $inheritedFrom); } else { if (is_string($inherited) || is_int($inherited)) { $el->setAttrib('placeholder', $inherited . sprintf($txtInherited, $inheritedFrom)); diff --git a/library/Director/Web/Form/IplElement/ExtensibleSetElement.php b/library/Director/Web/Form/IplElement/ExtensibleSetElement.php index 76b2c939..7f1ffeaf 100644 --- a/library/Director/Web/Form/IplElement/ExtensibleSetElement.php +++ b/library/Director/Web/Form/IplElement/ExtensibleSetElement.php @@ -42,6 +42,10 @@ class ExtensibleSetElement extends BaseHtmlElement private $hideOptions = []; + private $inherited; + + private $inheritedFrom; + protected $defaultAttributes = [ 'class' => 'extensible-set' ]; @@ -129,11 +133,18 @@ class ExtensibleSetElement extends BaseHtmlElement $this->disable($attribs['disable']); unset($attribs['disable']); } - if (array_key_exists('value', $attribs)) { $this->setValue($attribs['value']); unset($attribs['value']); } + if (array_key_exists('inherited', $attribs)) { + $this->inherited = $attribs['inherited']; + unset($attribs['inherited']); + } + if (array_key_exists('inheritedFrom', $attribs)) { + $this->inheritedFrom = $attribs['inheritedFrom']; + unset($attribs['inheritedFrom']); + } if (array_key_exists('multiOptions', $attribs)) { $this->setMultiOptions($attribs['multiOptions']); @@ -228,10 +239,13 @@ class ExtensibleSetElement extends BaseHtmlElement return; } $field = Html::tag('select', ['class' => 'autosubmit']); + $more = $this->inherited === null + ? $this->translate('- add more -') + : $this->getInheritedInfo(); $field->add(Html::tag('option', [ 'value' => '', 'tabindex' => '-1' - ], $this->translate('- add more -'))); + ], $more)); foreach ($this->multiOptions as $key => $label) { if ($key === null) { @@ -253,7 +267,9 @@ class ExtensibleSetElement extends BaseHtmlElement } else { $field = Html::tag('input', [ 'type' => 'text', - 'placeholder' => $this->translate('Add a new one...'), + 'placeholder' => $this->inherited === null + ? $this->translate('Add a new one...') + : $this->getInheritedInfo(), ]); } $field->addAttributes([ @@ -284,6 +300,22 @@ class ExtensibleSetElement extends BaseHtmlElement } } + private function getInheritedInfo() + { + if ($this->inheritedFrom === null) { + return \sprintf( + $this->translate('%s (inherited)'), + \implode(', ', $this->inherited) + ); + } else { + return \sprintf( + $this->translate('%s (inherited from %s)'), + \implode(', ', $this->inherited), + $this->inheritedFrom + ); + } + } + private function createAddNewButton() { return $this->newInlineButtons(