FieldLoader, TemplateResolver: more cleanup
A few fixes related to modified imports for unstored objects refs #12922
This commit is contained in:
parent
98acba9fb4
commit
041fd52174
|
@ -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]);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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_'));
|
||||
|
|
Loading…
Reference in New Issue