webform_encrypt.module 1.65 KB
Newer Older
Jake Bell's avatar
Jake Bell committed
1 2
<?php

Jake Bell's avatar
Jake Bell committed
3 4 5 6 7
/**
 * @file
 * Main module file for the Webform Encrypt module.
 */

8 9
use Drupal\Core\Form\FormStateInterface;

10
/**
11
 * Implements hook_form_FORM_ID_alter().
12
 */
13
function webform_encrypt_form_webform_ui_element_form_alter(&$form, FormStateInterface $form_state) {
14 15 16 17 18
  /** @var \Drupal\webform\WebformElementManagerInterface $element_manager */
  $element_manager = \Drupal::service('plugin.manager.webform.element');

  $element = $form_state->getBuildInfo()['callback_object']->getElement();
  $element_handler = $element_manager->getElementInstance($element);
19

20 21 22 23
  // Checks whether the element carries a value.
  // Only input elements are allowed to be encrypted.
  $is_input_element = $element_handler->isInput($element);
  if ($is_input_element) {
th_tushar's avatar
th_tushar committed
24 25 26 27
    // To provide the fieldset for encryption fields on element config form.
    $form['element_encrypt'] = [
      '#type' => 'details',
      '#title' => t('Encryption'),
28
      '#group' => 'tab_advanced',
th_tushar's avatar
th_tushar committed
29
    ];
30

th_tushar's avatar
th_tushar committed
31 32 33
    // To provide the encryption fields for webform elements.
    $form['element_encrypt']['encrypt'] = [
      '#type' => 'webform_element_encrypt',
34
      '#title' => t('Encryption'),
th_tushar's avatar
th_tushar committed
35 36
      '#title_display' => 'hidden',
    ];
Jake Bell's avatar
Jake Bell committed
37
  }
38
}
Jake Bell's avatar
Jake Bell committed
39

40 41 42 43 44
/**
 * Implements hook_entity_type_alter().
 */
function webform_encrypt_entity_type_alter(array &$entity_types) {
  /* @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
45 46 47 48
  if (isset($entity_types['webform_submission'])) {
    $entity_types['webform_submission']->setStorageClass('Drupal\webform_encrypt\WebformEncryptSubmissionStorage');
    $entity_types['webform_submission']->setAccessClass('Drupal\webform_encrypt\WebformEncryptSubmissionAccessControlHandler');
  }
49
}