Commit 7aa6a30d by Alexander Makarov

Fixes #4290: Fixed throwing exception when trying to access AR relation that is null

parent fd5e05b1
......@@ -7,6 +7,7 @@ Yii Framework 2 twig extension Change Log
- Bug #2925: Fixed throwing exception when accessing AR property with null value (samdark)
- Bug #3767: Fixed repeated adding of extensions when using config. One may now pass extension instances as well (grachov)
- Bug #3877: Fixed `lexerOptions` throwing exception (dapatrese)
- Bug #4290: Fixed throwing exception when trying to access AR relation that is null (samdark, tenitski)
- Enh #1799: Added `form_begin`, `form_end` to twig extension (samdark)
- Enh #3674: Various enhancements (samdark)
- Removed `FileLoader` and used `\Twig_Loader_Filesystem` instead.
......
......@@ -54,11 +54,6 @@ class Extension extends \Twig_Extension
];
}
public function initRuntime(\Twig_Environment $environment)
{
$environment->setBaseTemplateClass('yii\twig\Template');
}
/**
* @inheritdoc
*/
......
......@@ -14,12 +14,14 @@ namespace yii\twig;
*/
abstract class Template extends \Twig_Template
{
protected function getAttribute($object, $item, array $arguments = array(), $type = \Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
/**
* @inheritdoc
*/
protected function getAttribute($object, $item, array $arguments = [], $type = \Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
{
// Twig uses isset() to check if attribute exists which does not work when attribute exists but is null
if ($object instanceof \yii\db\BaseActiveRecord) {
if ($type == \Twig_Template::METHOD_CALL) {
if ($type === \Twig_Template::METHOD_CALL) {
return $object->$item();
} else {
return $object->$item;
......
......@@ -98,6 +98,8 @@ class ViewRenderer extends BaseViewRenderer
'charset' => Yii::$app->charset,
], $this->options));
$this->twig->setBaseTemplateClass('yii\twig\Template');
// Adding custom globals (objects or static classes)
if (!empty($this->globals)) {
$this->addGlobals($this->globals);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment