thunder_amp.theme in Thunder 8.3
Same filename and directory in other branches
Preprocess html for thunder_amp theme.
File
themes/thunder_amp/thunder_amp.themeView source
<?php
/**
* @file
* Preprocess html for thunder_amp theme.
*/
/**
* Implements hook_preprocess_HOOK() for HTML document templates.
*
* Example of a preprocess hook for a subtheme that could be used to change
* variables in templates in order to support custom styling of AMP pages.
*/
function thunder_amp_preprocess_html(&$variables) {
}
/**
* Implements hook_preprocess_HOOK().
*/
function thunder_amp_preprocess_media__source_oembed__derivative_video__provider_youtube(&$variables) {
/** @var \Drupal\media\Entity\Media $media */
$media = $variables['media'];
$url = $media
->getSource()
->getSourceFieldValue($media);
preg_match('%(?:youtube(?:-nocookie)?\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\\.be/)([^"&?/ ]{11})%i', $url, $match);
$variables['videoid'] = $match[1];
_thunder_amp_set_oembed_attributes($variables, $url);
}
/**
* Implements hook_preprocess_HOOK().
*/
function thunder_amp_preprocess_media__source_oembed__derivative_video__provider_vimeo(&$variables) {
/** @var \Drupal\media\Entity\Media $media */
$media = $variables['media'];
$url = $media
->getSource()
->getSourceFieldValue($media);
preg_match('%^https?:\\/\\/(?:www\\.|player\\.)?vimeo.com\\/(?:channels\\/(?:\\w+\\/)?|groups\\/([^\\/]*)\\/videos\\/|album\\/(\\d+)\\/video\\/|video\\/|)(\\d+)(?:$|\\/|\\?)(?:[?]?.*)$%im', $url, $match);
$variables['videoid'] = $match[3];
_thunder_amp_set_oembed_attributes($variables, $url);
}
/**
* Set's width and height for oEmbed items.
*/
function _thunder_amp_set_oembed_attributes(&$variables, $url) {
/** @var \Drupal\media\OEmbed\UrlResolverInterface $url_resolver */
$url_resolver = \Drupal::service('media.oembed.url_resolver');
$resource_url = $url_resolver
->getResourceUrl($url);
/** @var \Drupal\media\OEmbed\ResourceFetcherInterface $resource_fetcher */
$resource_fetcher = \Drupal::service('media.oembed.resource_fetcher');
$resource = $resource_fetcher
->fetchResource($resource_url);
$variables['attributes']['width'] = $resource
->getWidth();
$variables['attributes']['height'] = $resource
->getHeight();
}
/**
* Implements hook_preprocess_HOOK().
*/
function thunder_amp_preprocess_media_twitter_tweet(&$variables) {
$explodedUrl = explode('/', $variables['path']);
$variables['tweetid'] = end($explodedUrl);
}
Functions
Name | Description |
---|---|
thunder_amp_preprocess_html | Implements hook_preprocess_HOOK() for HTML document templates. |
thunder_amp_preprocess_media_twitter_tweet | Implements hook_preprocess_HOOK(). |
thunder_amp_preprocess_media__source_oembed__derivative_video__provider_vimeo | Implements hook_preprocess_HOOK(). |
thunder_amp_preprocess_media__source_oembed__derivative_video__provider_youtube | Implements hook_preprocess_HOOK(). |
_thunder_amp_set_oembed_attributes | Set's width and height for oEmbed items. |