protected function TimelineJS::buildMedia in Views TimelineJS integration 8.3
Builds timeline media from the current data row.
Return value
\Drupal\views_timelinejs\TimelineJS\Media|null A media object or NULL if the URL is empty.
2 calls to TimelineJS::buildMedia()
- 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 633
Class
- TimelineJS
- Style plugin to render items as TimelineJS3 slides.
Namespace
Drupal\views_timelinejs\Plugin\views\styleCode
protected function buildMedia() {
$url = '';
if ($this->options['timeline_fields']['media']) {
$url_markup = $this
->getField($this->view->row_index, $this->options['timeline_fields']['media']);
$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);
}
}
// Return NULL if the URL is empty.
if (empty($url)) {
return NULL;
}
$media = new Media($url);
if ($this->options['timeline_fields']['thumbnail']) {
$thumbnail_markup = $this
->getField($this->view->row_index, $this->options['timeline_fields']['thumbnail']);
$thumbnail = $thumbnail_markup ? $thumbnail_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($thumbnail, FILTER_VALIDATE_URL)) {
// Attempt to extract a URL from an img or anchor tag in the string.
$thumbnail = $this
->extractUrl($thumbnail);
}
$media
->setThumbnail($thumbnail);
}
if ($this->options['timeline_fields']['caption']) {
$caption_markup = $this
->getField($this->view->row_index, $this->options['timeline_fields']['caption']);
$caption = $caption_markup ? $caption_markup
->__toString() : '';
$media
->setCaption($caption);
}
if ($this->options['timeline_fields']['credit']) {
$credit_markup = $this
->getField($this->view->row_index, $this->options['timeline_fields']['credit']);
$credit = $credit_markup ? $credit_markup
->__toString() : '';
$media
->setCredit($credit);
}
return $media;
}