5 * Hook implementations for media_entity_twitter module.
9 * Implements hook_theme().
11 function media_entity_twitter_theme() {
13 'media_entity_twitter_tweet' => [
14 'variables' => ['path' => NULL, 'attributes' => []],
16 'media_entity_twitter_tweet_thumbnail' => [
27 * Preprocess function for media_entity_twitter_tweet_thumbnail theme hook.
29 * @param array $variables
30 * Variables to be injected into the template.
32 function media_entity_twitter_preprocess_media_entity_twitter_tweet_thumbnail(array &$variables) {
33 // If the avatar exists, load it directly into memory and base64 encode it.
34 // For security reasons, browsers don't always allow external images xlinked
35 // in an SVG to be displayed when the SVG is being embedded via an <img> tag.
36 // The workaround is to embed the image directly into the SVG as a base64
38 if ($variables['avatar']) {
39 $extension = pathinfo($variables['avatar'], PATHINFO_EXTENSION);
40 $extension = strtolower($extension);
42 // Don't fetch the avatar if it has an unrecognized extension.
43 if (in_array($extension, ['gif', 'jpg', 'jpeg', 'png', 'webp'])) {
44 $data = file_get_contents($variables['avatar']);
47 // image/jpg is not a thing.
48 if ($extension == 'jpg') {
51 $variables['avatar'] = 'data:image/' . $extension . ';base64,' . base64_encode($data);
54 unset($variables['avatar']);
58 unset($variables['avatar']);