-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Replace hard-coded list of category attributes #28216
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
Replace hard-coded list of category attributes #28216
Conversation
Hi @fredden. Thank you for your contribution
❗ Automated tests can be triggered only manually with an appropriate comment:
ℹ️ 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. |
It works in |
@magento run all tests |
This looks good, I also tested it in |
@magento-engcom-team any idea why there are no build reports? |
@magento run all tests |
…category_form-hard-coded-list
…category_form-hard-coded-list
@magento run all tests |
@@ -233,6 +241,7 @@ public function __construct( | |||
$this->storeManager = $storeManager; | |||
$this->request = $request; | |||
$this->categoryFactory = $categoryFactory; | |||
$this->uiConfigFactory = $uiConfigFactory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep backward compatibility let's add nullable argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, Magento's stance on extension is to prefer composition over inheritance. If a third party has extended this model via a preference (which is documented as "a method of last resort"), then keeping their extension up to date with changes here is a necessary cost to using such a technique. I do not see any benefit in using a nullable argument here.
My objections aside, I do not know how to create this object if not via dependency injection. (I have no experience with the Object Manager as "Magento prohibits the direct use of the ObjectManager
" and any existing usages "are not tacit endorsements of using the ObjectManager
directly." I understand this exists as an internal implementation detail of Magento's dependency injection system.)
How should I create this virtualType
if not supplied via dependency injection?
magento2/app/code/Magento/Ui/etc/di.xml
Lines 339 to 343 in 8b7d949
<virtualType name="uiComponentConfigFactory" type="Magento\Framework\Config\DataInterfaceFactory"> | |
<arguments> | |
<argument xsi:type="string" name="instanceName">Magento\Ui\Config\Data</argument> | |
</arguments> | |
</virtualType> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right about composition over inheritance principle. However, constructor modification is considered as a braking change. As a workaround, we recommend adding new optional parameter to the constructor at the end of the arguments list.
Please refer to the Backward compatible development guide and section about Adding a constructor parameter
.
} | ||
|
||
// Remove empty groups | ||
if (empty($fieldsMap[$group])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we can remove this along with assignment in the line 674.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we can remove this and the assignment on 674. I'd prefer to keep these however, as I feel like this method is more explicit in intent: showing clearly that empty groups are omitted on purpose.
The PHP manual also suggests that implicit array creation is discouraged. (Emphasis is mine.)
If $arr doesn't exist yet, it will be created, so this is also an alternative way to create an array. This practice is however discouraged because if $arr already contains some value (e.g. string from request variable) then this value will stay in the place and [] may actually stand for string access operator. It is always better to initialize a variable by a direct assignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I'd prefer creating array variable to collect needed data and if it is not empty, write this data to $fieldsMap[$group]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see review comments.
Looks like the fix should be applied to commerce repo. You can easily open commerce PR and link this this one through PR description.
@magento run all tests |
…e specific value - SVC test fix.
@magento run all tests |
✔️ QA Passed Manual testing scenario:
Before: After: |
@magento run all tests |
1 similar comment
@magento run all tests |
Hi @fredden, thank you for your contribution! |
Description
Magento\Catalog\Model\Category\DataProvider::getFieldsMap()
had a hard-coded list of category attributes. This pull request replaces this with a list generated from cache. The cache is built from readingview/adminhtml/ui_component/category_form.xml
files, so this dynamically generated list includes all category attributes, not only those in the hard-coded list.Fixed Issues
Related Pull Requests
https://github.com/magento/partners-magento2ee/pull/267
Manual testing scenarios
See issue #13440 for reproduction steps, expected result, and actual result.
Questions or comments
magento/module-catalog-staging
will need to also be updated for Commerce as a similar hard-coded list exists there and that class extends this. - See https://github.com/magento/partners-magento2ee/pull/267Contribution checklist (*)