-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpubkey_encrypt.install
45 lines (41 loc) · 1.22 KB
/
pubkey_encrypt.install
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
<?php
/**
* @file
* Install, update and uninstall functions for the pubkey_encrypt module.
*/
/**
* Implements hook_install().
*/
function pubkey_encrypt_install() {
// Rebuild user entity form display for new fields.
$storage = \Drupal::entityTypeManager()->getStorage('entity_form_display');
$user_form_display = $storage->load('user.user.default');
if (!$user_form_display) {
$user_form_display = $storage->create([
'targetEntityType' => 'user',
'bundle' => 'user',
'mode' => 'default',
'status' => TRUE,
]);
}
// Hide all fields from UI.
$user_form_display
->removeComponent('field_public_key')
->removeComponent('field_private_key')
->removeComponent('field_private_key_protected')
->save();
drupal_set_message(t('The module Pubkey Encrypt needs to be initialized.'), 'warning');
}
/**
* Implements hook_uninstall().
*/
function pubkey_encrypt_uninstall() {
// Delete Encryption Profiles for all Role keys.
$keys = \Drupal::service('key.repository')
->getKeysByProvider('pubkey_encrypt');
foreach ($keys as $key) {
\Drupal::entityTypeManager()->getStorage('encryption_profile')
->load($key->id() . '_encryption_profile')
->delete();
}
}