[Adminhtml] add Events to Widget Grid#5169
Conversation
|
How about using For _afterLoadCollection and _prepareColums we have to change some code to call parent method (instead of |
|
@sreichel Block doesn't have |
|
@sreichel would it make sense to use Block#getId for Event Names? Like this? Mage::dispatchEvent('grid_prepare_columns_after_' . $this->getId(), ['grid' => $this]); |
Add dynamic events
There was a problem hiding this comment.
Pull request overview
This pull request aims to add events to the Adminhtml Widget Grid to allow modifications without extending grid classes. The PR adds two pairs of events (prepare_collection_after and prepare_columns_after/before) and updates several grid child classes to properly call their parent methods.
Changes:
- Added grid lifecycle events (
prepare_collection_after,prepare_columns_before/after) - Fixed grid child classes to properly call parent methods instead of returning
$thisdirectly
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| app/code/core/Mage/Adminhtml/Block/Widget/Grid.php | Added event dispatching in grid lifecycle methods |
| app/code/core/Mage/Index/Block/Adminhtml/Process/Grid.php | Changed to call parent::_afterLoadCollection() |
| app/code/core/Mage/Adminhtml/Block/Urlrewrite/Product/Grid.php | Changed to call parent::_prepareColumns() via fully qualified name |
| app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid.php | Changed to call parent::_prepareColumns() |
| app/code/core/Mage/Adminhtml/Block/Review/Product/Grid.php | Changed to call parent::_prepareColumns() via fully qualified name |
| app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid.php | Changed to call parent::_prepareColumns() |
| app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php | Changed to call parent::_prepareColumns() |
| app/code/core/Mage/Adminhtml/Block/Cache/Grid.php | Changed to call parent::_afterLoadCollection() |
|
i know, but we can add it. :) how about ... Mage::dispatchEvent('adminhtml_widget_grid_prepare_collection_before', [
'collection' => $collection,
]);
if ($this->_eventPrefix !== '') {
Mage::dispatchEvent($this->_eventPrefix . '_prepare_collection_before', [
'collection' => $collection,
]);
} |
…eature/widgetGridEvents # Conflicts: # app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Roles.php # app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php # app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag.php # app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php # app/code/core/Mage/Adminhtml/Block/Catalog/Search/Grid.php # app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Grid.php # app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid.php # app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Tag.php # app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist.php # app/code/core/Mage/Adminhtml/Block/Customer/Grid.php # app/code/core/Mage/Adminhtml/Block/Customer/Group/Grid.php # app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php # app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Last.php # app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Top.php # app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Customers/Newest.php # app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid.php # app/code/core/Mage/Adminhtml/Block/Permissions/Block/Grid.php # app/code/core/Mage/Adminhtml/Block/Permissions/Role/Grid/User.php # app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Roles.php # app/code/core/Mage/Adminhtml/Block/Permissions/Variable/Grid.php # app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Grid.php # app/code/core/Mage/Adminhtml/Block/Promo/Quote/Grid.php # app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned/Grid.php # app/code/core/Mage/Adminhtml/Block/Review/Grid.php # app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php # app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php # app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php # app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Grid.php # app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Invoices.php # app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php # app/code/core/Mage/Adminhtml/Block/System/Variable/Grid.php # app/code/core/Mage/Adminhtml/Block/Tag/Grid/Products.php # app/code/core/Mage/Adminhtml/Block/Tag/Tag/Grid.php # app/code/core/Mage/Adminhtml/Block/Tax/Rule/Grid.php # app/code/core/Mage/Adminhtml/Block/Widget/Grid.php # app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Abstract.php # app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php # app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tab/Users.php # app/code/core/Mage/Index/Block/Adminhtml/Process/Grid.php # app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Grid.php # app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Grid.php
# Conflicts: # app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid.php # app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid.php
|





Description (*)
This adds some Events to the Adminhtml/Widget/Grid,
allowing it to add more Columns without the need to extend the Grid classes.
Example:
set_collectionEventprepare_columns_afterEventRelated Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)