You are here

public function BlazyManager::buildCaption in Blazy 7

Same name and namespace in other branches
  1. 8.2 src/BlazyManager.php \Drupal\blazy\BlazyManager::buildCaption()

Build captions for both old image, or media entity.

1 call to BlazyManager::buildCaption()
BlazyManager::prepareImage in src/BlazyManager.php
Prepares the Blazy image as a structured array ready for ::renderer().

File

src/BlazyManager.php, line 334

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

public function buildCaption(array $captions, array $settings) {
  $content = [];
  foreach ($captions as $key => $caption_content) {
    if ($caption_content) {

      // Sanitization is performed by implementors (formatters).
      $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'] = [];
      $content[$key]['attributes']['class'][] = $settings['item_id'] . '__caption--' . str_replace('_', '-', $class);
    }
  }
  return $content ? [
    'inline' => $content,
  ] : [];
}