Problem/Motivation
The file src/components/navbar/navbar-brand.twig
contains a macro to define the image used inside that component, and later on for example in the file templates/block/block--system-branding-block.html.twig
, when we call it with the parameters, if for whatever reason we dont want to use the `path` parameter and it is ommited, the parameters into the macro are wrong and the width takes the value of the alt parameter.
A second error is also flagged while validating the html in both cases with the W3C validator:
If we dont have a assigned value to the height parameter and analyse the code, we get the following error:
Bad value auto for attribute height on element img: Expected a digit but saw a instead.
Steps to reproduce
- Make sure we have a logo in our site
- Create a subtheme and copy the templates/block/block--system-branding-block.html.twig file into ours (so we dont alter the radix one)
- remove the path in the copied file, or make it empty
- CR, and you will see the results: in the html, the width tag contains the alt value, and alt is empty (and in my case the sixe of the logo goes crazy)
Proposed resolution
Pass the missing parameters also in the else, (or at least a null value), like here:
{% else %}
<span class="navbar-brand h1 mb-0 {{ utility_classes }}" aria-label="{{ text }}">
{% if image %}
{{ navbar_brand.image(image, width, height, alt) }}
{% endif %}
{{ text }}
</span>
{% endif %}
for the second issue, the code could be as simple as:
height="{{ height|default('30') }}"
inside the macro (or any value that is related with the dimensions of the drupal logo (I forgot that '' also gives error in the validator)
Remaining tasks
User interface changes
API changes
Data model changes
Best,