You are here

class Slide in Views TimelineJS integration 8.3

Defines a TimelineJS3 slide.

Hierarchy

Expanded class hierarchy of Slide

1 file declares its use of Slide
TimelineJS.php in src/Plugin/views/style/TimelineJS.php

File

src/TimelineJS/Slide.php, line 8

Namespace

Drupal\views_timelinejs\TimelineJS
View source
class Slide implements SlideInterface {

  /**
   * The slide start date.
   *
   * @var \Drupal\views_timelinejs\TimelineJS\DateInterface
   */
  protected $startDate;

  /**
   * The slide end date.
   *
   * @var \Drupal\views_timelinejs\TimelineJS\DateInterface
   */
  protected $endDate;

  /**
   * The slide headline and text.
   *
   * @var \Drupal\views_timelinejs\TimelineJS\TextInterface
   */
  protected $text;

  /**
   * The slide media and its metadata.
   *
   * @var \Drupal\views_timelinejs\TimelineJS\MediaInterface
   */
  protected $media;

  /**
   * The slide group.
   *
   * @var string
   */
  protected $group;

  /**
   * The slide display date.
   *
   * @var string
   */
  protected $displayDate;

  /**
   * The slide background url and color.
   *
   * @var \Drupal\views_timelinejs\TimelineJS\BackgroundInterface
   */
  protected $background;

  /**
   * The slide autolink property.
   *
   * @var bool
   */
  protected $autolink = TRUE;

  /**
   * The slide unique id.
   *
   * @var int|string
   */
  protected $uniqueId;

  /**
   * Constructs a new Slide object.
   *
   * @param \Drupal\views_timelinejs\TimelineJS\DateInterface $start_date
   *   The slide's start date.
   * @param \Drupal\views_timelinejs\TimelineJS\DateInterface|null $end_date
   *   The slide's end date.
   * @param \Drupal\views_timelinejs\TimelineJS\TextInterface|null $text
   *   Text to display on the slide.
   */
  public function __construct(DateInterface $start_date, DateInterface $end_date = NULL, TextInterface $text = NULL) {
    $this->startDate = $start_date;
    if (!empty($end_date)) {
      $this->endDate = $end_date;
    }
    if (!empty($text)) {
      $this->text = $text;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setMedia(MediaInterface $media) {
    $this->media = $media;
  }

  /**
   * {@inheritdoc}
   */
  public function setGroup($group) {
    $this->group = $group;
  }

  /**
   * {@inheritdoc}
   */
  public function setDisplayDate($display_date) {
    $this->displayDate = $display_date;
  }

  /**
   * {@inheritdoc}
   */
  public function setBackground(BackgroundInterface $backgound) {
    $this->background = $backgound;
  }

  /**
   * {@inheritdoc}
   */
  public function setUniqueId($id) {
    $this->uniqueId = $id;
  }

  /**
   * {@inheritdoc}
   */
  public function enableAutolink() {
    $this->autolink = TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function disableAutolink() {
    $this->autolink = FALSE;
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Slide::$autolink protected property The slide autolink property.
Slide::$background protected property The slide background url and color.
Slide::$displayDate protected property The slide display date.
Slide::$endDate protected property The slide end date.
Slide::$group protected property The slide group.
Slide::$media protected property The slide media and its metadata.
Slide::$startDate protected property The slide start date.
Slide::$text protected property The slide headline and text.
Slide::$uniqueId protected property The slide unique id.
Slide::buildArray public function Creates an array representing the TimelineJS javascript object. Overrides ObjectInterface::buildArray 1
Slide::disableAutolink public function Sets the slide's autolink property to FALSE. Overrides SlideInterface::disableAutolink
Slide::enableAutolink public function Sets the slide's autolink property to TRUE. Overrides SlideInterface::enableAutolink
Slide::setBackground public function Sets the background for this slide. Overrides SlideInterface::setBackground
Slide::setDisplayDate public function Sets the display date for this slide. Overrides SlideInterface::setDisplayDate
Slide::setGroup public function Sets the group for this slide. Overrides SlideInterface::setGroup
Slide::setMedia public function Sets the media for this slide. Overrides SlideInterface::setMedia
Slide::setUniqueId public function Sets the unique ID for this slide. Overrides SlideInterface::setUniqueId
Slide::__construct public function Constructs a new Slide object. 1