mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
Widget/Documentation: cleanup, new quick init
This commit is contained in:
parent
63a72bec0d
commit
9de84c3a72
@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Web\Widget;
|
|||||||
use gipfl\IcingaWeb2\Link;
|
use gipfl\IcingaWeb2\Link;
|
||||||
use gipfl\Translation\TranslationHelper;
|
use gipfl\Translation\TranslationHelper;
|
||||||
use Icinga\Application\ApplicationBootstrap;
|
use Icinga\Application\ApplicationBootstrap;
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Authentication\Auth;
|
use Icinga\Authentication\Auth;
|
||||||
use ipl\Html\Html;
|
use ipl\Html\Html;
|
||||||
|
|
||||||
@ -24,6 +25,12 @@ class Documentation
|
|||||||
$this->auth = $auth;
|
$this->auth = $auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function link($label, $module, $chapter, $title = null)
|
||||||
|
{
|
||||||
|
$doc = new static(Icinga::app(), Auth::getInstance());
|
||||||
|
return $doc->getModuleLink($label, $module, $chapter, $title);
|
||||||
|
}
|
||||||
|
|
||||||
public function getModuleLink($label, $module, $chapter, $title = null)
|
public function getModuleLink($label, $module, $chapter, $title = null)
|
||||||
{
|
{
|
||||||
if ($title !== null) {
|
if ($title !== null) {
|
||||||
@ -33,31 +40,35 @@ class Documentation
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
$linkToGitHub = false;
|
$linkToGitHub = false;
|
||||||
$hasModule = $this->app->getModuleManager()->hasLoaded($module);
|
$baseParams = [
|
||||||
if ($hasModule && $this->hasAccessToDocumentationModule()) {
|
|
||||||
return Link::create(
|
|
||||||
$label,
|
|
||||||
'doc/module/director/chapter/' . \preg_replace('/^\d+-/', '', \rawurlencode($chapter)),
|
|
||||||
null,
|
|
||||||
[
|
|
||||||
'data-base-target' => '_next',
|
|
||||||
'class' => 'icon-book',
|
'class' => 'icon-book',
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
]
|
];
|
||||||
|
if ($this->hasAccessToDocumentationModule()) {
|
||||||
|
return Link::create(
|
||||||
|
$label,
|
||||||
|
$this->getDirectorDocumentationUrl($chapter),
|
||||||
|
null,
|
||||||
|
['data-base-target' => '_next'] + $baseParams
|
||||||
);
|
);
|
||||||
} elseif ($linkToGitHub) {
|
}
|
||||||
|
|
||||||
|
$baseParams['target'] = '_blank';
|
||||||
|
if ($linkToGitHub) {
|
||||||
return Html::tag('a', [
|
return Html::tag('a', [
|
||||||
'href' => $this->githubDocumentationUrl($module, $chapter),
|
'href' => $this->githubDocumentationUrl($module, $chapter),
|
||||||
'target' => '_blank',
|
] + $baseParams, $label);
|
||||||
'title' => $title,
|
}
|
||||||
], $label);
|
|
||||||
} else {
|
|
||||||
return Html::tag('a', [
|
return Html::tag('a', [
|
||||||
'href' => $this->icingaDocumentationUrl($module, $chapter),
|
'href' => $this->icingaDocumentationUrl($module, $chapter),
|
||||||
'target' => '_blank',
|
] + $baseParams, $label);
|
||||||
'title' => $title,
|
|
||||||
], $label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getDirectorDocumentationUrl($chapter)
|
||||||
|
{
|
||||||
|
return 'doc/module/director/chapter/'
|
||||||
|
. \preg_replace('/^\d+-/', '', \rawurlencode($chapter));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function githubDocumentationUrl($module, $chapter)
|
protected function githubDocumentationUrl($module, $chapter)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user