You are here

public function BlazyStylePluginTrait::getCaption in Blazy 8.2

Same name and namespace in other branches
  1. 8 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 116

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'])) {

    // Exclude non-caption fields so that theme_views_view_fields() kicks in
    // and only render expected caption fields. As long as not-hidden, each
    // caption field should be wrapped with Views markups.
    $excludes = array_diff_assoc(array_combine($keys, $keys), $settings['caption']);
    foreach ($excludes as $field) {
      $this->view->field[$field]->options['exclude'] = TRUE;
    }
    $items['data'] = $this->view->rowPlugin
      ->render($this->view->result[$index]);
  }
  $items['link'] = empty($settings['link']) ? [] : $this
    ->getFieldRendered($index, $settings['link']);
  $items['title'] = empty($settings['title']) ? [] : $this
    ->getFieldRendered($index, $settings['title'], TRUE);
  $items['overlay'] = empty($settings['overlay']) ? [] : $this
    ->getFieldRendered($index, $settings['overlay']);
  return $items;
}