-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrusign.module
124 lines (115 loc) · 4.8 KB
/
drusign.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
use \Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use \Drupal\Core\Entity\Display\EntityViewDisplayInterface;
/**
* Implements hook_help().
*
* The help page of the module
*/
function drusign_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.drusign':
return t('<p>The "Drusign" Module provides Contract Signing Capabilities for Drupal</p>');
}
}
/**
* Implements hook_mail().
*
* Creates the content of the e-mails created in the 'ContractReceiverForm' class and the 'SendButtonForm' class.
*/
function drusign_mail($key, &$message, $params) {
$options = [
'langcode' => $message['langcode'],
];
switch ($key) {
// The mail containing the link to the contract:
case 'drusign_send_contract':
// Dynamic parameters from the 'SendButtonForm' class:
$contractUrl = $params["contractUrl"];
$receiverName = $params["receiverName"];
$senderName = $params["senderName"];
// Creating the subject and body of the mail:
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t("Important Contract from {$senderName}", [], $options);
$message['body'][] = t("Dear Mr, Mrs {$receiverName},<br/>there is a Contract from {$senderName} for you to sign.<br/> Please follow the following link to receive {$contractUrl} ", [], $options);
break;
// The mail containing the contract accept message, if a contract was accepted:
case 'drusign_send_accepted':
// Dynamic parameters from the 'ContractReceiverForm' class:
$userMailA = $params['userMailA'];
$userNameA = $params['userNameA'];
$contractNameA = $params['contractNameA'];
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t("Mr/Ms {$userNameA} accepted your Contract {$contractNameA}!", [], $options);
$message['body'][] = t("Your Contract {$contractNameA} was accepted by Mr/Ms {$userNameA},<br />if you want to contact him directly write an E-Mail to this adress: {$userMailA}", [], $options);
break;
// The mail containing the contract rejected message, if a contract was rejected:
case 'drusign_send_rejected':
// Dynamic parameters from the 'ContractReceiverForm' class:
$userMailR = $params['userMailR'];
$userNameR = $params['userNameR'];
$contractNameR = $params['contractNameR'];
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t("Mr/Ms {$userNameR} rejected your Contract {$contractNameR}!", [], $options);
$message['body'][] = t("Your Contract {$contractNameR} was rejected by Mr/Ms {$userNameR},<br />if you want to contact him directly write an E-Mail to this adress: {$userMailR}", [], $options);
break;
}
}
/**
* Implements hook_form_alter().
*
* It can alter different forms.
*/
function drusign_form_alter(&$form, &$form_state, $form_id) {
// Logic to render a form on the contract creation and edit site:
$formObject = $form_state->getFormObject();
if ($formObject instanceof \Drupal\Core\Entity\EntityFormInterface) {
$entity = $formObject->getEntity();
$operation = $formObject->getOperation();
if (
$entity->getEntityTypeId() === 'node'
&& in_array($entity->bundle(), ['vertrag'])
&& ($operation === 'edit' || $operation === 'default')
) {
// Render a textarea where the user can type his contract content in on
// submission the content of this field gets encrypted and saved in the
// 'original' textarea of the contract node:
$form['#attached']['library'][] = 'drusign/init';
$form['unencrypted_text'][] = [
'#title' => t('Vertragsinhalt'),
'#type' => 'textarea',
'#weight' => 10,
'#attributes' => [
'id' => 'unencrypted_text'
]
];
}
}
}
/**
* Implements hook_entity_extra_field_info().
*
* Used in combination with 'drusign_node_view' to render the 'drusign_send_form' as a field on the contract view page of each contract.
*/
function drusign_entity_extra_field_info() {
$extra = array();
$extra['node']['vertrag']['display']['send_field'] = [
'label' => t('Send Field'),
'description' => t('Custom Send field for sending Contracts'),
'weight' => 100,
'visible' => TRUE,
];
return $extra;
}
/**
* Implements hook_node_view().
*
* Used in combination with 'drusign_entity_extra_field_info' to render the 'drusign_send_form' as a field on the contract view page of each contract.
*/
function drusign_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
if ($display->getComponent('send_field')) {
$builder = \Drupal::formBuilder();
$build['send_field'] = $builder->getForm('Drupal\drusign\Form\SendButtonForm');
}
}