public function BlazyManager::buildCaption in Blazy 8.2
Same name and namespace in other branches
- 7 src/BlazyManager.php \Drupal\blazy\BlazyManager::buildCaption()
Build captions for both old image, or media entity.
1 call to BlazyManager::buildCaption()
- BlazyManager::prepareBlazy in src/
BlazyManager.php - Prepares the Blazy output as a structured array ready for ::renderer().
File
- src/
BlazyManager.php, line 341
Class
- BlazyManager
- Implements a public facing blazy manager.
Namespace
Drupal\blazyCode
public function buildCaption(array $captions, array $settings) {
$content = [];
foreach ($captions as $key => $caption_content) {
if ($caption_content) {
$content[$key]['content'] = $caption_content;
$content[$key]['tag'] = strpos($key, 'title') !== FALSE ? 'h2' : 'div';
$class = $key == 'alt' ? 'description' : str_replace('field_', '', $key);
$content[$key]['attributes'] = new Attribute();
$content[$key]['attributes']
->addClass($settings['item_id'] . '__caption--' . str_replace('_', '-', $class));
}
}
return $content ? [
'inline' => $content,
] : [];
}