You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Magento 2 famework forces image properties to be managed by themes.
Why it is a violation of the Separation of Concerns principles
Image properties are declared in etc/view.xml, a file that is expected by Magento 2 framework to be provided by themes. This is documented in Configure theme properties.
This is a violation because image properties depend on image types, and image types are product attributes created either by modules or from the back-office. It makes the themes dependent on data that they are not managing themselves and can't be declared as dependencies.
Illustration of the violation
Consider the following etc/view.xml file, taken from the above documentation:
<imagesmodule="Magento_Catalog">
<imageid="unique_image_id"type="image">
<width>100</width> <!-- Image width in px -->
<height>100</height> <!-- Image height in px -->
</image>
</images>
Here, a theme declares an image identifier named unique_image_id as a resized variant of the imageimage type. This imageimage type may or may not exist: if one of the installed module did create that image product attribute, or if that product attribute was created in the back-office, then unique_image_id is a perfectly valid image identifier; if no module did create the image product attribute and it was not created either from the back-office, then unique_image_id is not valid and trying to use it to create an image variant would lead to a crash.
It is impossible when writing a theme to know if a product attribute exists - and thus it is impossible to know if an image identifier declared in a theme will function or not.
In other words, having image identifiers managed by themes makes the behavior of the final product unpredictable.
Workarounds
It may be possible to declare image properties programmatically at modules level. This needs to be checked. If not, there is no workaround for this issue.
Proposed solution
Override Magento 2 configuration resolvers to have image properties declared by modules instead of themes.
Remove support for etc/view.xml by themes configuration resolvers.
The text was updated successfully, but these errors were encountered:
Violation
Magento 2 famework forces image properties to be managed by themes.
Why it is a violation of the Separation of Concerns principles
Image properties are declared in
etc/view.xml
, a file that is expected by Magento 2 framework to be provided by themes. This is documented in Configure theme properties.This is a violation because image properties depend on image types, and image types are product attributes created either by modules or from the back-office. It makes the themes dependent on data that they are not managing themselves and can't be declared as dependencies.
Illustration of the violation
Consider the following
etc/view.xml
file, taken from the above documentation:Here, a theme declares an image identifier named
unique_image_id
as a resized variant of theimage
image type. Thisimage
image type may or may not exist: if one of the installed module did create thatimage
product attribute, or if that product attribute was created in the back-office, thenunique_image_id
is a perfectly valid image identifier; if no module did create theimage
product attribute and it was not created either from the back-office, thenunique_image_id
is not valid and trying to use it to create an image variant would lead to a crash.It is impossible when writing a theme to know if a product attribute exists - and thus it is impossible to know if an image identifier declared in a theme will function or not.
In other words, having image identifiers managed by themes makes the behavior of the final product unpredictable.
Workarounds
It may be possible to declare image properties programmatically at modules level. This needs to be checked. If not, there is no workaround for this issue.
Proposed solution
etc/view.xml
by themes configuration resolvers.The text was updated successfully, but these errors were encountered: