DirectorObjectForm, TemplateTree: more fixes...

...related to inheritance and fields
This commit is contained in:
Thomas Gelf 2017-08-21 15:15:06 +02:00
parent 45111ac622
commit 7b2e13f9c1
2 changed files with 38 additions and 20 deletions

View File

@ -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'));
}
}

View File

@ -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)) {