function FileMediaFormatterBase::prepareAttributes

Same name in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileMediaFormatterBase::prepareAttributes()
  2. 10 core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileMediaFormatterBase::prepareAttributes()
  3. 11.x core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileMediaFormatterBase::prepareAttributes()

Prepare the attributes according to the settings.

Parameters

string[] $additional_attributes: Additional attributes to be applied to the HTML element. Attribute names will be used as key and value in the HTML element.

Return value

\Drupal\Core\Template\Attribute Container with all the attributes for the HTML tag.

1 call to FileMediaFormatterBase::prepareAttributes()
FileMediaFormatterBase::viewElements in core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php
Builds a renderable array for a field value.
1 method overrides FileMediaFormatterBase::prepareAttributes()
FileVideoFormatter::prepareAttributes in core/modules/file/src/Plugin/Field/FieldFormatter/FileVideoFormatter.php
Prepare the attributes according to the settings.

File

core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php, line 152

Class

FileMediaFormatterBase
Base class for media file formatter.

Namespace

Drupal\file\Plugin\Field\FieldFormatter

Code

protected function prepareAttributes(array $additional_attributes = []) {
    $attributes = new Attribute();
    foreach (array_merge([
        'controls',
        'autoplay',
        'loop',
    ], $additional_attributes) as $attribute) {
        if ($this->getSetting($attribute)) {
            $attributes->setAttribute($attribute, $attribute);
        }
    }
    return $attributes;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.