You are here

function slick_get_caption in Slick Carousel 7.2

Builds slide captions with possible multi-value fields.

3 calls to slick_get_caption()
slick_format_field_collection in includes/slick.field_collection.inc
Formats Field collection data.
slick_format_media in includes/slick.media.inc
Formats image/media file data.
slick_format_paragraphs in includes/slick.paragraphs.inc
Formats Paragraphs data.

File

includes/slick.extras.inc, line 191
Contains optional functions called by frontend Media, or Field collection.

Code

function slick_get_caption($settings, $entity_type, $entity, array &$slide = array()) {
  $view_mode = $settings['view_mode'];

  // Title can be plain text, or link field.
  if (!empty($settings['slide_title']) && ($slide_title = field_get_items($entity_type, $entity, $settings['slide_title']))) {
    if (isset($slide_title[0]['value']) && !empty($slide_title[0]['value'])) {

      // Prevents HTML-filter-enabled text from having bad markups (h2 > p),
      // except for a few reasonable tags acceptable within H2 tag.
      $slide['caption']['title']['#markup'] = strip_tags($slide_title[0]['value'], '<a><strong><em><span><small>');
    }
    elseif (isset($slide_title[0]['url']) && !empty($slide_title[0]['title'])) {

      // The $item paramater expected here is $slide_title[0].
      $slide['caption']['title'] = field_view_value($entity_type, $entity, $settings['slide_title'], $slide_title[0], $view_mode);
    }
  }

  // Other caption fields, if so configured.
  if (!empty($settings['slide_caption'])) {
    $caption_items = array();
    foreach ($settings['slide_caption'] as $i => $caption_field) {
      if (!empty($settings['markup'])) {
        $rendereable = field_view_field($entity_type, $entity, $caption_field, $view_mode);
        $caption_items[$i] = empty($rendereable) ? array() : $rendereable;
      }
      elseif ($captions = field_get_items($entity_type, $entity, $caption_field)) {
        foreach ($captions as $j => $caption) {
          $rendereable = field_view_value($entity_type, $entity, $caption_field, $caption, $view_mode);
          $caption_items[$i][$j] = empty($rendereable) ? array() : $rendereable;
        }
      }
    }
    if (array_filter($caption_items)) {
      $slide['caption']['data'] = $caption_items;
    }
  }

  // Link, if so configured.
  if (!empty($settings['slide_link']) && ($slide_links = field_get_items($entity_type, $entity, $settings['slide_link']))) {
    $links = field_view_field($entity_type, $entity, $settings['slide_link'], $view_mode);

    // Only simplify markups for the known formatters registered by link.module.
    if (isset($links['#formatter']) && strpos($links['#formatter'], 'link_') !== FALSE) {
      $links = array();
      foreach ($slide_links as $i => $slide_link) {
        $links[$i] = field_view_value($entity_type, $entity, $settings['slide_link'], $slide_link, $view_mode);
      }
    }
    $slide['caption']['link'] = $links;
  }
}