Problem/Motivation
Breakpoints are referenced in several modules / configurations, for example to define image styles needed for drowl_paragraphs.
They are currently defined in drowl_base theme in drowl_base.breakpoints.yml:
drowl_base.small:
label: Small
mediaQuery: 'all and (max-width: 640px)'
weight: 0
multipliers:
- 1x
group: drowl_base
extras:
minWidth: 0
drowl_base.medium:
label: Medium
mediaQuery: 'all and (min-width: 641px) and (max-width: 1024px)'
weight: 1
multipliers:
- 1x
group: drowl_base
extras:
minWidth: 641
drowl_base.large:
label: Large
mediaQuery: 'all and (min-width: 1025px) and (max-width: 1366px)'
minWidth: 1025
weight: 2
multipliers:
- 1x
group: drowl_base
extras:
minWidth: 1025
drowl_base.xlarge:
label: X-Large
mediaQuery: 'all and (min-width: 1367px) and (max-width: 1920px)'
minWidth: 1367
weight: 3
multipliers:
- 1x
group: drowl_base
extras:
minWidth: 1367
drowl_base.xxlarge:
label: XX-Large
mediaQuery: 'all and (min-width: 1921px)'
minWidth: 1921
weight: 4
multipliers:
- 1x
group: drowl_base
extras:
minWidth: 1921
This name is then referenced in config like:
responsive_image.styles.page_width_25_scale.yml: breakpoint_id: drowl_base.small
The issue appears for all modules that directly or indirectly reference breakpoint _id's in code or config link responsive image styles, responsive background image, ...
Example:
Notice: Undefined index: drowl_base.small in Drupal\responsive_background_image\ResponsiveBackgroundImage::generateMediaQueries() (line 127 of modules/contrib/responsive_background_image/src/ResponsiveBackgroundImage.php).
Steps to reproduce
Install drowl_paragraphs outside the typical DROWL environments, for example on simplytest.me and see things crashing
Proposed resolution
Breakpoint names should be as general and neutral as possible, so for example
- small
- medium
- large
- xlarge
- xxlarge
Without the theme name prefix.
The theme is the right point to define their sizes, but perhaps not to define their name (interface vs. implementation) Defining the names neutrally outside the theme would allow to reference the ID in all modules, but leave the sizing to the theme.
I'm not sure yet, how to solve this best practice, I'm not even sure if Drupal requires the theme name to be put in front of the breakpoint_id and didn't see this logical problem yet...
Some ideas:
- Look how other modules and themes solve this, for example by using a neutral naming which can then perhaps be overridden / implemented by the theme??
- Or define the breakpoints in a common module like drowl_layouts or drowl_xxx which can be a lightweight dependency?
- ...
In the end we should be able to reference the breakpoint ids without having to add the drowl_base theme as dependency to alle the modules which indirectly use breakpoints.
Remaining tasks
- Look for a way to define breakpoints independently of the theme
- Look for a way to set breakpoint sizes in the theme
- Rename breakpoints in our modules to the neutral names
- Test
User interface changes
API changes
Data model changes
Issue fork drowl_media-3260767
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybodyComment #3
anybodyMoved to drowl_media as drowl_media_types contains the DIRECT references:
While drowl_paragraphs requires drowl_media (like drowl_header_images also) and this way has an indirect dependency on drowl_base theme.
Comment #4
thomas.frobieterI think breakpoint.yml's always have a namespace prefixed, see:
https://www.drupal.org/docs/theming-drupal/working-with-breakpoints-in-d...
IMO modules need a setting for this, to match breakpoints given by the theme.
Aren't the responsive image styles (& the imagecaches used by them) also a problematic thing here?
Comment #5
anybodyComment #6
anybodyIndeed I'm unsure if there's anything we can do about this problem. Let's keep this open as reminder, if someone has a good idea, but it's definitely minor.
Comment #7
anybodyThis looked like a minor problem, but not defining the theme, which provides the breakpoints, broke configuration import!
So as a quickfix I moved all the responsive image styles into config/optional and added drowl_base as dependency. This has some consequences:
In consequence this also means that none of the configs depending on these responsive image styles will be imported / working!
Whenever drowl_base is present (which is the case for our NEW sites) or existing installations where we already added the responsive image styles manually, this is no problem. Anyway, we can't just leave it as it is forever.
Best would still be to define the breakpoints outside of the theme (better in this module), but I think this isn't allowed by Drupal Core currently? Or is it? We should check that with more time...
=> No concrete consequences for us currently, but this part is definitely polluted by "drowl_base" and should be resolved some day!
Here's the related commit:
Comment #9
thomas.frobieterI would consider the following behavior for new fresh installations of the module:
- No matter what theme is used, the module should provide defaults for the required breakpoints. The Docs for breakpoints mentions Themes AND modules => https://www.drupal.org/docs/theming-drupal/working-with-breakpoints-in-d...
"Specifying a group is optional, if you don't specify a group, the group will be named the same as your theme or module." so it should work by simply adding a drowl_media.breakpoints.yml? I will try this..
- On the modules setting page, we need to have a select with all available breakpoint-groups, like we have it already in drowl_paragraphs
Badaboom, problem solved? ;)
Comment #10
anybodyPerhaps yes, perhaps not... we'll have to look at this with more time and test carefully.
1.
If it's possible to define the breakpoints in a module, we should consider doing that, instead of the theme. In drowl_media or a separate.
Then this would be decoupled, and everything is fine and usable without referencing a theme.
2.
I think this is what the UI does, but we have three references in the responsive image style config:
A)
tells drupal about the dependencies. If there wouldn't be any, we could remove them (that was the case before, lead to breaking config - which is correct behaviour of drupal. The dependency should be defined explicitly, if it exists
B)
breakpoint_group: drowl_baseI guess that is what the text refers to. PERHAPS it can even be left empty or be ANY string in the config as it's just for structuring the UI and has no technical implications.
C)
I guess the real inner dependency is:
breakpoint_id: drowl_base.smallAnd if I remember correctly, I already invested some time, the last time I worked on this issue and found out that this was the logical problem...
Conclusion and further steps:
For me, this topic is too large and dangerous to proceed here for now or trying a simple fix without extensive testing. This is supposed to break a lot of things if rolled out.
Next step would be to decide where to put the breakpoints (separate module or drowl_media), set up a proof of concept and document the required migration / update steps. But this has to be 100% bulletproof.
Comment #11
anybodySwitching to bug report as of the last comments.
Comment #12
thomas.frobieterSo, YES, it is possible to have a drowl_media.breakpoints.yml (ready to use):
So, we need to (probably the same on drowl_paragraphs?):
- Add the drowl_media.breakpoints.yml shown above
-
Add the breakpoint-match setting from drowl_paragraphsI think we don't need a matching here. The matching needs to be done in /admin/config/media/responsive-image-style. We just need to ensure that the responsive image styles, drowl_media relies on, are exists?!- Replace drowl_base breakpoints with drowl_media breakpoints in the configuration files
Comment #14
anybodyCreated a first MR from #12
Still TDB:
- Read all comments above and ensure we considered everything
- Replace drowl_base breakpoints with drowl_media breakpoints in the configuration files
- Match with our theme? / VL?
Comment #15
anybodyJust ran into this again. Let's get this committed. We also had to align the import configurations accordingly.
Comment #16
anybodyComment #18
anybody