Skip to content
Snippets Groups Projects
Commit a3b9036b authored by Nicholas Mangold's avatar Nicholas Mangold
Browse files

Move extension logic to the block plugin, and allow templates to render the logo the same way.

parent d8a5b282
No related branches found
No related tags found
1 merge request!11538Inline logo SVG.
......@@ -167,20 +167,29 @@ public function build() {
if ($logo_uri !== NULL) {
$extension = pathinfo($logo_uri, PATHINFO_EXTENSION);
}
$build['site_logo'] = [
'#theme' => 'image',
'#uri' => $logo_uri,
'#alt' => $this->t('Home'),
'#attributes' => ['loading' => 'eager', 'fetchpriority' => 'high'],
'#access' => $this->configuration['use_site_logo'],
];
// Add width and height attributes. SVGs are printed inline in the template.
if (isset($extension) && $extension !== 'svg') {
$image = $this->imageFactory->get(ltrim($logo_uri, '/'));
if ($image->isValid()) {
$build['site_logo']['#attributes']['width'] = $image->getWidth();
$build['site_logo']['#attributes']['height'] = $image->getHeight();
if (isset($extension)) {
$logo_uri = ltrim($logo_uri, '/');
$build['site_logo'] = [
'#access' => $this->configuration['use_site_logo'],
];
// SVG uses an inline template. Otherwise, use the image factory.
if ($extension === 'svg') {
$build['site_logo']['#type'] = 'inline_template';
$build['site_logo']['#template'] = file_get_contents($logo_uri);
}
else {
$image = $this->imageFactory->get($logo_uri);
if ($image->isValid()) {
$build['site_logo']['#theme'] = 'image';
$build['site_logo']['#uri'] = $logo_uri;
$build['site_logo']['#alt'] = $this->t('Home');
$build['site_logo']['#attributes'] = ['loading' => 'eager',
'fetchpriority' => 'high',
'width' => $image->getWidth(),
'height' => $image->getHeight(),
];
}
}
}
......
......@@ -313,9 +313,8 @@ function system_preprocess_block(&$variables): void {
switch ($variables['base_plugin_id']) {
case 'system_branding_block':
$variables['site_logo'] = '';
if ($variables['content']['site_logo']['#access'] && $variables['content']['site_logo']['#uri']) {
$variables['site_logo'] = $variables['content']['site_logo']['#uri'];
$variables['site_logo_rendered'] = $variables['content']['site_logo'];
if ($variables['content']['site_logo']['#access']) {
$variables['site_logo'] = $variables['content']['site_logo'];
}
$variables['site_name'] = '';
if ($variables['content']['site_name']['#access'] && $variables['content']['site_name']['#markup']) {
......
......@@ -19,11 +19,7 @@
{% block content %}
{% if site_logo %}
<a href="{{ path('<front>') }}" rel="home">
{% if site_logo|split('.')|last == "svg" %}
{% include site_logo %}
{% else %}
{{ site_logo_rendered }}
{% endif %}
{{ site_logo }}
</a>
{% endif %}
{% if site_name %}
......
......@@ -19,11 +19,7 @@
<div class="site-branding__inner">
{% if site_logo %}
<a href="{{ path('<front>') }}" rel="home" class="site-branding__logo">
{% if site_logo|split('.')|last == "svg" %}
{% include site_logo %}
{% else %}
{{ site_logo_rendered }}
{% endif %}
{{ site_logo }}
</a>
{% endif %}
{% if site_name %}
......
......@@ -17,11 +17,7 @@
{% block content %}
{% if site_logo %}
<a href="{{ path('<front>') }}" rel="home" class="site-logo">
{% if site_logo|split('.')|last == "svg" %}
{% include site_logo %}
{% else %}
{{ site_logo_rendered }}
{% endif %}
{{ site_logo }}
</a>
{% endif %}
{% if site_name %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment