function views_rss_core_preprocess_channel_image in Views RSS 8.2
Same name and namespace in other branches
- 8.3 modules/views_rss_core/views_rss_core.inc \views_rss_core_preprocess_channel_image()
- 6.2 modules/views_rss_core/views_rss_core.inc \views_rss_core_preprocess_channel_image()
- 7.2 modules/views_rss_core/views_rss_core.inc \views_rss_core_preprocess_channel_image()
Preprocess function for channel <image> element.
1 string reference to 'views_rss_core_preprocess_channel_image'
- views_rss_core_views_rss_channel_elements in modules/
views_rss_core/ views_rss_core.module - Implements hook_views_rss_item_elements().
File
- modules/
views_rss_core/ views_rss_core.inc, line 99 - Preprocess functions for Views RSS: Core Elements module.
Code
function views_rss_core_preprocess_channel_image(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
$image_path = $variables['elements'][0]['value'];
// Get value of channel <title> element from its preprocess function.
views_rss_core_preprocess_channel_title($variables);
$title = $variables['elements'][0]['value'];
// Create subelements array.
$variables['elements'][0]['value'] = array(
// The image's url element identifies the URL of the image.
'url' => file_create_url($image_path),
// The image's title element SHOULD have the same text as the channel's
// title element and be suitable for use as the alt attribute of the img
// tag in an HTML rendering.
'title' => $title,
// The image's link element identifies the URL of the web site represented
// by the image (not the feed URL).
'link' => $GLOBALS['base_url'] . '/',
);
// Try to get image description from website's mission.
if ($site_slogan = \Drupal::config('system.site')
->get('slogan')) {
$variables['elements'][0]['value']['description'] = $site_slogan;
}
// Get image width and height.
$image = Drupal::service('image.factory')
->get($image_path);
if (!empty($image)) {
$variables['elements'][0]['value']['width'] = $image
->getWidth();
$variables['elements'][0]['value']['height'] = $image
->getHeight();
}
}