Modules\Module: modules should register config tabs

This allows modules to register their config tabs and provides a
convenient way to fetch a modules fully instanced config tabs.
This commit is contained in:
Thomas Gelf 2014-06-24 20:47:03 +02:00
parent b7b99cfd67
commit 13ef06c700
1 changed files with 48 additions and 0 deletions

View File

@ -17,7 +17,9 @@ use Icinga\Application\Icinga;
use Icinga\Logger\Logger;
use Icinga\Util\Translator;
use Icinga\Web\Hook;
use Icinga\Web\Widget;
use Icinga\Util\File;
use Icinga\Exception\ProgrammingError;
/**
* Module handling
@ -124,6 +126,13 @@ class Module
*/
private $restrictionList = array();
/**
* Provided config tabs
*
* @var array
*/
private $configTabs = array();
/**
* Icinga application
*
@ -515,6 +524,27 @@ class Module
return array_key_exists($name, $this->restrictionList);
}
/**
* Retrieve this modules configuration tabs
*
* @return Icinga\Web\Widget\Tabs
*/
public function getConfigTabs()
{
$this->launchConfigScript();
$tabs = Widget::create('tabs');
$tabs->add('info', array(
'url' => 'config/module',
'urlParams' => array('name' => $this->getName()),
'title' => 'Module: ' . $this->getName()
));
foreach ($this->configTabs as $name => $config) {
$tabs->add($name, $config);
}
return $tabs;
}
/**
* Provide a named permission
*
@ -557,6 +587,24 @@ class Module
);
}
/**
* Provide a module config tab
*
* @param string $name Unique tab name
* @param string $config Tab config
*
* @return self
*/
protected function provideConfigTab($name, $config = array())
{
if (! array_key_exists('url', $config)) {
throw new ProgrammingError('A module config tab MUST provide and "url"');
}
$config['url'] = $this->getName() . '/' . ltrim($config['url'], '/');
$this->configTabs[$name] = $config;
return $this;
}
/**
* Register new namespaces on the autoloader
*