Skip to content

[Adminhtml] add Events to Widget Grid#5169

Open
Hanmac wants to merge 18 commits intoOpenMage:mainfrom
Hanmac:feature/widgetGridEvents
Open

[Adminhtml] add Events to Widget Grid#5169
Hanmac wants to merge 18 commits intoOpenMage:mainfrom
Hanmac:feature/widgetGridEvents

Conversation

@Hanmac
Copy link
Contributor

@Hanmac Hanmac commented Dec 18, 2025

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:

  • you can add a Join to another table in the set_collection Event
  • and then add Columns in the prepare_columns_after Event

Related Pull Requests

  • see OpenMage/magento-lts#<issue_number>

Fixed Issues (if relevant)

  • fixes OpenMage/magento-lts#<issue_number>

Manual testing scenarios (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

@github-actions github-actions bot added the Component: Adminhtml Relates to Mage_Adminhtml label Dec 18, 2025
@sreichel
Copy link
Contributor

How about using $_eventPrefix to access specific grids?

For _afterLoadCollection and _prepareColums we have to change some code to call parent method (instead of return $this).

@sreichel sreichel added this to the 20.18.0 milestone Dec 20, 2025
@github-actions github-actions bot added the Component: Index Relates to Mage_Index label Jan 5, 2026
@Hanmac
Copy link
Contributor Author

Hanmac commented Jan 5, 2026

@sreichel Block doesn't have $_eventPrefix (yet)
it is only defined for Core_Model_Abstract

@Hanmac
Copy link
Contributor Author

Hanmac commented Jan 8, 2026

@sreichel would it make sense to use Block#getId for Event Names?

Like this?

Mage::dispatchEvent('grid_prepare_columns_after_' . $this->getId(), ['grid' => $this]);

@Hanmac Hanmac marked this pull request as ready for review January 20, 2026 13:48
Add dynamic events
@addison74 addison74 requested a review from Copilot January 28, 2026 18:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 $this directly

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()

@sonarqubecloud
Copy link

@sreichel
Copy link
Contributor

sreichel commented Feb 23, 2026

@sreichel Block doesn't have $_eventPrefix (yet) it is only defined for Core_Model_Abstract

i know, but we can add it. :)

how about ... getId() would work, but i'd prefer unified naming pattern. 🤓

            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
@github-actions github-actions bot added Component: PayPal Relates to Mage_Paypal Component: Core Relates to Mage_Core Component: Catalog Relates to Mage_Catalog Component: Sales Relates to Mage_Sales Component: Widget Relates to Mage_Widget Component: Oauth Relates to Mage_Oauth Component: Bundle Relates to Mage_Bundle Component: Api2 Relates to Mage_Api2 phpstan labels Mar 20, 2026
@sreichel
Copy link
Contributor

@sreichel would it make sense to use Block#getId for Event Names?

@Hanmac imho ... as for models the eventname should follow classnaming. (and getId() could be same for differnt grids)

Added "some" eventprefixes to grids ... please revert if its not okay.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
24.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Adminhtml Relates to Mage_Adminhtml Component: Api2 Relates to Mage_Api2 Component: Bundle Relates to Mage_Bundle Component: Catalog Relates to Mage_Catalog Component: Core Relates to Mage_Core Component: Index Relates to Mage_Index Component: Oauth Relates to Mage_Oauth Component: PayPal Relates to Mage_Paypal Component: Sales Relates to Mage_Sales Component: Widget Relates to Mage_Widget phpstan

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants