Problem/Motivation
The logo in olivero is hard-coded. All logos in core are either hard-coded or we _only_ render the image path. Never dimensions. We should. And we might want a holistic solution that passes from theme config the logo and the logo dimensions. For good measure, we could even add loading="eager". That's the default, but adding it is more explicit and instructive.
Steps to reproduce
Inspect the HTML source for the logo, and see the width and height attributes are not included.
Proposed resolution
Use the image factory to render the img tag including the width and height attributes.
Remaining tasks
None
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | 3345259-for-d11.2.x-40.patch | 8.55 KB | flyke |
| #36 | drupal-site-logo_after-dump.png | 352.79 KB | tirupati_singh |
| #36 | drupal-site-logo_after-svg.png | 324.75 KB | tirupati_singh |
| #36 | drupal-site-logo_after.png | 271.32 KB | tirupati_singh |
| #36 | drupal-site-logo-svg_before.png | 258.16 KB | tirupati_singh |
Issue fork drupal-3345259
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
heddnComment #4
catchI wonder if this was an unexpected regression from #908282: Remove unnecessary I/O from theme_image() (although that issue was good in general).
The main issue with this is that we don't have anywhere obvious to store the dimensions, the theme settings just point to a file on disk, there's no file reference or similar.
We could do what #908282: Remove unnecessary I/O from theme_image() used to do in preprocess and cache it somewhere maybe? It's a bit hacky, but it's minimal and would help page rendering quite a lot.
Or we could add dimensions to the theme configuration form/config object and prepopulate them from the file info if not explicitly set? This would have the advantage of not needing an extra cache get but you could end up with weird issues if you change your theme logo file without updating the form.
Comment #5
longwaveCould we render the logo alone in its own template, preprocessing the height/width, and leverage the render cache?
Storing it in config feels like the wrong solution given it is not configuration and we can't guarantee it will be updated correctly.
Comment #6
catchI couldn't remember where the logo is rendered, but it's in SystemBrandingBlock - we could do it directly in there I think, just add the attributes when building the render array. It might even be OK to rely on render caching for of the block, although would need to check that.
Comment #7
catchComment #8
catchMade a start on this but it's quite painful.
The pain is mostly because of
system_preprocess_blockandIn
SystemBrandingBlockwe do things 'properly' and use '#theme' => 'image', but then that preprocess and the template just extracts the URI from the image render array and renders the image with hard-coded HTML. Why?This means any added attributes get stripped.
Promoting to a bug because there's no way at all to do this generically at the moment.
I got around this in stark by adding an extra variable for the rendered image, then using that in the template, it is really ugly but I can't think of any other way except adding an entirely new block and deprecating the old one.
Comment #10
catchDeprecated the 'site_logo' variable, adding a change record and a release note, this ought to be reviewable now.
Comment #11
catchThat svg logic isn't happy, removed that and also switched to using the image factory for non-svg images.
Comment #12
quietone commentedTrying to remove the 'See more' from the snippet
Comment #13
longwaveThis won't make it into 10.3.
Comment #16
nmangold commentedThe current MR, https://git.drupalcode.org/project/drupal/-/merge_requests/7241, dumps "boo" to the page. Consequently, the height and width attributes are not added to the image. This is because SVG is not a supported type in GDToolkit. The image factory method
$image->isValid()returns false. I assume that is why the URI is extracted and used in the hard-coded<img>tag instead of the render array.I created a new MR, https://git.drupalcode.org/project/drupal/-/merge_requests/11538, that proposes checking the extension and printing the SVG inline, which includes the height and width attributes.
Comment #17
smustgrave commentedSo currently there are now 2 MRs, 1 should be hidden or closed
Also issue summary appears to be complete.
Will probably need test coverage
Comment #18
nmangold commentedAdded a screenshot of the logo as an inline SVG.
Comment #20
nmangold commentedNow that I better understand this, I added code similar to the previous, hidden branch. The default logo in the themes is now an SVG. However, a non-SVG image could be configured or uploaded using the theme settings. Some of the tests also use the old Druplicon logo.
For SVGs, we cannot render the image using the image factory, because GDToolkit does not support SVGs. So, we need both solutions, one for images supported by GDTookit and one for images not supported (SVGs).
I changed the release notes for deprecating the
site_logoand described the additionalsite_logo_renderedfor rendering the<img>tag with attributes.Also, I added tests covering both situations.
Comment #21
catchOne question on the MR.
Comment #22
nmangold commentedAdded a screenshot of the logo as a PNG, which renders the
<img>tag with attributes including dimensions.Comment #23
nmangold commentedComment #24
nmangold commentedComment #25
nmangold commentedI removed the release notes. The new variable is no longer used. The extension logic was moved to the block plugin which allows the templates to simply print the
site_logovariable.Comment #26
nmangold commentedI believe everything is done, and this is ready for review again.
Comment #27
smustgrave commentedThis seems like it's going to be immediate breaking change for many sites using their own branding-block twig..
Comment #28
nmangold commented@smustgrave You are correct. The
site_logovariable now renders the entire<img>or<svg>element. Not just the URI. I suppose that should be in the release notes.Comment #29
smustgrave commentedI think this needs some kind of backwards compatibility change. Definitely can't release in patched release or even minor release. So as is I don't think it should be included till Drupal 12
Comment #30
nmangold commentedThat might be best. Unless someone can suggest a backwards compatibility change.
I changed the release notes to reflect the change as of now.
Comment #31
smustgrave commentedPosted in #core-development to hopefully get some attention.
Comment #32
nmangold commentedComment #33
nmangold commentedImproved the release notes.
Comment #34
catchWe can change templates in minor releases with a change record and release note, see https://www.drupal.org/about/core/policies/core-change-policies/frontend...
Comment #35
nmangold commented@catch Can you review the MR, please?
Comment #36
tirupati_singh commentedHi all, I was able to reproduce the issue by following the outlined steps, and I observed that the site branding logo was being rendered without its height, width, and loading attributes. I’ve applied the provided MR !1158 as a patch, and it applied cleanly. After applying the patch, the site branding logo is now rendered with height, width, and loading attributes for PNG, JPG, and SVG files, which was previously missing. Previously, only the src and alt attributes were rendered for the logo. The MR changes are working fine, and I’ve attached screenshots showing the issue before and after the fix for reference.
Additionally, with the new MR changes, $site_logo now returns an array containing the image elements with their properties instead of just the URI. This change may potentially cause layout issues for themes that use their own branding logo system or preprocess the branding block template.
Although the MR changes are working well with D11, I’m keeping the issue in "Needs work" state since the pipeline is failing and to consider backward compatibility.
Comment #37
flyke commentedI can confirm that MR11538 applies to D11.2.2
I have a custom subtheme of the bootstrap5 theme, so I had to overwrite
themes/contrib/bootstrap5/templates/block/block--system-branding-block.html.twigin my custom theme. In there I replaced:with:
At all works fine.
Comment #39
flyke commentedIt seems that MR11538 no longer applies to D11.2.2 since the changes in #38.
I digged a little further and you seem to have
core/modules/system/src/Hook/SystemThemeHooks.phpwhich I dont see in my project.Even more, I do not see this file in the D11.2.x repository:
https://git.drupalcode.org/project/drupal/-/tree/11.2.x/core/modules/sys...
BUT it is in the D11.x repository:
https://git.drupalcode.org/project/drupal/-/tree/11.x/core/modules/syste...
I checked the version this patch is against and you are correct and I am wrong. It should not apply to D11.2.2, it looks like it should apply to D11.x which unfortunatly my project dont have. I believe that the MR modification in SystemThemeHooks.php was added after #37, which is why I was able to apply the MR to D11.2.2 at the time of #37 but now I cant anymore
Comment #40
flyke commentedI cut the SystemThemeHooks.php out of the MR to have a patch that applies to D11.2.2