diff options
Diffstat (limited to 'library/Director/Web/Controller/ObjectController.php')
-rw-r--r-- | library/Director/Web/Controller/ObjectController.php | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index 0c06937..994a717 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -10,6 +10,7 @@ use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\Data\Db\DbObjectTypeRegistry; use Icinga\Module\Director\Db\Branch\Branch; use Icinga\Module\Director\Db\Branch\BranchedObject; +use Icinga\Module\Director\Db\Branch\BranchSupport; use Icinga\Module\Director\Db\Branch\UuidLookup; use Icinga\Module\Director\Deployment\DeploymentInfo; use Icinga\Module\Director\DirectorObject\Automation\ExportInterface; @@ -61,8 +62,11 @@ abstract class ObjectController extends ActionController public function init() { - parent::init(); $this->enableStaticObjectLoader($this->getTableName()); + if (! $this->getRequest()->isApiRequest()) { + $this->loadOptionalObject(); + } + parent::init(); if ($this->getRequest()->isApiRequest()) { $this->initializeRestApi(); } else { @@ -97,7 +101,6 @@ abstract class ObjectController extends ActionController protected function initializeWebRequest() { - $this->loadOptionalObject(); if ($this->getRequest()->getActionName() === 'add') { $this->addSingleTab( sprintf($this->translate('Add %s'), ucfirst($this->getType())), @@ -151,8 +154,11 @@ abstract class ObjectController extends ActionController $this->addObject(); } $branch = $this->getBranch(); - if ($branch->isBranch() && ! $this->getRequest()->isApiRequest()) { - $this->content()->add(new BranchedObjectHint($branch, $this->Auth())); + if (! $this->getRequest()->isApiRequest()) { + $hasPreferred = $this->hasPreferredBranch(); + if ($branch->isBranch() || $hasPreferred) { + $this->content()->add(new BranchedObjectHint($branch, $this->Auth(), null, $hasPreferred)); + } } $form->handleRequest(); @@ -267,7 +273,7 @@ abstract class ObjectController extends ActionController if ($id = $this->params->get('field_id')) { $form->loadObject([ - "${type}_id" => $object->id, + "{$type}_id" => $object->id, 'datafield_id' => $id ]); @@ -362,7 +368,7 @@ abstract class ObjectController extends ActionController $this->actions()->add([ Link::create( $this->translate('Usage'), - "director/${type}template/usage", + "director/{$type}template/usage", ['name' => $object->getObjectName()], ['class' => 'icon-sitemap'] ) @@ -558,8 +564,16 @@ abstract class ObjectController extends ActionController if (! $this->allowsObject($object)) { throw new NotFoundError('No such object available'); } - if ($showHint && $branch->isBranch() && $object->isObject() && ! $this->getRequest()->isApiRequest()) { - $this->content()->add(new BranchedObjectHint($branch, $this->Auth(), $branchedObject)); + if ($showHint) { + $hasPreferredBranch = $this->hasPreferredBranch(); + if (($hasPreferredBranch || $branch->isBranch()) + && $object->isObject() + && ! $this->getRequest()->isApiRequest() + ) { + $this->content()->add( + new BranchedObjectHint($branch, $this->Auth(), $branchedObject, $hasPreferredBranch) + ); + } } return $object; |