-
Notifications
You must be signed in to change notification settings - Fork 0
/
fedora_resource.page.inc
71 lines (66 loc) · 2.01 KB
/
fedora_resource.page.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
66
67
68
69
70
71
<?php
/**
* @file
* Contains fedora_resource.page.inc.
*
* Page callback for Fedora resource entities.
*
* This file is part of the Islandora Project.
*
* (c) Islandora Foundation
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Diego Pino Navarro <[email protected]> https://github.com/diegopino
*/
use Drupal\Core\Render\Element;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Prepares variables for Fedora resource templates.
*
* Default template: fedora_resource.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_fedora_resource(array &$variables) {
// Fetch FedoraResource Entity Object.
$fedora_resource = $variables['elements']['#fedora_resource'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
/**
* Prepares variables for a custom entity type creation list templates.
*
* Default template: fedora_resource-content-add-list.html.twig.
*
* @param array $variables
* An associative array containing:
* - content: An array of fedora_resource-types.
*
* @see block_content_add_page()
*/
function template_preprocess_fedora_resource_content_add_list(array &$variables) {
$variables['types'] = [];
$query = \Drupal::request()->query->all();
foreach ($variables['content'] as $type) {
$variables['types'][$type->id()] = [
'link' => Link::fromTextAndUrl($type->label(), new Url('entity.fedora_resource.add_form', [
'fedora_resource_type' => $type->id(),
], ['query' => $query])),
'description' => [
'#markup' => $type->label(),
],
'title' => $type->label(),
'localized_options' => [
'query' => $query,
],
];
}
}