Fixes #839 - When rendering partials from component PHP code, be firm about the context
This commit is contained in:
parent
ae8289735c
commit
df3e66246f
|
|
@ -168,6 +168,16 @@ abstract class ComponentBase extends Extendable
|
||||||
return $this->alias;
|
return $this->alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a requested partial in context of this component,
|
||||||
|
* see Cms\Classes\Controller@renderPartial for usage.
|
||||||
|
*/
|
||||||
|
public function renderPartial()
|
||||||
|
{
|
||||||
|
$this->controller->setComponentContext($this);
|
||||||
|
return call_user_func_array([$this->controller, 'renderPartial'], func_get_args());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the event cycle when running an AJAX handler.
|
* Executes the event cycle when running an AJAX handler.
|
||||||
* @return boolean Returns true if the handler was found. Returns false otherwise.
|
* @return boolean Returns true if the handler was found. Returns false otherwise.
|
||||||
|
|
|
||||||
|
|
@ -84,11 +84,6 @@ class Controller extends BaseController
|
||||||
*/
|
*/
|
||||||
protected $pageContents;
|
protected $pageContents;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string Alias name of an executing component.
|
|
||||||
*/
|
|
||||||
protected $componentContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array A list of variables to pass to the page.
|
* @var array A list of variables to pass to the page.
|
||||||
*/
|
*/
|
||||||
|
|
@ -99,8 +94,19 @@ class Controller extends BaseController
|
||||||
*/
|
*/
|
||||||
protected $statusCode = 200;
|
protected $statusCode = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var self Cache of self
|
||||||
|
*/
|
||||||
protected static $instance = null;
|
protected static $instance = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Cms\Classes\ComponentBase Object of the active component, used internally.
|
||||||
|
*/
|
||||||
|
protected $componentContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array Component partial stack, used internally.
|
||||||
|
*/
|
||||||
protected $partialComponentStack = [];
|
protected $partialComponentStack = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -701,7 +707,7 @@ class Controller extends BaseController
|
||||||
}
|
}
|
||||||
elseif (($componentObj = $this->findComponentByPartial($partialName)) === null) {
|
elseif (($componentObj = $this->findComponentByPartial($partialName)) === null) {
|
||||||
if ($throwException) {
|
if ($throwException) {
|
||||||
throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name'=>$name]));
|
throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name'=>$partialName]));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1095,6 +1101,16 @@ class Controller extends BaseController
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the component context manually, used by Components when calling renderPartial.
|
||||||
|
* @param ComponentBase $component
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setComponentContext(ComponentBase $component)
|
||||||
|
{
|
||||||
|
$this->componentContext = $component;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets component property values from partial parameters.
|
* Sets component property values from partial parameters.
|
||||||
* The property values should be defined as {{ param }}.
|
* The property values should be defined as {{ param }}.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue