Commit 5002875d authored by Ivica Puljic's avatar Ivica Puljic Committed by Ivica Puljic
Browse files

Issue #3218479 by pivica, Berdir: Site logo image is missing width and height

parent 0917c59f
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -324,14 +324,34 @@ function bs_bootstrap_preprocess_block(&$variables) {
          $variables['site_logo'] = $logo_path_language;
        }

        $logo_attributes = ['class' => ['site-logo']];

        if ($logo_path_info['extension'] === 'svg') {
          // Inline SVG logo.
        if (bs_bootstrap_get_setting('logo_svg_inline') && $logo_path_info['extension'] === 'svg') {
          if (bs_bootstrap_get_setting('logo_svg_inline')) {
            $variables['site_logo_svg'] = file_get_contents(DRUPAL_ROOT . $variables['site_logo']);
          }
        }
        else {
          // Get the logo width and height.
          if (file_exists(DRUPAL_ROOT . $variables['site_logo'])) {
            /** @var \Drupal\Core\Image\Image $image */
            $image = \Drupal::service('image.factory')->get(DRUPAL_ROOT . $variables['site_logo']);
            $logo_attributes['width'] = $image->getWidth();
            $logo_attributes['height'] = $image->getHeight();
          }

          $config = \Drupal::config('system.site');
      $variables['site_logo_alt_text'] = t('@site_name logo', ['@site_name' => Xss::filter($config->get('name'))]);
          $logo_attributes['alt'] = t('@site_name logo', ['@site_name' => Xss::filter($config->get('name'))]);
          // Keep the old site_logo_alt_text for compatibility with older
          // custom themes that are using site_logo_alt_text.
          // @TODO - remove for 2.x version.
          $variables['site_logo_alt_text'] = $logo_attributes['alt'];
        }

        $variables['logo_attributes'] = new Attribute($logo_attributes);
      }

      break;
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
      {%- if site_logo_svg -%}
        {{- site_logo_svg|raw -}}
      {%- else -%}
        <img src="{{ site_logo }}" alt="{{ site_logo_alt_text }}" class="site-logo"/>
        <img src="{{ site_logo }}" {{ logo_attributes }} />
      {%- endif -%}
    </a>
  {%- endif %}