-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathIpRangeAccessExemptionController.php
More file actions
75 lines (66 loc) · 1.93 KB
/
IpRangeAccessExemptionController.php
File metadata and controls
75 lines (66 loc) · 1.93 KB
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
72
73
74
75
<?php
namespace Drupal\embargo\Controller;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller for displaying an IP access denied message.
*/
class IpRangeAccessExemptionController extends ControllerBase {
/**
* The HTTP request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* Constructs an IP access denied controller.
*
* @param \Symfony\Component\HttpFoundation\Request|null $request
* The current request.
*/
public function __construct(?Request $request = NULL) {
$this->request = $request;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('request_stack')->getCurrentRequest());
}
/**
* Formats a response for an IP access denied page.
*
* @return array
* Renderable array of markup for IP access denied.
*/
public function response() {
$ranges = [];
$cache_tags = [];
/** @var \Drupal\embargo\IpRangeInterface[] $entities */
$entities = $this->entityTypeManager()->getStorage('embargo_ip_range')->loadMultiple($this->request->query->all()['ranges'] ?? []);
foreach ($entities as $entity) {
$ranges[] = [
'label' => $entity->label(),
'proxy_url' => $entity->getProxyUrl(),
];
$cache_tags = Cache::mergeTags($cache_tags, $entity->getCacheTags());
}
return [
'#theme' => 'embargo_ip_access_exemption',
'#resources' => $this->request->query->all()['resources'] ?? [],
'#ranges' => $ranges,
'#contact_email' => $this->config('embargo.settings')->get('contact_email'),
'#cache' => [
'contexts' => [
'user',
'url.path',
'url.query_args',
],
'tags' => $cache_tags,
],
];
}
}