-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fix relative template references in individual Magento modules #1895
Fix relative template references in individual Magento modules #1895
Conversation
Relative template references work up until 3rd party code attempts to use a DI to change a block type via a preference, thus changing the base for the relative template reference from the original module to their own. This replacement done globally via following regex on any *.xml files in `app/code/Magento`: match: `<block class="Magento\\([^\\"]+)\\(.*)template="([^:"]+)"` replace: `<block class="Magento\\$1\\$2template="Magento_$1::$3"`
Question: should there be a static code test to enforce these are absolute template references in core layout code? |
We keep running into issues with these relative template paths when building a new (3rd party) module to extend some functionality of a block class. In several instances the templates all of the sudden stop showing up because they don't exist in the new module's directory. It seems like some template definitions are set that includes the module name, and other are not. Our current workaround is to define a layout update in the new module to point every template that uses the block class back to the original module by including the module in the template path. It seems like having the core modules explicitly state the module in the template path would be a more reasonable thing to standardize on. Either way it is frustrating running into the differences where some templates have the module name and others do not. |
We have automated a Magento Contributor License Agreement verifier for contributions sent to our GitHub projects. |
…tive-template-paths # Conflicts: # app/code/Magento/Catalog/view/adminhtml/layout/catalog_product_set_edit.xml # app/code/Magento/Customer/view/frontend/layout/default.xml # app/code/Magento/GroupedProduct/view/adminhtml/layout/catalog_product_grouped.xml # app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_new.xml
Relative templates implementation needs more internal discussion |
@vkublytskyi Is there a sticky point with this which you could shed some light on? Not having had this right out of the gate is causing major holdups in theme customizations, and it's been > 6 months since I initially submitted the PR. I'd love to see it included, and am willing to help and/or dialog to get us all to the same end goal: making things consistent and usable for developers. |
Let me describe an alternative solution. Please reply with your thoughts.
|
@davidalger This will be taken soon into progress, would be great if you provide your feedback on alternative proposal described above. |
@vkorotun - Let me know if this is correct. If you resolve the template path earlier, any relative template path would always end up relating to the module where the block was originally defined in a layout file, and relative template paths would just be relegated to being a short hand way of defining the layout path, rather than having them always be fully qualified with the prefix of the module name, it in effect becomes the same thing as if it was fully stated. If the relative paths are only ever used when originally defining a block in the layout, and it always resolves to the path of the module it was defined in, what would be the purpose of ever using a relative path at that point? Is the intention of relative template paths just supposed to be a shorthand? Consistency in the core is important, and that was one thing I noticed initially is that it seemed to be inconsistent where relative template paths were used, and where prefixed template paths were used, and that made it a lot more difficult to know what to expect when trying to extend functionality in different ways. If this change in functionality occurs, then would you state relative paths in all the block declaration layout files that are referencing their own module's template path, or would you put in the module prefix on all of them? |
Internal ticket: MAGETWO-60451 |
@davidalger I'm ready to go ahead and accept this PR. Will you be willing to help with that? If yes, what I need from you:
P.S.: I read again the initial comment and my question regarding script is answered. |
@vrann Awesome! thank you! :) I've updated the branch with latest from develop, and then used the following one-liner to update new references which came in on the merge:
After I did that, I used
This turns up a few relative references in the integration tests, but I'm not certain those should change, so I left them alone. That first command should make EE and B2B repos very happy! I'll see if I can get to the test next week, I'm under the gun on an end-of-month deadline atm and traveling to a friends wedding over the weekend, so I'm not sure yet. |
@davidalger perfect, now I'm working on EE, B2B and static tests. |
@davidalger few occurrences in CE was not fixed, not sure yet why they are not caught. One issue is it seems the script does not take into account the template attribute on the new line. Though this one is weird
|
@davidalger fixing those and the failing static test |
@davidalger ok, fixed everything mentioned before. The new tricky part if virtual types for the blocks. Here is an instance which failing:
See how the reference to the template different from the real instance of the block. |
@davidalger Luckily, there are just 2 such cases of virtual classes. Fixed those and added the static test for any further occurrence. |
… modules #1895 - fix references - update static test
… modules #1895 - remove redundant hard dependencies
… modules #1895 - add static test to ensure that no new broken template references appears in the codebase
… modules #1895 - fix static test
… modules #1895 - Corrected templates referencing the module of the Virtual type versus the module of the base - Add static test for the Blocks virtual types
[EngCom] Fix relative template references in individual Magento modules #1895
@vrann w00t!! And thanks for adding the static test too! :) |
@davidalger great PR, excited about it too :) |
While you are here, mind fixing relative paths in require statements?! I had one quote.js bite me recently due to the code using '../model/quote' - had to change them all to full absolute paths, seems to be all over the code base - but it would be nice to have no more relative paths that can cause error when upgrading from 2.1.2 to 2.1.7 quote.min.js missing! |
…-engcom/develop-prs-isolated [EngCom] Fix relative template references in individual Magento modules magento#1895 (cherry picked from commit a434162)
Relative template references work up until 3rd party code attempts to use a DI to change a block type via a preference, thus changing the base for the relative template reference from the original module to their own.
This replacement done globally via following regex on any *.xml files in
app/code/Magento
:match:
<block class="Magento\\([^\\"]+)\\(.*)template="([^:"]+)"
replace:
<block class="Magento\\$1\\$2template="Magento_$1::$3"