You are here

public function BlazyStylePluginTrait::getCaption in Blazy 8

Same name and namespace in other branches
  1. 8.2 src/Dejavu/BlazyStylePluginTrait.php \Drupal\blazy\Dejavu\BlazyStylePluginTrait::getCaption()
  2. 7 src/Dejavu/BlazyStylePluginTrait.php \Drupal\blazy\Dejavu\BlazyStylePluginTrait::getCaption()

Returns the rendered caption fields.

1 call to BlazyStylePluginTrait::getCaption()
BlazyStylePluginBase::buildElement in src/Dejavu/BlazyStylePluginBase.php
Returns an individual row/element content.

File

src/Dejavu/BlazyStylePluginTrait.php, line 229

Class

BlazyStylePluginTrait
A Trait common for optional views style plugins.

Namespace

Drupal\blazy\Dejavu

Code

public function getCaption($index, $settings = []) {
  $items = [];
  $keys = array_keys($this->view->field);
  if (!empty($settings['caption'])) {
    $caption_items = [];
    foreach ($settings['caption'] as $key => $caption) {
      $caption_rendered = $this
        ->getField($index, $caption);
      if (empty($caption_rendered)) {
        continue;
      }
      if (in_array($caption, array_values($keys))) {
        $caption_items[$key]['#markup'] = $caption_rendered;
      }
    }
    $items['data'] = $caption_items;
  }
  $items['link'] = empty($settings['link']) ? [] : $this
    ->getFieldRendered($index, $settings['link']);
  $items['title'] = empty($settings['title']) ? [] : $this
    ->getFieldRendered($index, $settings['title'], TRUE);
  if (!empty($settings['overlay'])) {
    $items['overlay'] = $this
      ->getFieldRendered($index, $settings['overlay']);
  }
  return $items;
}