Skip to content

Added a dedicated modifier pool for categories #30119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

bgorski
Copy link
Contributor

@bgorski bgorski commented Sep 20, 2020

Description (*)

This PR greatly decreases chances for conflicts if your application has more than one custom or 3rd party module extending category edit form using modifiers.

The problem:
As we know, ui component forms can be extended either in xml files or using modifiers written in PHP and injected via modifier pools to their corresponding form.
This is easy for products, the etc/adminhtml/di.xml file in the Magento_Catalog module defines a Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool virtual type with some modifiers already there and injects it as the pool argument for Magento\Catalog\Ui\DataProvider\Product\Form\ProductDataProvider. If you want to add your own argument, you simply target that virtual class in your own di.xml and add a new item to the modifiers array.
However, in case of categories it's not that straightforward. Although the overall logic is the same, categories don't have any virtual type for the pool defined. So they get null as the pool argument and end up with the generic Magento\Ui\DataProvider\Modifier\Pool as the pool, which is added in the parent constructor of the data provider. Needless to say, you can't add your own modifiers that are related to category form to that generic pool.
This means that if you want to add modifiers to category form, you need to create your own virtualType for the pool, add your modifier to it and inject it as the pool argument for the data provider for the category form. Which works if you happen to have only one module doing that, but if you have more than one, a conflict is guaranteed (they last one to load wins and overwrites the pool argument with its own pool).
A solution to that is adding a new virtualType for that pool and injecting it as the pool argument directly in the Magento_Core. Although that pool doesn't contain any actual modifiers by default, it serves as a point to which custom/3rd party modules can hook to and add their own modifiers without conflicts.
This is also a backwards-compatible solution, because if you happen to already have some module adding its own pool to the category form, that pool will overwrite the empty one added in this PR (assuming you have a correct sequence in your module.xml, with Magento_Catalog added there).

Manual testing scenarios (*)

  1. None really. Go to a category edit page in the admin panel (which is the only page loading the affected functionality) for any category and ensure it still works if you want to test something.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Added a dedicated modifier pool for categories #30134: Added a dedicated modifier pool for categories

@m2-assistant
Copy link

m2-assistant bot commented Sep 20, 2020

Hi @bgorski. Thank you for your contribution
Here is some useful tips 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

❗ 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:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@bgorski
Copy link
Contributor Author

bgorski commented Sep 20, 2020

@magento run all tests

@bgorski
Copy link
Contributor Author

bgorski commented Sep 21, 2020

@magento run Functional Tests B2B

@rogyar rogyar self-assigned this Sep 21, 2020
@rogyar
Copy link
Contributor

rogyar commented Sep 21, 2020

Hi @bgorski. Thank you for your improvement. From my point of view, that's a good idea since I met a similar problem with the virtual type overriding for the pull. Could we create a simple integration test that ensures that the pool of category data provider is not null after the change introduced in this PR?

@sidolov sidolov added Priority: P3 May be fixed according to the position in the backlog. Risk: low Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”. labels Sep 21, 2020
@sidolov
Copy link
Contributor

sidolov commented Sep 21, 2020

@magento create issue

@bgorski
Copy link
Contributor Author

bgorski commented Sep 21, 2020

Hi @bgorski. Thank you for your improvement. From my point of view, that's a good idea since I met a similar problem with the virtual type overriding for the pull. Could we create a simple integration test that ensures that the pool of category data provider is not null after the change introduced in this PR?

The pool wouldn't be null before this PR is introduced, because the parent constructor assigns a generic Magento\Ui\DataProvider\Modifier\Pool. So we could only create a test testing the object creation (on the object manager level) instead of testing an already created object. However, now I'm thinking that we could as well change the constructor head line:
PoolInterface $pool = null,
to just
PoolInterface $pool,
So this would be indirectly tested by already existing integration tests. Meaning that if it was passed null, it would simply throw Type Error occurred when creating object: Magento\\Catalog\\Model\\Category\\DataProvider\\Interceptor, Argument 13 passed to Magento\\Catalog\\Model\\Category\\DataProvider::__construct() must implement interface Magento\\Ui\\DataProvider\\Modifier\\PoolInterface, null given
@rogyar what do you think?

…ory\DataProvider with null as the modifier pool
@bgorski
Copy link
Contributor Author

bgorski commented Sep 22, 2020

@magento run all tests

@bgorski
Copy link
Contributor Author

bgorski commented Sep 22, 2020

I went ahead and did exactly what I mentioned in my previous comment. The integration test that will test the correct instantiation of the data provider is dev/tests/integration/testsuite/Magento/Catalog/Model/Category/DataProviderTest.php

@bgorski
Copy link
Contributor Author

bgorski commented Sep 22, 2020

@magento run all tests

@bgorski
Copy link
Contributor Author

bgorski commented Sep 22, 2020

@magento run all tests

…el\Category\DataProvider with null as the modifier pool"

This reverts commit 1ac2ab8.
@bgorski
Copy link
Contributor Author

bgorski commented Sep 23, 2020

Actually I reverted the change above. It would be a major change as the data provider is marked with @api. I don't think it's worth it at this point, but I think it would be best to introduce that as a second PR instead of creating a new integration test for the reason I mentioned in one of my comments above - the parent constructor assigns the generic pool, so the change from that null to a pool object could only be checked at the object manager level (before instantiating the data provider). At least without providing a custom di.xml that adds something to the pool of the new virtualType to make the pool testable this way. I haven't done anything like that in any integration tests, though. Is that possible and worth it?

@bgorski
Copy link
Contributor Author

bgorski commented Sep 23, 2020

@magento run all tests

@bgorski
Copy link
Contributor Author

bgorski commented Sep 23, 2020

@magento run Functional Tests B2B, Functional Tests CE

@rogyar
Copy link
Contributor

rogyar commented Sep 27, 2020

Hi @bgorski. Thank you for providing the extended information on that matter. Let's wait with the complex test and check for approval from architects for this change.

Thank you.

Copy link
Contributor

@rogyar rogyar left a comment

Choose a reason for hiding this comment

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

Approving this PR with "Not test required option". I see no easy way to cover this case with an automated test without developing a separate modifier

@magento-engcom-team
Copy link
Contributor

Hi @rogyar, thank you for the review.
ENGCOM-8956 has been created to process this Pull Request

@engcom-Delta engcom-Delta added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Mar 18, 2024
@engcom-Dash engcom-Dash self-assigned this Oct 22, 2024
@engcom-Dash
Copy link
Contributor

Hello @bgorski

Thanks for the collaboration & contribution!

✔️ QA Passed
Preconditions:

Install fresh Magento 2.4-develop
Steps to reproduce

  • As per the description

Category edit page is working as expected with the changes from PR.

Builds are failed. Hence, moving this PR to Extended Testing.

Thanks

@engcom-Dash
Copy link
Contributor

@magento run all tests

@engcom-Dash
Copy link
Contributor

@magento run Unit Tests, Magento Health Index, Functional Tests B2B

@engcom-Dash
Copy link
Contributor

@magento run all tests

@engcom-Dash
Copy link
Contributor

@magento run Functional Tests EE, Functional Tests B2B

@engcom-Dash
Copy link
Contributor

engcom-Dash commented Oct 29, 2024

Hello @bgorski,

Thanks for your contributions!

Moving this PR to on hold since it’s a feature request and we need PO approval for it. Once we get approval, we will proceed accordingly.

Thanks.

@engcom-Dash
Copy link
Contributor

Hello @bgorski,

We have received the go-ahead on this PR from the PO. We are moving it to extended testing for now to analyze the build results with the latest code.

Thanks.

@engcom-Dash
Copy link
Contributor

@magento run all tests

@engcom-Dash
Copy link
Contributor

@magento run Functional Tests CE, Functional Tests B2B

@engcom-Dash
Copy link
Contributor

Moving this PR to Extended Testing to resolve the conflicts

@engcom-Dash engcom-Dash moved this from Merge in Progress to Extended Testing (optional) in Pull Requests Dashboard Jun 25, 2025
@engcom-Dash
Copy link
Contributor

@magento run all tests

@engcom-Dash
Copy link
Contributor

@magento run Functional Tests B2B, Unit Tests

1 similar comment
@engcom-Dash
Copy link
Contributor

@magento run Functional Tests B2B, Unit Tests

@engcom-Dash
Copy link
Contributor

@magento run all tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests Component: Catalog Partner: MRM Commerce partners-contribution Pull Request is created by Magento Partner Priority: P3 May be fixed according to the position in the backlog. Progress: extended testing Progress: ready for testing Release Line: 2.4 Risk: low Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Extended Testing (optional)
Development

Successfully merging this pull request may close these issues.

[Issue] Added a dedicated modifier pool for categories
6 participants