-
Notifications
You must be signed in to change notification settings - Fork 9.4k
#10402 fix theme templates overrides in environment emulation cross-area #10403
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
#10402 fix theme templates overrides in environment emulation cross-area #10403
Conversation
In such case |
|
Note that |
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 rewrite method in such a way that if we go through line 141 getThemeById call is used and getThemeByFullPath otherwise.
Also, such case with emulated cross-area needs to be covered with integration test.
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.
Actually, also for line 145 getThemeById should be called as getConfigurationDesignTheme returns the id. I don't have time to write integration test at this moment, unfortunately.
Should I open another PR on develop branch?
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 changed base branch, please force push into the same branch applying your commit on top of develop.
Yeah, you are right about line 145.
Just finish your implementation without integration test then.
…cross-area Row 141 and 145 are obviously returning a theme id, so we'd better load the theme by id. I'm not sure if execution will fall into row 143 what to expect.
… cross-area Load theme by full path only in case we received a 'theme' in $params
2c83345 to
72ed28e
Compare
|
Pushed the suggested change and the fix to the unit test. |
|
Please try to simplify modified method Maybe we can leave only one exception throwing and decrease amount of |
|
Just moving the exception throwing was not enough to go below 200. On top of that, I found that in case we load the theme by id we should ensure that the theme exists in the requested area (this is implicit in the load by full path), so I added that check and refactored a bit. |
…he theme param returned by getConfigurationDesignTheme is an id or a path
|
The issue unveiled by the integration tests run is that
So my (ugly) solution is that, in case we rely on A more appropriate solution would be to modify the implementation of |
| } | ||
| } elseif (empty($params['themeModel'])) { | ||
| if (empty($params['themeModel'])) { | ||
| $params['themeModel'] = $this->getDefaultParameter('themeModel'); |
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.
For better readability please do $themeModel = ... instead of $params['themeModel'] = ... and only in the very end do $params['themeModel'] = $themeModel ?: $this->getDefaultParameter('themeModel').
| * @return \Magento\Framework\View\Design\ThemeInterface | ||
| */ | ||
| private function getTheme($theme, $area) | ||
| { |
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.
Yeah, looking into \Magento\Theme\Model\View\Design::getConfigurationDesignTheme this seems to be the best option to me (although we won't support string theme identifiers consisting of digits only).
Can we eliminate this method and still pass PHPMD? getThemeById and getThemeByPath seem much more understandable to me at the place of call but I would like to avoid method named like getThemeByIdOrPath.
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.
Moving this in the method we wouldn't pass the cyclomatic complexity
| private function getThemeByPath($themePath, $area) | ||
| { | ||
| $themeModel = $this->getThemeProvider()->getThemeByFullPath($area . '/' . $themePath); | ||
| if (!$themeModel) { |
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 reword Could not find theme by full path ...
| private function getThemeById($themeId, $area) | ||
| { | ||
| $themeModel = $this->getThemeProvider()->getThemeById($themeId); | ||
| if (!$themeModel || $themeModel->getArea() != $area) { |
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 reword Could not find theme by id ...
| $this->themeProvider | ||
| ->expects($this->any()) | ||
| ->method('getThemeByFullPath') | ||
| ->with('frontend/Magento/luma') |
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 avoid Luma theme mentioning in framework, just use some fictional theme path (fix both occurrences).
| if (empty($params['area'])) { | ||
| $params['area'] = $this->getDefaultParameter('area'); | ||
| } | ||
|
|
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 this method was refactored significantly, please remove @SuppressWarnings(PHPMD.CyclomaticComplexity), probably it is already passing this check.
| return $themeModel; | ||
| } | ||
|
|
||
| /** |
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.
Change to int.
|
Thanks, your findings look great to me, especially that there was Would be great if you add case to check new logic into some existing integration test but it's not mandatory. Please check my comments to slightly polish up the code. |
|
@alessandroniciforo there is one real failure left: https://travis-ci.org/magento/magento2/jobs/261023165 Could you please look into it? |
|
@alessandroniciforo @orlangur Is there any progress on this Pull Request? |
|
@ishakhsuvarov I planned to look into this failure if Alessandro will not do it as fix seems quite valuable to me. Didn't have time yet, will have during this weekend. Feel free to investigate failure yourself (maybe it occurred already in some other circumstances already?) or close this PR for now, I'll reopen when ready. |
|
Hi All |
|
@diamondavocado sure, not sure how it could help though since you are not an author :) |
|
Hi @alessandroniciforo. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
|
|
|
Hey guys, |
|
Hi @alessandroniciforo , thank you for your contribution! Unfortunately, we are no longer accept contributions to 2.1-develop and 2.2-develop branches. Looks like the issue was fixed in the scope of d3e32b4, as you mentioned before. |
|
Hi @alessandroniciforo, thank you for your contribution! |
Row 141 and 145 are obviously returning a theme id, so we'd better load the theme by id. I'm not sure if execution will fall into row 143 what to expect.
Fixed Issues (if relevant)