You are here

function field_encrypt_form_field_add_form_builder in Field Encryption 3.0.x

Same name and namespace in other branches
  1. 8.2 field_encrypt.module \field_encrypt_form_field_add_form_builder()

Update the field storage configuration to set the encryption state.

Parameters

string $entity_type: The entity type.

\Drupal\field\Entity\FieldStorageConfig $field_storage_config: The field storage config entity.

array $form: The complete form array.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

1 string reference to 'field_encrypt_form_field_add_form_builder'
field_encrypt_form_alter in ./field_encrypt.module
Implements hook_form_alter().

File

./field_encrypt.module, line 101
Contains module hooks for field_encrypt.

Code

function field_encrypt_form_field_add_form_builder($entity_type, FieldStorageConfig $field_storage_config, array &$form, FormStateInterface $form_state) {
  $field_encryption_settings = $form_state
    ->getValue('field_encrypt');
  $field_encryption_settings['encrypt'] = (bool) $field_encryption_settings['encrypt'];

  // If the form has the value, we set it.
  if ($field_encryption_settings['encrypt']) {
    foreach ($field_encryption_settings as $settings_key => $settings_value) {
      $field_storage_config
        ->setThirdPartySetting('field_encrypt', $settings_key, $settings_value);
    }
  }
  else {

    // If there is no value, remove third party settings.
    $field_storage_config
      ->unsetThirdPartySetting('field_encrypt', 'encrypt');
    $field_storage_config
      ->unsetThirdPartySetting('field_encrypt', 'properties');
  }
}