diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index a597922b..7c3a93e4 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -12,7 +12,7 @@ use Icinga\Module\Director\Data\Db\DbObjectWithSettings; use Icinga\Module\Director\Exception\NestingError; use Icinga\Module\Director\IcingaConfig\StateFilterSet; use Icinga\Module\Director\IcingaConfig\TypeFilterSet; -use Icinga\Module\Director\Objects\IcingaTemplateChoiceHost; +use Icinga\Module\Director\Objects\IcingaTemplateChoice; use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Util; use Zend_Form_Element as ZfElement; @@ -45,8 +45,6 @@ abstract class DirectorObjectForm extends QuickForm private $choiceElements = []; - private $choiceTemplates = []; - protected $preferredObjectType; /** @var IcingaObjectFieldLoader */ @@ -1062,9 +1060,10 @@ abstract class DirectorObjectForm extends QuickForm return $this; } - protected function addChoiceElement(IcingaTemplateChoiceHost $choice) + protected function addChoiceElement(IcingaTemplateChoice $choice) { - $element = $choice->createFormElement($this, $this->object()->imports); + $imports = $this->object()->imports; + $element = $choice->createFormElement($this, $imports); $this->addElement($element); $this->choiceElements[$element->getName()] = $element; return $this; @@ -1094,7 +1093,20 @@ abstract class DirectorObjectForm extends QuickForm return $this; } - $type = $this->object()->getShortTableName(); + $db = $this->getDb()->getDbAdapter(); + $object = $this->object; + if ($object->supportsChoices()) { + $choiceNames = $db->fetchCol( + $db->select()->from( + $this->object()->getTableName(), + 'object_name' + )->where('template_choice_id IS NOT NULL') + ); + } else { + $choiceNames = []; + } + + $type = $object->getShortTableName(); $this->addElement('extensibleSet', 'imports', array( 'label' => $this->translate('Imports'), 'description' => $this->translate( @@ -1104,6 +1116,7 @@ abstract class DirectorObjectForm extends QuickForm ), 'required' => $required, 'spellcheck' => 'false', + 'hideOptions' => $choiceNames, 'suggest' => "${type}templates", // 'multiOptions' => $this->optionallyAddFromEnum($enum), 'sorted' => true, diff --git a/library/Director/Web/Form/IplElement/ExtensibleSetElement.php b/library/Director/Web/Form/IplElement/ExtensibleSetElement.php index 12ca5050..932d51a1 100644 --- a/library/Director/Web/Form/IplElement/ExtensibleSetElement.php +++ b/library/Director/Web/Form/IplElement/ExtensibleSetElement.php @@ -40,6 +40,8 @@ class ExtensibleSetElement extends BaseElement private $remainingAttribs; + private $hideOptions = []; + protected $defaultAttributes = [ 'class' => 'extensible-set' ]; @@ -49,6 +51,12 @@ class ExtensibleSetElement extends BaseElement $this->name = $this->id = $name; } + public function hideOptions($options) + { + $this->hideOptions = array_merge($this->hideOptions, $options); + return $this; + } + private function setMultiOptions($options) { $this->multiOptions = $options; @@ -132,6 +140,11 @@ class ExtensibleSetElement extends BaseElement unset($attribs['multiOptions']); } + if (array_key_exists('hideOptions', $attribs)) { + $this->hideOptions($attribs['hideOptions']); + unset($attribs['hideOptions']); + } + if (array_key_exists('sorted', $attribs)) { $this->sorted = (bool) $attribs['sorted']; unset($attribs['sorted']); @@ -270,6 +283,10 @@ class ExtensibleSetElement extends BaseElement $total = count($this->value); foreach ($this->value as $val) { + if (in_array($val, $this->hideOptions)) { + continue; + } + if ($this->multiOptions !== null) { if ($this->isValidOption($val)) { $this->multiOptions = $this->removeOption(