Skip to content
Snippets Groups Projects

Add aria-hidden form option

1 file
+ 13
0
Compare changes
  • Side-by-side
  • Inline
@@ -70,6 +70,7 @@ public static function defaultSettings() {
'force_fill' => FALSE,
'sanitize' => TRUE,
'sanitize_remote' => FALSE,
'aria_hidden' => FALSE,
] + parent::defaultSettings();
}
@@ -162,6 +163,12 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
],
],
];
$form['aria_hidden'] = [
'#title' => $this->t('Hide from screen readers'),
'#description' => $this->t('Apply aria-hidden attribute'),
'#type' => 'checkbox',
'#default_value' => $this->getSetting('aria_hidden'),
];
$form['link'] = [
'#title' => $this->t('Link image to'),
'#type' => 'select',
@@ -198,6 +205,9 @@ public function settingsSummary() {
if ($this->getSetting('apply_dimensions') && $this->getSetting('width')) {
$summary[] = $this->t('Image height: @height', ['@height' => $this->getSetting('height')]);
}
if ($this->getSetting('aria_hidden')) {
$summary[] = $this->t('Hide from screen readers');
}
if ($this->getSetting('enable_alt')) {
$summary[] = $this->t('Alt enabled');
}
@@ -224,6 +234,9 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
$attributes['width'] = $this->getSetting('width');
$attributes['height'] = $this->getSetting('height');
}
if ($this->getSetting('aria_hidden')) {
$attributes['aria-hidden'] = 'true';
}
$url = NULL;
$image_link_setting = $this->getSetting('link');
Loading