protected function PodcastViewsMappingsTrait::buildElementForLink in Podcast (using Views) 8
Same as buildElementFromOptions but generates full URLs.
Parameters
string $key: The name of the key.
int $row_index: The index of the row to get the fields from.
string[] $options_parents: The parents to extract the field name from the config options.
Return value
array Key value array for the property.
2 calls to PodcastViewsMappingsTrait::buildElementForLink()
- Rss::getPodcastElements in src/
Plugin/ views/ style/ Rss.php - Return an array of additional XHTML elements to add to the podcast channel.
- RssFields::render in src/
Plugin/ views/ row/ RssFields.php - Render a row object. This usually passes through to a theme template of some form, but not always.
File
- src/
PodcastViewsMappingsTrait.php, line 57
Class
- PodcastViewsMappingsTrait
- Trait that contains common mapping tasks for channel and item level mappings.
Namespace
Drupal\podcastCode
protected function buildElementForLink($key, $row_index = 0, array $options_parents = NULL) {
$build = $this
->buildElementFromOptions($key, $row_index, $options_parents);
if (empty($build['value'])) {
return [];
}
// Make sure to cast to a string for the Url conversion.
$value = (string) $build['value'];
// Do not convert to an absolute URL if it already is one.
if (preg_match('/https?:/', $value)) {
return [
'key' => $key,
'value' => $value,
];
}
$link_input = '/' . ltrim($value, '/');
try {
return [
'key' => $key,
'value' => Url::fromUserInput($link_input)
->setAbsolute()
->toString(),
];
} catch (\InvalidArgumentException $exception) {
watchdog_exception('podcast', $exception);
}
return [];
}