icingaweb2-module-director/library/Director/Web/Widget/ObjectModificationBranchHin...

61 lines
2.0 KiB
PHP
Raw Normal View History

2021-08-16 11:43:09 +02:00
<?php
namespace Icinga\Module\Director\Web\Widget;
use gipfl\Translation\TranslationHelper;
use gipfl\Web\Widget\Hint;
use Icinga\Authentication\Auth;
2021-08-16 11:43:09 +02:00
use Icinga\Module\Director\Data\Db\DbObject;
use Icinga\Module\Director\Db\Branch\Branch;
use Icinga\Module\Director\Db\Branch\ObjectModification;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
class ObjectModificationBranchHint extends HtmlDocument
{
use TranslationHelper;
public function __construct(Branch $branch, Auth $auth, DbObject $object, ObjectModification $modification = null)
2021-08-16 11:43:09 +02:00
{
if (! $branch->isBranch()) {
return;
}
$hook = Branch::requireHook();
$name = $branch->getName();
if (substr($name, 0, 1) === '/') {
$label = $this->translate('this configuration branch');
} else {
$label = $name;
}
$link = $hook->linkToBranch($branch, $auth, $label);
2021-08-16 11:43:09 +02:00
if ($modification === null) {
$this->add(Hint::info(Html::sprintf($this->translate(
'Your changes will be stored in %s. The\'ll not be part of any deployment'
2021-08-16 11:43:09 +02:00
. ' unless being merged'
), $link)));
2021-08-16 11:43:09 +02:00
return;
}
if ($modification->isDeletion()) {
$this->add(Hint::info(Html::sprintf(
$this->translate('This object has been deleted in %s'),
$link
2021-08-16 11:43:09 +02:00
)));
} elseif ($modification->isModification()) {
$this->add(Hint::info(Html::sprintf(
$this->translate('This object has modifications visible only in %s'),
// TODO: Also link to object modifications
// $hook->linkToBranchedObject($this->translate('modifications'), $branch, $object, $auth),
$link
2021-08-16 11:43:09 +02:00
)));
} else {
$this->add(Hint::info(Html::sprintf(
$this->translate('This object has been created in %s'),
$link
2021-08-16 11:43:09 +02:00
)));
}
}
}