my custom module block, with supposely no cache
<?php
namespace Drupal\amu_social_icon\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'Icon' Block
*
* @Block(
* id = "amu_social_icon_block",
* admin_label = @Translation("Social Icon block"),
* )
*/
class IconBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$config = \Drupal::config('amu_social_icon.settings');
return [
'#theme' => 'amu_social_icon_block',
'#icons' => $config->get('amu_social_icon_icons'),
'#attached' => [
'library' => [
'amu_social_icon/global-styling',
],
],
];
}
/**
* @return int
*/
public function getCacheMaxAge() {
return 0;
}
}
the language context i am trying to add on internal urls
<ul class="social-icon menu socialicon-nav">
{{ dump(language) }}
{% for icon in icons %}
{% if icon.url is not empty %}
{% if icon.url starts with '/' %}
<li><a href="/{{ language }}{{ icon.url }}" aria-label="{{ icon.aria_label }}"><i aria-hidden="true" class="{{ icon.icon }}"></i></a></li>
{% else %}
<li><a href="{{ icon.url }}" aria-label="{{ icon.aria_label }}"><i aria-hidden="true" class="{{ icon.icon }}"></i></a></li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
i understood the variable passed by hook_theme are static so i have tried to override it on preprocess block
function amu_social_icon_theme($existing, $type, $theme, $path) {
return [
'amu_social_icon_block' => [
'variables' => [
'icons' => null,
'language' => \Drupal::languageManager()->getCurrentLanguage()->getId()
],
],
];
}
function amu_social_icon_preprocess_block(&$vars) {
if ($vars['plugin_id'] == 'amu_social_icon_block') {
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$vars['language'] = $language;
}
}
None of these works. I need to empty drupal cache so that
{{ dump(language) }}
display the correct current language