Skip to content

Add ability to build responsive image styles in style guide#982

Open
dipakmdhrm wants to merge 5 commits intomainfrom
981-style-guide-responsive-images
Open

Add ability to build responsive image styles in style guide#982
dipakmdhrm wants to merge 5 commits intomainfrom
981-style-guide-responsive-images

Conversation

@dipakmdhrm
Copy link
Copy Markdown
Collaborator

#981

Update:

  • Add ability to build responsive image styles in style guide
    • Use breakpoints from server_theme
Mobile Tablet Desktop
1 2 3

@dipakmdhrm dipakmdhrm force-pushed the 981-style-guide-responsive-images branch from 44e1ce5 to 08472dc Compare January 30, 2026 11:53
@dipakmdhrm dipakmdhrm force-pushed the 981-style-guide-responsive-images branch from 08472dc to 8dba918 Compare January 30, 2026 11:56
* @return array
* A render array for a <picture> element.
*/
private function buildResponsiveImage(array $image_dimensions, string $id = '', string $id_type = 'id', string $alt = ''): array {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • string should normally be replaced with an enum
  • Can we call an actual responsive image, like used in the Themetrits / PEVB, instead of building one ourselves?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string should normally be replaced with an enum

I've created enum for $id_type. $id and $alt can have any value, so keeping those as string.

  • Can we call an actual responsive image, like used in the Themetrits / PEVB, instead of building one ourselves?

@amitaibu PEVB uses drupal media/image entity to build responsive images. But shouldn't we avoid Drupal entities in StyleGuideController (to avoid any database dependency and just using placeholder data)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming there's a low level method that recieves a file, and creates the image style from it. Can you check that please

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amitaibu To create a responsive image we use:

[
      '#theme' => 'responsive_image',
      '#uri' => $file_uri,
]

The file uri needs to be from a file stream in Drupal's local filesystem i.e. either public:// or private://.

A file in modules is in neither such stream. We'll need to temporarily copy file directly to public:// to build it's image styles, which will copy a new file on every /style-guide page request (or we'll need to hardcode a filename for public://)

We do have an alternative. We can create a custom stream wrapper for style guide module server_style_guide:// which can process files from web/modules/custom/server_style_guide/images/ to create responsive image styles.
I'd recommend this option as we have responsive images in most of our components and currently style guide displays static images for all of them.

@dipakmdhrm dipakmdhrm force-pushed the 981-style-guide-responsive-images branch from 2458c7a to 9499e8e Compare March 10, 2026 14:36
dipakmdhrm and others added 2 commits March 11, 2026 15:06
Replaces the html_tag-based <picture> implementation with Drupal's
responsive_image theme. Adds a StyleGuideStream (server-style-guide://)
read-only stream wrapper pointing to the module's images/ directory,
allowing image styles to process module-bundled files without copying
them to public://.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dipakmdhrm
Copy link
Copy Markdown
Collaborator Author

Update:

  • Add a new server-style-guide:// stream wrapper.
  • Use '#theme' => 'responsive_image' to render responsive images in style guide.

@dipakmdhrm dipakmdhrm requested a review from amitaibu March 13, 2026 10:11
edutrul added a commit to edutrul/drupal-starter that referenced this pull request Mar 26, 2026
Add accordion paragraph with three FAQ items covering DDEV setup,
PEVB pattern explanation, and running automated tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants