mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
ObjectForm: allow to preset imports
This commit is contained in:
parent
5407c4fe7c
commit
b39e7efce7
@ -9,6 +9,7 @@ use Icinga\Exception\NotFoundError;
|
|||||||
use Icinga\Module\Director\Exception\NestingError;
|
use Icinga\Module\Director\Exception\NestingError;
|
||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||||
use Icinga\Module\Director\Objects\IcingaObject;
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
|
|
||||||
abstract class ObjectController extends ActionController
|
abstract class ObjectController extends ActionController
|
||||||
@ -186,8 +187,10 @@ abstract class ObjectController extends ActionController
|
|||||||
$ltype = strtolower($type);
|
$ltype = strtolower($type);
|
||||||
|
|
||||||
$url = sprintf('director/%ss', $ltype);
|
$url = sprintf('director/%ss', $ltype);
|
||||||
|
/** @var DirectorObjectForm $form */
|
||||||
$form = $this->view->form = $this->loadForm('icinga' . ucfirst($type))
|
$form = $this->view->form = $this->loadForm('icinga' . ucfirst($type))
|
||||||
->setDb($this->db())
|
->setDb($this->db())
|
||||||
|
->presetImports($this->params->shift('imports'))
|
||||||
->setApi($this->getApiIfAvailable())
|
->setApi($this->getApiIfAvailable())
|
||||||
->setSuccessUrl($url);
|
->setSuccessUrl($url);
|
||||||
|
|
||||||
|
@ -45,12 +45,27 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
/** @var CoreApi */
|
/** @var CoreApi */
|
||||||
private $api;
|
private $api;
|
||||||
|
|
||||||
|
private $presetImports;
|
||||||
|
|
||||||
public function setPreferredObjectType($type)
|
public function setPreferredObjectType($type)
|
||||||
{
|
{
|
||||||
$this->preferredObjectType = $type;
|
$this->preferredObjectType = $type;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function presetImports($imports)
|
||||||
|
{
|
||||||
|
if (! empty($imports)) {
|
||||||
|
if (is_array($imports)) {
|
||||||
|
$this->presetImports = $imports;
|
||||||
|
} else {
|
||||||
|
$this->presetImports = array($imports);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $values
|
* @param array $values
|
||||||
*
|
*
|
||||||
@ -248,7 +263,7 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
unset($props['vars']);
|
unset($props['vars']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setDefaults($this->removeNullProperties($props));
|
$this->setDefaults($this->removeEmptyProperties($props));
|
||||||
|
|
||||||
if ($resolve) {
|
if ($resolve) {
|
||||||
$this->showInheritedProperties($object);
|
$this->showInheritedProperties($object);
|
||||||
@ -270,11 +285,11 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function removeNullProperties($props)
|
protected function removeEmptyProperties($props)
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($props as $k => $v) {
|
foreach ($props as $k => $v) {
|
||||||
if ($v !== null && $v !== '') {
|
if ($v !== null && $v !== '' && $v !== array()) {
|
||||||
$result[$k] = $v;
|
$result[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -913,6 +928,7 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
'required' => ($required !== null ? $required : !$this->isTemplate()),
|
'required' => ($required !== null ? $required : !$this->isTemplate()),
|
||||||
'multiOptions' => $this->optionallyAddFromEnum($enum),
|
'multiOptions' => $this->optionallyAddFromEnum($enum),
|
||||||
'sorted' => true,
|
'sorted' => true,
|
||||||
|
'value' => $this->presetImports,
|
||||||
'class' => 'autosubmit'
|
'class' => 'autosubmit'
|
||||||
));
|
));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user