Make the view available to DetailviewExtensionHooks

refs #2104
This commit is contained in:
Alexander A. Klimov 2017-02-21 12:23:21 +01:00
parent 0a9aa20dfa
commit fb2abf40f8
2 changed files with 32 additions and 1 deletions

View File

@ -4,6 +4,7 @@
namespace Icinga\Module\Monitoring\Hook;
use Icinga\Module\Monitoring\Object\MonitoredObject;
use Icinga\Web\View;
/**
* Base class for hooks extending the detail view of monitored objects
@ -12,6 +13,13 @@ use Icinga\Module\Monitoring\Object\MonitoredObject;
*/
abstract class DetailviewExtensionHook
{
/**
* The view the generated HTML will be included in
*
* @var View
*/
private $view;
/**
* Create a new hook
*
@ -37,4 +45,27 @@ abstract class DetailviewExtensionHook
* @return string
*/
abstract public function getHtmlForObject(MonitoredObject $object);
/**
* Get {@link view}
*
* @return View
*/
public function getView()
{
return $this->view;
}
/**
* Set {@link view}
*
* @param View $view
*
* @return $this
*/
public function setView($view)
{
$this->view = $view;
return $this;
}
}

View File

@ -101,7 +101,7 @@ abstract class MonitoredObjectController extends Controller
$this->view->extensionsHtml = array();
foreach (Hook::all('Monitoring\DetailviewExtension') as $hook) {
/** @var DetailviewExtensionHook $hook */
$this->view->extensionsHtml[] = $hook->getHtmlForObject($this->object);
$this->view->extensionsHtml[] = $hook->setView($this->view)->getHtmlForObject($this->object);
}
}