Problem/Motivation
It will be good to have a desktop/mobile switcher available in the navigation top bar provided by Drupal Core.
Proposed resolution
Drupal core has introduced the Navigation module, which includes a top bar feature. This top bar enables other modules to define items using the @TopBarItem plugin. As part of this issue, a top bar tool will be created to preview the desktop and mobile versions of the current page.
Remaining tasks
This implementation will depend on https://www.drupal.org/project/drupal/issues/3484564
User interface changes
The new top bar tool will look like following 
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | Screen Recording 2024-12-23 at 5.23.56 PM.mov | 4.16 MB | anjali rathod |
| Screenshot 2024-11-22 at 12.17.04 PM.png | 80.42 KB | kunalkursija |
Issue fork responsive_preview-3489112
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
kunalkursija commentedComment #3
anjali rathodComment #4
anjali rathodI am facing issue setting up the responsive preview module. Attaching the screen recording video for reference.
Comment #5
roshni upadhyay commentedI encountered an issue while working with the responsive_preview module. The error was as follows:
Error: Call to undefined function drupal_common_theme() in responsive_preview_theme() (line 40 of modules/contrib/responsive_preview/responsive_preview.module)I resolved it by modifying the code in the responsive_preview_theme() function. Could you please confirm whether this should be addressed as a separate issue, or can we include the fix under the scope of the current issue?
Additionally, I need clarification regarding the default dimensions for the device icons. What dimensions should we use for both devices? Please provide the recommended width and height values to standardize the implementation.
Comment #6
roshni upadhyay commentedI would like to clarify that I am still facing the issue. In my previous comment, I mentioned that it was working, but that was due to a version mismatch. The issue persists as follows:
Comment #7
roshni upadhyay commentedThe Responsive Preview block was not functioning as expected due to the missing #block-responsivepreviewcontrols ID when the block was placed. After adding the required ID, the block started working as intended. With this issue resolved, I am now unblocked and able to continue working on it.
Comment #9
roshni upadhyay commentedComment #10
plopesc@roshni upadhyay Thank you for your work on this one.
After reading the code, I have some ideas to make it a bit more generic:
* We could create the navigation top bar as a submodule, or even a new contrib module that depends on this one and navigation. Let's work on a MR for this one for now.
* Add a 3rd party setting to the config entity as part of this submodule to "Show in Top Bar" the responsive_preview entity
* Instead of hardcoding the types in
ResponsiveIconsclass, load the items whose 3rd party setting is defined to be shown in the top bar* Think in a way of how to display those options different from "mobile" & "desktop". That could be part of a follow-up issue
Comment #11
plopescAnother approach could be to make it fully hardcoded, and do not make use of the config entities, and use the original module as an API to provide the logic to switch between devices, but not crating new entities, nor using them.
This 2nd approach could be simpler to implement at this point, but we will probably want something more generic in the long term.
Comment #12
lauriiiDiscussed with @plopesc and @roshni upadhyay to align on the approach. We agreed that we will continue with the approach proposed in #11. What we will do is:
Deviceconfig entity but we will hard code those values in theDrupal\navigation\TopBarItemBaseimplementation which will allow us to provide a good experience consistentlyComment #13
roshni upadhyay commentedComment #14
plopescChanges look great and goes in the right direction.
Added some comments in the MR that might need to be addressed.
Comment #15
roshni upadhyay commentedComment #16
plopescMade a couple of minor adjustments, but overall, I think this is ready for final review.
Comment #17
lauriiiThis looks pretty good based on the functionality and code has been reviewed by @plopesc.
I think an important follow-up to this would be to render the responsive preview as an anonymous user. That might lead into some complications so it's better to leave that to another issue.
Comment #18
plopescCreated follow-up #3501374: Preview displays include Navigation Toolbars
Comment #20
rajeshreeputraRebased, will merge this and wait for the follow-up #3501374: Preview displays include Navigation Toolbars.
Comment #22
rajeshreeputraMerged! will wait for the follow-up #3501374: Preview displays include Navigation Toolbars.
Comment #24
rajab natshahThank you for this integration, hoping that it could be released
1- The following issue was committed and released in Drupal Core.
#3484564: Define the 3 areas the Top Bar will provide
2- Not listing all devices. (Should we do that? )
3- Have an option to show the dropdown. (Should we do that?)
4- A new project could have better management ( not sure if this could end up in Drupal Core or Drupal CMS )
Comment #25
rajab natshahOne more question:
Should the
getResponsivePreviewItemsmethod be filled with the dynamic configs and use the Icon API?Comment #26
rajab natshahMoving to adopt the committed method, and enable the new sub module.
Answering my own questions after an internal meeting with my teams:
Hoping for a tag release
Comment #27
rajeshreeputraReleased 2.3.0!