SVG logo is missing width and height

Created on 22 September 2023, over 1 year ago
Updated 26 April 2024, 8 months ago

Problem/Motivation

In #3218479: Site logo image is missing width and height we added logo width and height support for regular image. But often our logo is SVG image and that code will not work for SVG logo image case.

Let's try to cover this case. For sure SVG image is without dimension, it is a vector. But we can try to extract width and height dimensions from either width and height SVG attributes or viewBox attribute.

Feature request
Status

Fixed

Version

1.0

Component

BS Bootstrap

Created by

🇷🇸Serbia pivica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @pivica
  • Status changed to Needs review over 1 year ago
  • 🇷🇸Serbia pivica

    Here is a patch. Note that for this patch to work you first need a patch from 🐛 Logo accessibility problems Needs review , I guess it is a time for a new release ;)

    This also needs a patch from Add service for extraction dimensions from SVG image Active .

  • Status changed to Needs work about 1 year ago
  • 🇨🇭Switzerland berdir Switzerland
    1. +++ b/themes/bs_bootstrap/bs_bootstrap.theme
      @@ -382,9 +381,25 @@ function bs_bootstrap_preprocess_block(&$variables) {
      +          if (file_exists(DRUPAL_ROOT . $variables['site_logo'])) {
      +            $svg_content = file_get_contents(DRUPAL_ROOT . $variables['site_logo']);
      

      this assumes that the logo is svg, should we check the file extension?

    2. +++ b/themes/bs_bootstrap/bs_bootstrap.theme
      @@ -382,9 +381,25 @@ function bs_bootstrap_preprocess_block(&$variables) {
      +              /** @var \Drupal\bs_lib\SvgTools $svg_tools */
      +              $svg_tools = \Drupal::service('bs_lib.svg_tools');
      

      I think it maks sense to do a getContainer()->hasService(), because if someone for some reason didn't update the module, it's going to be very hard to recover from this.

    3. +++ b/themes/bs_bootstrap/bs_bootstrap.theme
      @@ -382,9 +381,25 @@ function bs_bootstrap_preprocess_block(&$variables) {
      +              if (isset($dimensions['width'])) {
      

      I assume we don't want to set only width or height, so we should make sure we either return both or nothing and then you can just do if ($dimensions).

  • Status changed to Needs review about 1 year ago
  • 🇷🇸Serbia pivica

    > 1. this assumes that the logo is svg, should we check the file extension?

    381: if ($logo_path_info['extension'] === 'svg') {
    

    This we are already doing here, right?

    2. and 3. should be done, needed to do a new patch for related service in bs_lib https://www.drupal.org/project/bs_lib/issues/3389133#comment-15253540 Add service for extraction dimensions from SVG image Active .

  • 🇷🇸Serbia pivica

    Removed one extra if and added rounding to int.

    • pivica committed 9af4863f on 8.x-1.x
      Issue #3389127 by pivica, Berdir: SVG logo is missing width and height
      
  • Status changed to Fixed 9 months ago
  • 🇷🇸Serbia pivica

    Committed.

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

Production build 0.71.5 2024