You are here

protected function views_timelinejs_plugin_style_timelinejs::build_media in Views TimelineJS integration 7.3

Builds timeline media from the current data row.

Return value

TimelineMedia|NULL A media object or NULL if the URL is empty.

2 calls to views_timelinejs_plugin_style_timelinejs::build_media()
views_timelinejs_plugin_style_timelinejs::build_slide in ./views_timelinejs_plugin_style_timelinejs.inc
Builds a timeline slide from the current views data row.
views_timelinejs_plugin_style_timelinejs::build_title_slide in ./views_timelinejs_plugin_style_timelinejs.inc
Builds a timeline title slide from the current views data row.

File

./views_timelinejs_plugin_style_timelinejs.inc, line 564

Class

views_timelinejs_plugin_style_timelinejs
Style plugin to render items as TimelineJS3 slides.

Code

protected function build_media() {
  $url = '';
  if ($this->options['timeline_fields']['media']) {
    $url = $this
      ->get_field($this->view->row_index, $this->options['timeline_fields']['media']);

    // Special handling because core Image fields have no raw URL formatter.
    // Check to see if we don't have a raw URL.
    if (!filter_var($url, FILTER_VALIDATE_URL)) {

      // Attempt to extract a URL from an img or anchor tag in the string.
      $url = $this
        ->extract_url($url);
    }
  }

  // Return NULL if the URL is empty.
  if (empty($url)) {
    return NULL;
  }
  $media = new TimelineMedia($url);
  if ($this->options['timeline_fields']['thumbnail']) {
    $thumbnail = $this
      ->get_field($this->view->row_index, $this->options['timeline_fields']['thumbnail']);

    // Special handling because core Image fields have no raw URL formatter.
    // Check to see if we don't have a raw URL.
    if (!filter_var($thumbnail, FILTER_VALIDATE_URL)) {

      // Attempt to extract a URL from an img or anchor tag in the string.
      $thumbnail = $this
        ->extract_url($thumbnail);
    }
    $media
      ->setThumbnail($thumbnail);
  }
  if ($this->options['timeline_fields']['caption']) {
    $media
      ->setCaption($this
      ->get_field($this->view->row_index, $this->options['timeline_fields']['caption']));
  }
  if ($this->options['timeline_fields']['credit']) {
    $media
      ->setCredit($this
      ->get_field($this->view->row_index, $this->options['timeline_fields']['credit']));
  }
  return $media;
}