CloneObject: use modern loading

This commit is contained in:
Thomas Gelf 2017-07-25 10:16:15 +02:00
parent 649fff7486
commit b675d37b6f
2 changed files with 11 additions and 8 deletions

View File

@ -3,19 +3,20 @@
namespace Icinga\Module\Director\Forms; namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Web\Form\QuickForm; use Icinga\Module\Director\Web\Form\DirectorForm;
class IcingaCloneObjectForm extends QuickForm class IcingaCloneObjectForm extends DirectorForm
{ {
/** @var IcingaObject */ /** @var IcingaObject */
protected $object; protected $object;
public function setup() public function setup()
{ {
$name = $this->object->getObjectName();
$this->addElement('text', 'new_object_name', array( $this->addElement('text', 'new_object_name', array(
'label' => $this->translate('New name'), 'label' => $this->translate('New name'),
'required' => true, 'required' => true,
'value' => $this->object->getObjectName(), 'value' => $name,
)); ));
$this->addElement('select', 'clone_type', array( $this->addElement('select', 'clone_type', array(
@ -29,7 +30,7 @@ class IcingaCloneObjectForm extends QuickForm
$this->submitLabel = sprintf( $this->submitLabel = sprintf(
$this->translate('Clone "%s"'), $this->translate('Clone "%s"'),
$this->object->getObjectName() $name
); );
} }

View File

@ -10,6 +10,7 @@ use Icinga\Module\Director\Deployment\DeploymentInfo;
use Icinga\Module\Director\Exception\DuplicateKeyException; use Icinga\Module\Director\Exception\DuplicateKeyException;
use Icinga\Module\Director\Exception\NestingError; use Icinga\Module\Director\Exception\NestingError;
use Icinga\Module\Director\Forms\DeploymentLinkForm; use Icinga\Module\Director\Forms\DeploymentLinkForm;
use Icinga\Module\Director\Forms\IcingaCloneObjectForm;
use Icinga\Module\Director\Forms\IcingaObjectFieldForm; use Icinga\Module\Director\Forms\IcingaObjectFieldForm;
use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Objects\IcingaObjectGroup; use Icinga\Module\Director\Objects\IcingaObjectGroup;
@ -234,14 +235,15 @@ abstract class ObjectController extends ActionController
$this->assertPermission('director/' . $ltype); $this->assertPermission('director/' . $ltype);
$this->tabs()->activate('modify'); $this->tabs()->activate('modify');
$this->addTitle($this->translate('Clone Icinga %s'), ucfirst($type)); $this->addTitle($this->translate('Clone Icinga %s'), ucfirst($type));
$form = $this->loadForm('icingaCloneObject')->setObject($this->object); $form = IcingaCloneObjectForm::load()
$form->handleRequest(); ->setObject($this->object)
->handleRequest();
$this->content()->add($form); $this->content()->add($form);
$this->actions()->add(Link::create( $this->actions()->add(Link::create(
$this->translate('back'), $this->translate('back'),
'director/' . $ltype, 'director/' . $ltype,
array('name' => $this->object->object_name), ['name' => $this->object->getObjectName()],
array('class' => 'icon-left-big') ['class' => 'icon-left-big']
)); ));
} }