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 ...@@ -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 #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 #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 #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 #1799: Added `form_begin`, `form_end` to twig extension (samdark)
- Enh #3674: Various enhancements (samdark) - Enh #3674: Various enhancements (samdark)
- Removed `FileLoader` and used `\Twig_Loader_Filesystem` instead. - Removed `FileLoader` and used `\Twig_Loader_Filesystem` instead.
......
...@@ -54,11 +54,6 @@ class Extension extends \Twig_Extension ...@@ -54,11 +54,6 @@ class Extension extends \Twig_Extension
]; ];
} }
public function initRuntime(\Twig_Environment $environment)
{
$environment->setBaseTemplateClass('yii\twig\Template');
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
......
...@@ -14,12 +14,14 @@ namespace yii\twig; ...@@ -14,12 +14,14 @@ namespace yii\twig;
*/ */
abstract class Template extends \Twig_Template 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 // 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 ($object instanceof \yii\db\BaseActiveRecord) {
if ($type == \Twig_Template::METHOD_CALL) { if ($type === \Twig_Template::METHOD_CALL) {
return $object->$item(); return $object->$item();
} else { } else {
return $object->$item; return $object->$item;
......
...@@ -98,6 +98,8 @@ class ViewRenderer extends BaseViewRenderer ...@@ -98,6 +98,8 @@ class ViewRenderer extends BaseViewRenderer
'charset' => Yii::$app->charset, 'charset' => Yii::$app->charset,
], $this->options)); ], $this->options));
$this->twig->setBaseTemplateClass('yii\twig\Template');
// Adding custom globals (objects or static classes) // Adding custom globals (objects or static classes)
if (!empty($this->globals)) { if (!empty($this->globals)) {
$this->addGlobals($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