Skip to content

Instantly share code, notes, and snippets.

@joni1993
Last active October 7, 2021 10:32
Show Gist options
  • Save joni1993/df1566eb1c2a8db425e55f3c6b7ff07f to your computer and use it in GitHub Desktop.
Save joni1993/df1566eb1c2a8db425e55f3c6b7ff07f to your computer and use it in GitHub Desktop.
Fix exception when using dictionary on host
diff --git a/application/controllers/DataController.php b/application/controllers/DataController.php
index ae4bbcf3..588c4604 100644
--- a/application/controllers/DataController.php
+++ b/application/controllers/DataController.php
@@ -6,7 +6,7 @@ use gipfl\Web\Widget\Hint;
use Icinga\Exception\NotFoundError;
use Icinga\Module\Director\Forms\DirectorDatalistEntryForm;
use Icinga\Module\Director\Forms\DirectorDatalistForm;
-use Icinga\Module\Director\Forms\IcingaServiceDictionaryMemberForm;
+use Icinga\Module\Director\Forms\IcingaDictionaryMemberForm;
use Icinga\Module\Director\Objects\DirectorDatalist;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaObject;
@@ -193,7 +193,8 @@ class DataController extends ActionController
'object_name' => $field->getSetting('template_name')
], $connection);
- $form = new IcingaServiceDictionaryMemberForm();
+ $form = new IcingaDictionaryMemberForm();
+ $form->setType(get_class($object));
$form->setDb($connection);
if ($instance) {
$instanceObject = $object::create([
diff --git a/application/forms/IcingaServiceDictionaryMemberForm.php b/application/forms/IcingaDictionaryMemberForm.php
similarity index 78%
rename from application/forms/IcingaServiceDictionaryMemberForm.php
rename to application/forms/IcingaDictionaryMemberForm.php
index 90b8f94b..8715b24c 100644
--- a/application/forms/IcingaServiceDictionaryMemberForm.php
+++ b/application/forms/IcingaDictionaryMemberForm.php
@@ -4,14 +4,17 @@ namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
use Icinga\Module\Director\Objects\IcingaService;
+use Icinga\Module\Director\Objects\IcingaHost;
-class IcingaServiceDictionaryMemberForm extends DirectorObjectForm
+class IcingaDictionaryMemberForm extends DirectorObjectForm
{
- /** @var IcingaService */
+ /** @var IcingaObject */
protected $object;
private $succeeded;
+ protected $object_class;
+
/**
* @throws \Zend_Form_Exception
*/
@@ -28,18 +31,23 @@ class IcingaServiceDictionaryMemberForm extends DirectorObjectForm
$this->groupMainProperties()->setButtons();
}
+ public function setType($object_class) {
+ $this->object_class = $object_class;
+ }
+
protected function isNew()
{
return $this->object === null;
}
+
protected function deleteObject($object)
{
}
protected function getObjectClassname()
{
- return IcingaService::class;
+ return $this->object_class;
}
public function succeeded()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment