diff --git a/library/Director/Objects/IcingaTemplateResolver.php b/library/Director/Objects/IcingaTemplateResolver.php index 1890e0d7..20eed6d8 100644 --- a/library/Director/Objects/IcingaTemplateResolver.php +++ b/library/Director/Objects/IcingaTemplateResolver.php @@ -117,8 +117,17 @@ class IcingaTemplateResolver $this->requireTemplates(); if ($name === null) { - $name = $this->object->object_name; - if ($this->object->imports()->hasBeenModified()) { + + $object = $this->object; + + if ($object->hasBeenLoadedFromDb()) { + + if ($object->gotImports() && $object->imports()->hasBeenModified()) { + return $this->listUnstoredParentNames(); + } + + $name = $object->object_name; + } else { return $this->listUnstoredParentNames(); } } @@ -140,7 +149,7 @@ class IcingaTemplateResolver public function listResolvedParentIds() { $this->requireTemplates(); - return $this->resolveParentIds($this->object->id); + return $this->resolveParentIds(); } public function listResolvedParentNames() @@ -166,9 +175,9 @@ class IcingaTemplateResolver protected function resolveParentNames($name, &$list = array()) { foreach ($this->listParentNames($name) as $parent) { - $this->assertNotInList($parent, $list, $id); + $this->assertNotInList($parent, $list, $name); $list[$parent] = true; - $this->resolveParentIds($parent, $list); + $this->resolveParentNames($parent, $list); unset($list[$parent]); $list[$parent] = true; } @@ -176,10 +185,12 @@ class IcingaTemplateResolver return array_keys($list); } - protected function resolveParentIds($id, &$list = array()) + protected function resolveParentIds($id = null, &$list = array()) { foreach ($this->listParentIds($id) as $parent) { - $this->assertNotInList($parent, $list, $id); + if ($id !== null) { + $this->assertNotInList($parent, $list, $id); + } $list[$parent] = true; $this->resolveParentIds($parent, $list); unset($list[$parent]); diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 485390b1..9ab41d9c 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -273,7 +273,7 @@ abstract class DirectorObjectForm extends QuickForm protected function handleCustomVars($object, & $values) { - IcingaObjectFieldLoader::addFieldsToForm($this, $values); + IcingaObjectFieldLoader::addFieldsToForm($this, $object, $values); } protected function isNew() diff --git a/library/Director/Web/Form/IcingaObjectFieldLoader.php b/library/Director/Web/Form/IcingaObjectFieldLoader.php index e8feec32..a6dad1c1 100644 --- a/library/Director/Web/Form/IcingaObjectFieldLoader.php +++ b/library/Director/Web/Form/IcingaObjectFieldLoader.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\Web\Form; use Icinga\Module\Director\Exception\NestingError; +use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaServiceSet; use Icinga\Module\Director\Objects\DirectorDatafield; use stdClass; @@ -13,19 +14,19 @@ class IcingaObjectFieldLoader protected $object; - protected function __construct(DirectorObjectForm $form) + protected function __construct(DirectorObjectForm $form, IcingaObject $object) { - $this->form = $form; - $this->object = $form->getObject(); + $this->form = $form; + $this->object = $object; } - public static function addFieldsToForm(DirectorObjectForm $form, & $values) + public static function addFieldsToForm(DirectorObjectForm $form, IcingaObject $object, & $values) { - if (! $form->getObject()->supportsCustomVars()) { + if (! $object->supportsCustomVars()) { return $form; } - $loader = new static($form); + $loader = new static($form, $object); $loader->addFields(); if ($values !== null) { $loader->setValues($loader->stripKeyPrefix($values, 'var_'));