You are here

private function SvgImageFieldFormatter::generateAltAttribute in SVG Image Field 2.1.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/SvgImageFieldFormatter.php \Drupal\svg_image_field\Plugin\Field\FieldFormatter\SvgImageFieldFormatter::generateAltAttribute()
  2. 2.0.x src/Plugin/Field/FieldFormatter/SvgImageFieldFormatter.php \Drupal\svg_image_field\Plugin\Field\FieldFormatter\SvgImageFieldFormatter::generateAltAttribute()

Generate alt attribute from an image filename.

1 call to SvgImageFieldFormatter::generateAltAttribute()
SvgImageFieldFormatter::viewElements in src/Plugin/Field/FieldFormatter/SvgImageFieldFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/SvgImageFieldFormatter.php, line 306

Class

SvgImageFieldFormatter
Plugin implementation of the 'svg_formatter' formatter.

Namespace

Drupal\svg_image_field\Plugin\Field\FieldFormatter

Code

private function generateAltAttribute($filename) {
  $alt = str_replace([
    '.svg',
    '-',
    '_',
  ], [
    '',
    ' ',
    ' ',
  ], $filename);
  $alt = ucfirst($alt);
  return $alt;
}