You are here

public function Slide::buildArray in Views TimelineJS integration 8.3

Creates an array representing the TimelineJS javascript object.

Return value

mixed[] The formatted array.

Overrides ObjectInterface::buildArray

1 method overrides Slide::buildArray()
TitleSlide::buildArray in src/TimelineJS/TitleSlide.php
Creates an array representing the TimelineJS javascript object.

File

src/TimelineJS/Slide.php, line 145

Class

Slide
Defines a TimelineJS3 slide.

Namespace

Drupal\views_timelinejs\TimelineJS

Code

public function buildArray() {
  $slide = [
    'start_date' => $this->startDate
      ->buildArray(),
  ];

  // Don't render end dates that are the same as the start date.  TimelineJS
  // won't display them anyway, but skipping them can make the rendered data
  // array smaller.
  if (!empty($this->endDate) && $this->startDate != $this->endDate) {
    $slide['end_date'] = $this->endDate
      ->buildArray();
  }
  if (!empty($this->text)) {
    $slide['text'] = $this->text
      ->buildArray();
  }
  if (!empty($this->media)) {
    $slide['media'] = $this->media
      ->buildArray();
  }
  if (!empty($this->group)) {
    $slide['group'] = $this->group;
  }
  if (!empty($this->displayDate)) {
    $slide['display_date'] = $this->displayDate;
  }
  if (!empty($this->background)) {
    $slide['background'] = $this->background
      ->buildArray();
  }
  if (!$this->autolink) {
    $slide['autolink'] = FALSE;
  }
  if (!empty($this->uniqueId)) {
    $slide['unique_id'] = $this->uniqueId;
  }

  // Filter any empty values before returning.
  return array_filter($slide);
}