MediaThemeHooks.php
Namespace
Drupal\media\HookFile
-
core/
modules/ media/ src/ Hook/ MediaThemeHooks.php
View source
<?php
namespace Drupal\media\Hook;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Render\Element\RenderElementBase;
use Drupal\Core\Render\Element;
use Drupal\Core\Hook\Attribute\Hook;
/**
* Hook implementations for media.
*/
class MediaThemeHooks {
/**
* Implements hook_preprocess_HOOK() for media reference widgets.
*/
public function preprocessMediaReferenceHelp(&$variables) : void {
// Most of these attribute checks are copied from
// \Drupal\Core\Form\FormPreprocess::preprocessFieldset(). Our template
// extends field-multiple-value-form.html.twig to provide our help text, but
// also groups the information within a semantic fieldset with a legend. So,
// we incorporate parity for both.
$element = $variables['element'];
Element::setAttributes($element, [
'id',
]);
RenderElementBase::setAttributes($element);
$variables['attributes'] = $element['#attributes'] ?? [];
$variables['legend_attributes'] = new Attribute();
$variables['header_attributes'] = new Attribute();
$variables['description']['attributes'] = new Attribute();
$variables['legend_span_attributes'] = new Attribute();
if (!empty($element['#media_help'])) {
foreach ($element['#media_help'] as $key => $text) {
$variables[substr($key, 1)] = $text;
}
}
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
MediaThemeHooks | Hook implementations for media. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.