This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
media_entity.theme.inc
65 lines (58 loc) · 1.86 KB
/
media_entity.theme.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* @file
* Theme functions for the media_entity module.
*/
use Drupal\Core\Render\Element;
use Drupal\Core\Link;
use Drupal\Component\Utility\Html;
/**
* Prepares variables for list of available media bundles.
*
* Default template: media-add-list.html.twig.
*
* @param array $variables
* An associative array containing:
* - content: An array of content types.
*/
function template_preprocess_media_add_list(&$variables) {
$variables['bundles'] = [];
if (!empty($variables['content'])) {
foreach ($variables['content'] as $bundle) {
/** @var \Drupal\media_entity\MediaBundleInterface $bundle */
$variables['bundles'][$bundle->id()] = [
'type' => $bundle->id(),
'add_link' => Link::createFromRoute($bundle->label(), 'media.add', ['media_bundle' => $bundle->id()]),
'description' => [
'#markup' => $bundle->getDescription(),
],
];
}
}
}
/**
* Prepares variables for media templates.
*
* Default template: media.html.twig.
*
* @param array $variables
* An associative array containing:
* - media: An individual media for display.
*/
function template_preprocess_media(&$variables) {
/** @var \Drupal\media_entity\MediaInterface $media */
$media = $variables['elements']['#media'];
$variables['name'] = $media->label();
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
$variables['attributes']['class'][] = 'media';
$variables['attributes']['class'][] = Html::getClass('media-' . $media->bundle());
if (!$media->isPublished()) {
$variables['attributes']['class'][] = 'unpublished';
}
if ($variables['elements']['#view_mode']) {
$variables['attributes']['class'][] = Html::getClass('view-mode-' . $variables['elements']['#view_mode']);
}
}