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

  1. Look for a way to define breakpoints independently of the theme
  2. Look for a way to set breakpoint sizes in the theme
  3. Rename breakpoints in our modules to the neutral names
  4. Test

User interface changes

API changes

Data model changes

Command icon 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

Anybody created an issue. See original summary.

anybody’s picture

Title: Define breakpoints neutrally outside the theme - leads to unwanted drowl_base dependency » Define breakpoin names neutrally outside the theme - leads to unwanted drowl_base dependency
Priority: Normal » Minor
Issue summary: View changes
anybody’s picture

Project: DROWL Paragraphs » DROWL Media
Version: 4.x-dev » 3.0.27

Moved to drowl_media as drowl_media_types contains the DIRECT references:

grep -r "drowl_base.small" *;
drowl_media/modules/drowl_media_types/config/optional/responsive_image.styles.viewport_width.yml:    breakpoint_id: drowl_base.small
drowl_media/modules/drowl_media_types/config/optional/responsive_image.styles.page_width_25.yml:    breakpoint_id: drowl_base.small
drowl_media/modules/drowl_media_types/config/optional/responsive_image.styles.page_width_scale.yml:    breakpoint_id: drowl_base.small
drowl_media/modules/drowl_media_types/config/optional/responsive_image.styles.page_width_50.yml:    breakpoint_id: drowl_base.small
drowl_media/modules/drowl_media_types/config/optional/responsive_image.styles.page_width_25_scale.yml:    breakpoint_id: drowl_base.small
drowl_media/modules/drowl_media_types/config/optional/responsive_image.styles.viewport_width_scale.yml:    breakpoint_id: drowl_base.small
drowl_media/modules/drowl_media_types/config/optional/responsive_image.styles.page_width.yml:    breakpoint_id: drowl_base.small
drowl_media/modules/drowl_media_types/config/optional/responsive_image.styles.page_width_50_scale.yml:    breakpoint_id: drowl_base.small

While drowl_paragraphs requires drowl_media (like drowl_header_images also) and this way has an indirect dependency on drowl_base theme.

thomas.frobieter’s picture

Breakpoint names should be as general and neutral as possible, so for example

small
medium
large
xlarge
xxlarge

Without the theme name prefix.

I 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?

anybody’s picture

Title: Define breakpoin names neutrally outside the theme - leads to unwanted drowl_base dependency » Define breakpoint names neutrally outside the theme - leads to unwanted drowl_base dependency
anybody’s picture

Version: 3.0.27 » 3.x-dev

Indeed 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.

anybody’s picture

Priority: Minor » Normal

This 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:

  • If drowl_base is not present, the responsive image styles will NOT be installed
  • drowl_base becomes an indirect / optional dependency

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:

  • Anybody committed e98ecae on 3.x
    Issue #3260767: Define breakpoint names neutrally outside the theme -...
thomas.frobieter’s picture

I 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? ;)

anybody’s picture

Perhaps yes, perhaps not... we'll have to look at this with more time and test carefully.

1.

The Docs for breakpoints mentions Themes AND modules

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.

Specifying a group is optional, if you don't specify a group, the group will be named the same as your theme or module.

I think this is what the UI does, but we have three references in the responsive image style config:

langcode: en
status: true
dependencies:
  config:
    - image.style.page_width_25_lg
  theme:
    - drowl_base
id: page_width_25
label: '25% Page width, cropped'
image_style_mappings:
  -
    image_mapping_type: image_style
    image_mapping: page_width_25_lg
    breakpoint_id: drowl_base.small
    multiplier: 1x
breakpoint_group: drowl_base

A)

  theme:
    - drowl_base

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_base
I 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.small

And 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.

anybody’s picture

Category: Feature request » Bug report

Switching to bug report as of the last comments.

thomas.frobieter’s picture

So, YES, it is possible to have a drowl_media.breakpoints.yml (ready to use):

drowl_media.small:
  label: Small
  mediaQuery: 'all and (max-width: 640px)'
  weight: 0
  multipliers:
    - 1x
drowl_media.medium:
  label: Medium
  mediaQuery: 'all and (min-width: 641px) and (max-width: 1024px)'
  weight: 1
  multipliers:
    - 1x
drowl_media.large:
  label: Large
  mediaQuery: 'all and (min-width: 1025px) and (max-width: 1366px)'
  weight: 2
  multipliers:
    - 1x
drowl_media.xlarge:
  label: X-Large
  mediaQuery: 'all and (min-width: 1367px) and (max-width: 1920px)'
  weight: 3
  multipliers:
    - 1x
drowl_media.xxlarge:
  label: XX-Large
  mediaQuery: 'all and (min-width: 1921px)'
  weight: 4
  multipliers:
    - 1x

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_paragraphs I 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

anybody’s picture

Created 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?

anybody’s picture

Status: Active » Reviewed & tested by the community

Just ran into this again. Let's get this committed. We also had to align the import configurations accordingly.

anybody’s picture

  • Anybody committed ed403eb on 3.x
    Issue #3260767 by Anybody, thomas.frobieter: Define breakpoint names...
anybody’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.