-
Notifications
You must be signed in to change notification settings - Fork 0
/
oe_subscriptions.module
65 lines (57 loc) · 1.79 KB
/
oe_subscriptions.module
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
* Subscriptions module.
*/
declare(strict_types=1);
use Drupal\Core\Form\FormStateInterface;
use Drupal\oe_subscriptions\Form\SettingsForm;
/**
* Implements hook_theme().
*/
function oe_subscriptions_theme(array $existing, string $type, string $theme, string $path): array {
return [
'oe_subscriptions_no_subscriptions' => [
'variables' => [],
],
'oe_subscriptions_introduction' => [
'variables' => [
'text' => '',
],
],
'oe_subscriptions_user_subscriptions_page' => [
'render element' => 'elements',
],
];
}
/**
* Prepares variables for the user subscriptions page template.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the content of the page.
*/
function template_preprocess_oe_subscriptions_user_subscriptions_page(array &$variables): void {
$subscriptions_config = \Drupal::configFactory()->get(SettingsForm::CONFIG_NAME);
$introduction_text = $subscriptions_config->get('introduction_text');
if (empty($introduction_text['value'])) {
return;
}
$variables['introduction'] = [
'#type' => 'processed_text',
'#text' => $introduction_text['value'],
'#format' => $introduction_text['format'] ?? '',
];
}
/**
* Implements hook_form_FORM_ID_alter() for the user subscriptions form.
*
* Wraps the user subscriptions form with the dedicated page template.
* This is added in a hook so the standard form wrappers will be added normally,
* and our wrapper only appended later on.
*/
function oe_subscriptions_form_oe_subscriptions_user_subscriptions_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
$form['#theme_wrappers']['oe_subscriptions_user_subscriptions_page'] = [
'#attributes' => [],
];
}