Add renderPartial event to match renderContent

Fixes #2519
Fixes #2533
This commit is contained in:
Samuel Georges 2016-12-09 08:15:32 +11:00
parent 4b79531499
commit 1bdedb5584
1 changed files with 26 additions and 6 deletions

View File

@ -780,10 +780,19 @@ class Controller
$name = '::' . substr($name, 1);
}
/*
* Extensibility
*/
if (
($event = $this->fireEvent('page.beforeRenderPartial', [$name], true)) ||
($event = Event::fire('cms.page.beforeRenderPartial', [$this, $name], true))
) {
$partial = $event;
}
/*
* Process Component partial
*/
if (strpos($name, '::') !== false) {
elseif (strpos($name, '::') !== false) {
list($componentAlias, $partialName) = explode('::', $name);
@ -802,10 +811,10 @@ class Controller
return false;
}
}
}
/*
* Component alias is supplied
*/
}
else {
if (($componentObj = $this->findComponentByName($componentAlias)) === null) {
if ($throwException) {
@ -866,7 +875,6 @@ class Controller
/*
* Run functions for CMS partials only (Cms\Classes\Partial)
*/
if ($partial instanceof Partial) {
$this->partialStack->stackPartial();
@ -877,8 +885,9 @@ class Controller
// Not sure if they're needed there by the requirements,
// but there were problems with array-typed properties used by Static Pages
// snippets and setComponentPropertiesFromParams(). --ab
if ($component == 'viewBag')
if ($component == 'viewBag') {
continue;
}
list($name, $alias) = strpos($component, ' ')
? explode(' ', $component)
@ -915,7 +924,7 @@ class Controller
CmsException::mask($partial, 400);
$this->loader->setObject($partial);
$template = $this->twig->loadTemplate($partial->getFilePath());
$result = $template->render(array_merge($this->vars, $parameters));
$partialContent = $template->render(array_merge($this->vars, $parameters));
CmsException::unmask();
if ($partial instanceof Partial) {
@ -923,7 +932,18 @@ class Controller
}
$this->vars = $vars;
return $result;
/*
* Extensibility
*/
if (
($event = $this->fireEvent('page.renderPartial', [$name, $partialContent], true)) ||
($event = Event::fire('cms.page.renderPartial', [$this, $name, $partialContent], true))
) {
return $event;
}
return $partialContent;
}
/**