mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 16:24:05 +02:00
DirectorObjectForm, TemplateTree: more fixes...
...related to inheritance and fields
This commit is contained in:
parent
45111ac622
commit
7b2e13f9c1
@ -132,13 +132,10 @@ class TemplateTree
|
||||
|
||||
public function getAncestorsFor(IcingaObject $object)
|
||||
{
|
||||
if ($object->hasBeenLoadedFromDb()) {
|
||||
return $this->getAncestorsById($object->getProperty('id'));
|
||||
} elseif ($id = $object->getProperty('id')) {
|
||||
// Special, this is for calls from onStore()
|
||||
return $this->getAncestorsById($id);
|
||||
} else {
|
||||
if ($object->hasBeenModified()) {
|
||||
return $this->getAncestorsForUnstoredObject($object);
|
||||
} else {
|
||||
return $this->getAncestorsById($object->getProperty('id'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,27 @@ abstract class DirectorObjectForm extends DirectorForm
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
protected function extractChoicesFromPost($post)
|
||||
{
|
||||
$imports = [];
|
||||
|
||||
foreach ($this->choiceElements as $other) {
|
||||
$name = $other->getName();
|
||||
if (array_key_exists($name, $post)) {
|
||||
$value = $post[$name];
|
||||
if (is_string($value)) {
|
||||
$imports[] = $value;
|
||||
} elseif (is_array($value)) {
|
||||
foreach ($value as $chosen) {
|
||||
$imports[] = $chosen;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $imports;
|
||||
}
|
||||
|
||||
protected function assertResolvedImports()
|
||||
{
|
||||
if ($this->resolvedImports !== null) {
|
||||
@ -144,26 +165,26 @@ abstract class DirectorObjectForm extends DirectorForm
|
||||
$key = 'imports';
|
||||
if ($el = $this->getElement($key)) {
|
||||
if (array_key_exists($key, $post)) {
|
||||
$imports = $post[$key];
|
||||
$imports = array_values(array_merge(
|
||||
$post[$key],
|
||||
$this->extractChoicesFromPost($post)
|
||||
));
|
||||
|
||||
/** @var ZfElement $el */
|
||||
foreach ($this->choiceElements as $other) {
|
||||
$name = $other->getName();
|
||||
if (array_key_exists($name, $post)) {
|
||||
$value = $post[$name];
|
||||
if (is_string($value)) {
|
||||
$imports[] = $value;
|
||||
} elseif (is_array($value)) {
|
||||
foreach ($value as $chosen) {
|
||||
$imports[] = $chosen;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->populate([$key => $imports]);
|
||||
$el->setValue($imports);
|
||||
$this->tryToSetObjectPropertyFromElement($object, $el, $key);
|
||||
}
|
||||
} elseif ($this->presetImports) {
|
||||
$imports = array_values(array_merge(
|
||||
$this->presetImports,
|
||||
$this->extractChoicesFromPost($post)
|
||||
));
|
||||
$this->object()->set('imports', $imports);
|
||||
} else {
|
||||
$this->object()->set('imports', $this->extractChoicesFromPost($post));
|
||||
}
|
||||
|
||||
foreach ($this->earlyProperties as $key) {
|
||||
if ($el = $this->getElement($key)) {
|
||||
if (array_key_exists($key, $post)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user