diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 38a98c977a..fc9bc39771 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.8 under development ----------------------- +- Bug #7717: Fixed the bug that `$properties` parameter in `ArrayHelper::toArray()` was not passed to recursive calls (quantum13) - Bug #11088: Fixed bug with column name not being quoted correctly, when a quoted table name or a table name in prefix syntax was used (cebe, edgardmessias, Ni-san) - Bug #9074: Fixed JS call `$('#grid').yiiGridView('getSelectedRows')` when `GridView::$showHeader` is set to false (NekitoSP, silverfire) - Bug #9935: Fixed `yii\validators\EachValidator` does not invoke `validateAttribute()` method of the embedded validator (klimov-paul) diff --git a/framework/helpers/BaseArrayHelper.php b/framework/helpers/BaseArrayHelper.php index ebe61fe4e8..ba269a52c5 100644 --- a/framework/helpers/BaseArrayHelper.php +++ b/framework/helpers/BaseArrayHelper.php @@ -93,7 +93,7 @@ class BaseArrayHelper } } - return $recursive ? static::toArray($result) : $result; + return $recursive ? static::toArray($result, $properties) : $result; } else { return [$object]; } diff --git a/tests/framework/helpers/ArrayHelperTest.php b/tests/framework/helpers/ArrayHelperTest.php index 0a100b3cb5..8ef2e6caf8 100644 --- a/tests/framework/helpers/ArrayHelperTest.php +++ b/tests/framework/helpers/ArrayHelperTest.php @@ -27,6 +27,7 @@ class Post2 extends Object class Post3 extends Object { public $id = 33; + /** @var Object */ public $subObject; public function init() @@ -88,6 +89,45 @@ class ArrayHelperTest extends TestCase 'content' => 'test', ], ], ArrayHelper::toArray($object)); + + //recursive with attributes of object and subobject + $this->assertEquals([ + 'id' => 33, + 'id_plus_1' => 34, + 'subObject' => [ + 'id' => 123, + 'id_plus_1' => 124, + ], + ], ArrayHelper::toArray($object, [ + $object->className() => [ + 'id', 'subObject', + 'id_plus_1' => function ($post) { + return $post->id+1; + } + ], + $object->subObject->className() => [ + 'id', + 'id_plus_1' => function ($post) { + return $post->id+1; + } + ], + ])); + + //recursive with attributes of subobject only + $this->assertEquals([ + 'id' => 33, + 'subObject' => [ + 'id' => 123, + 'id_plus_1' => 124, + ], + ], ArrayHelper::toArray($object, [ + $object->subObject->className() => [ + 'id', + 'id_plus_1' => function ($post) { + return $post->id+1; + } + ], + ])); } public function testRemove()