magento2
magento2 copied to clipboard
Extend Observer declaration in events.xml by new attribute ifconfig
Description (*)
Extension of Observer declaration in events.xml by new optional attribute ifconfig with appropriate handling of it. Similar to usage of ifconfig in layout's xml files - it executes (or not) Observer depending on boolean value of given config path. The purpose is to condition Observer's execution on config paths representing module's state - usually <module/general/active> or <module/general/enabled> etc.
Manual testing scenarios (*)
- Add ifconfig attribute to Observer A declaration in events.xml file where its value will be config path and dispatch event to trigger Observer. a) When config path value equals to true - Observer should execute. b) When config path value equals to false - Observer should not execute c) When config does not exist (path does not represent any actual value) - Observer should not execute
- Add ifconfig attribute to Observer A declaration in events.xml file where its value is empty string "" and dispatch event to trigger Observer. Observer should execute.
Contribution checklist (*)
- [X] Pull request has a meaningful description of its purpose
- [X] All commits are accompanied by meaningful commit messages
- [X] All new or changed code is covered with unit/integration tests (if applicable)
- [X] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- [X] All automated tests passed successfully (all builds are green)
Resolved issues:
- [x] resolves magento/magento2#38514: Extend Observer declaration in events.xml by new attribute ifconfig
Hi @bartekAtconvert. Thank you for your contribution! Here are some useful tips on how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:
@magento give me test instance- deploy test instance based on PR changes@magento give me 2.4-develop instance- deploy vanilla Magento instance
:exclamation: Automated tests can be triggered manually with an appropriate comment:
@magento run all tests- run or re-run all required tests against the PR changes@magento run <test-build(s)>- run or re-run specific test build(s) For example:@magento run Unit Tests
<test-build(s)> is a comma-separated list of build names.
Allowed build names are:
Database CompareFunctional Tests CEFunctional Tests EEFunctional Tests B2BIntegration TestsMagento Health IndexSample Data Tests CESample Data Tests EESample Data Tests B2BStatic TestsUnit TestsWebAPI TestsSemantic Version Checker
You can find more information about the builds here :information_source: Run only required test builds during development. Run all test builds before sending your pull request for review.
For more details, review the Code Contributions documentation. Join Magento Community Engineering Slack and ask your questions in #github channel.
Failed to run the builds. Please try to re-run them later.
@magento run all tests
@magento create issue
Failed to run the builds. Please try to re-run them later.
@magento run WebAPI Tests
Failed to run the builds. Please try to re-run them later.
@magento run Unit Tests
@magento run Static Tests
@magento run Unit Tests
@magento run Static Tests
@magento run WebAPI Tests
@magento run Database Compare
@magento run Static Tests
@magento run WebAPI Tests
Ha I was just running into this this week! I was wondering whether it existed.
My usecase; I wanted to add an ifconfig here in events.xml that checks for this config value from system.xml so I didn't have to do this in the observer.
@magento run all tests
@magento run all tests
@magento run all tests
@magento run all tests
@magento run Functional Tests B2B, Functional Tests EE, Functional Tests CE, Integration Tests, WebAPI Tests
@bartekAtconvert,
Thank you for the contribution and collaboration!
✔️ QA Passed
Steps to reproduce:
- Add ifconfig attribute to Observer A declaration in events.xml file where its value will be config path and dispatch event to trigger Observer. a) When config path value equals to true - Observer should execute. b) When config path value equals to false - Observer should not execute c) When config does not exist (path does not represent any actual value) - Observer should not execute
- Add ifconfig attribute to Observer A declaration in events.xml file where its value is empty string "" and dispatch event to trigger Observer. Observer should execute.
Before: ✖️ No ability to condtion the execution of observer.
After: ✔️ Able to conditionalize observer execution.
Created a module with observer, and added ifconfig in events.xml, observer is getting trigerred when config path in ifconfig is true.
Please refer the screenshot:
- Created a system configuration for ifconfig attribute, when this is enabled or the path for ifconfig is empty the observer is trigerred and it will be logged(for testing purpose).
log output:
[2024-06-11T10:06:03.927013+00:00] main.DEBUG: custom event Triggered [] []
- If the config is disabled or if the config path passed to ifconfig is incorrect, the observer will not be trigerred and the value will not be logged.
Please find the custom module used to test this PR. P38493V.zip
Thank you.
As the linked issue is tagged as feature request, moving this to on hold for PO confirmation.
As the linked issue is tagged as feature request, moving this to on hold for PO confirmation.
We have a confirmation from Product Owner on this feature request issue hence moving it back to Extended Testing.
@magento run all tests
@magento run all tests
Raised internal approval Jira for the SVC failure. Moving this PR to Pending Approval now. We will proceed ahead on this once will get all the required approvals.