When using almost any of the core Yii 2 widgets you cannot attach afterRun event and change the result, because most of the core widgets are using echo instead of returning the value, effectively making $result always being an empty string.
Run any widget which has echo in their run() method or uses other methods which have echo command in it. For instance GridView widget.
Affected widgets:
List view / Grid view:
https://github.com/yiisoft/yii2/blob/9e5c4abdb8d99811b8c4fdc5dc376e22c9f0d662/framework/widgets/BaseListView.php#L145
Breadcrumbs:
https://github.com/yiisoft/yii2/blob/9e5c4abdb8d99811b8c4fdc5dc376e22c9f0d662/framework/widgets/Breadcrumbs.php#L150
Content decorator:
https://github.com/yiisoft/yii2/blob/9e5c4abdb8d99811b8c4fdc5dc376e22c9f0d662/framework/widgets/ContentDecorator.php#L79
Detail view:
https://github.com/yiisoft/yii2/blob/9e5c4abdb8d99811b8c4fdc5dc376e22c9f0d662/framework/widgets/DetailView.php#L164
Fragement cache:
https://github.com/yiisoft/yii2/blob/9e5c4abdb8d99811b8c4fdc5dc376e22c9f0d662/framework/widgets/FragmentCache.php#L104
Link sorter:
https://github.com/yiisoft/yii2/blob/9e5c4abdb8d99811b8c4fdc5dc376e22c9f0d662/framework/widgets/LinkSorter.php#L69
Masked Input:
https://github.com/yiisoft/yii2/blob/9e5c4abdb8d99811b8c4fdc5dc376e22c9f0d662/framework/widgets/MaskedInput.php#L127


$event->result should not be empty to have at least some data after running any of the affected widgets.
$event->result is empty.
| Q | A
| ---------------- | ---
| Yii version | 2.0.15
| PHP version | 7.0
| Operating system | Linux Mint
Hi. That change is backwards incompatible. Here's the example:
https://github.com/yiisoft/yii2/blob/master/framework/widgets/BaseListView.php#L145 (return instead of echo)
https://github.com/yiisoft/yii2/blob/master/framework/grid/GridView.php#L301 (return instead of echo)
https://github.com/kartik-v/yii2-grid/blob/master/src/GridView.php#L1143 (External package).
It assumes that BaseListView should echo widget content instead of return it.
So, with following dependency chain:
"kartik-v/yii2-grid" depends on "kartik-v/yii2-krajee-base": ">=1.9.8" "kartik-v/yii2-krajee-base" depends on "yiisoft/yii2-bootstrap": "@dev""yiisoft/yii2-bootstrap" depends on "yiisoft/yii2": "~2.0.6".And "minimum-stability": "dev" in your composer.json.
The result of $res = \kartik\grid\GridView::widget([...]) would be '' (empty string)
@samdark, could you please give any comments on this?
Both echo and return should be supported.
This probably breaks yii\widgets\Pjax widget as well - since the default usage for Pjax Widget is to include a content between Pjax::begin and Pjax::end - somehow the Pjax::begin does not echo the begin content out. It seems Pjax widget code includes the begin part of the content within the Pjax::init method and that part returned is not echoed.
Can you check the usage? Pjax widget code may need some redesign if this BC breaking update is included.