You are here

protected function TimelineJS::buildBackground in Views TimelineJS integration 8.3

Builds a timeline background from the current data row.

Return value

\Drupal\views_timelinejs\TimelineJS\Background A background object.

2 calls to TimelineJS::buildBackground()
TimelineJS::buildSlide in src/Plugin/views/style/TimelineJS.php
Builds a timeline slide from the current views data row.
TimelineJS::buildTitleSlide in src/Plugin/views/style/TimelineJS.php
Builds a timeline title slide from the current views data row.

File

src/Plugin/views/style/TimelineJS.php, line 605

Class

TimelineJS
Style plugin to render items as TimelineJS3 slides.

Namespace

Drupal\views_timelinejs\Plugin\views\style

Code

protected function buildBackground() {
  $url = '';
  if ($this->options['timeline_fields']['background']) {
    $url_markup = $this
      ->getField($this->view->row_index, $this->options['timeline_fields']['background']);
    $url = $url_markup ? $url_markup
      ->__toString() : '';

    // 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
        ->extractUrl($url);
    }
  }
  $color = '';
  if ($this->options['timeline_fields']['background_color']) {
    $color_markup = $this
      ->getField($this->view->row_index, $this->options['timeline_fields']['background_color']);
    $color = $color_markup ? $color_markup
      ->__toString() : '';
  }
  return new Background($url, $color);
}