Skip to content
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

Image properties are managed by themes #1

Open
ericmorand opened this issue Oct 5, 2020 · 0 comments
Open

Image properties are managed by themes #1

ericmorand opened this issue Oct 5, 2020 · 0 comments

Comments

@ericmorand
Copy link
Member

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:

<images module="Magento_Catalog">
    <image id="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 image image type. This image image 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.
@ericmorand ericmorand changed the title Image properties should be managed by module Image properties should be managed by modules Oct 5, 2020
@ericmorand ericmorand changed the title Image properties should be managed by modules Image properties are managed by themes Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant