Example #1
0
 public function submitOptionsForm(&$form, FormStateInterface $form_state)
 {
     $exposed_form_options = $form_state->getValue('exposed_form_options');
     $form_state->setValue(array('exposed_form_options', 'text_input_required_format'), $exposed_form_options['text_input_required']['format']);
     $form_state->setValue(array('exposed_form_options', 'text_input_required'), $exposed_form_options['text_input_required']['value']);
     parent::submitOptionsForm($form, $form_state);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function submitOptionsForm(&$form, FormStateInterface $form_state)
 {
     $content = $form_state->getValue(array('options', 'content'));
     $form_state->setValue(array('options', 'format'), $content['format']);
     $form_state->setValue(array('options', 'content'), $content['value']);
     parent::submitOptionsForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Process the upload and perform validation. Note: we're using the
     // form value for the $replace parameter.
     if (!$form_state->isValueEmpty('file_subdir')) {
         $destination = 'temporary://' . $form_state->getValue('file_subdir');
         file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
     } else {
         $destination = FALSE;
     }
     // Setup validators.
     $validators = array();
     if ($form_state->getValue('is_image_file')) {
         $validators['file_validate_is_image'] = array();
     }
     if ($form_state->getValue('allow_all_extensions')) {
         $validators['file_validate_extensions'] = array();
     } elseif (!$form_state->isValueEmpty('extensions')) {
         $validators['file_validate_extensions'] = array($form_state->getValue('extensions'));
     }
     $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace'));
     if ($file) {
         $form_state->setValue('file_test_upload', $file);
         drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
         drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename())));
         drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
         drupal_set_message(t('You WIN!'));
     } elseif ($file === FALSE) {
         drupal_set_message(t('Epic upload FAIL!'), 'error');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     if (!$form_state->hasValue('context')) {
         $form_state->setValue('context', xmlsitemap_get_current_context());
     }
     if ($form_state->hasValue(['context', 'language'])) {
         $language = $form_state->getValue(['context', 'language']);
         if ($language == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
             $form_state->unsetValue(['context', 'language']);
         }
     }
     $context = $form_state->getValue('context');
     $this->entity->context = $context;
     $this->entity->label = $form_state->getValue('label');
     $this->entity->id = xmlsitemap_sitemap_get_context_hash($context);
     try {
         $status = $this->entity->save();
         if ($status == SAVED_NEW) {
             drupal_set_message($this->t('Saved the %label sitemap.', array('%label' => $this->entity->label())));
         } else {
             if ($status == SAVED_UPDATED) {
                 drupal_set_message($this->t('Updated the %label sitemap.', array('%label' => $this->entity->label())));
             }
         }
     } catch (EntityStorageException $ex) {
         drupal_set_message($this->t('There is another sitemap saved with the same context.'), 'error');
     }
     $form_state->setRedirect('xmlsitemap.admin_search');
 }
 /**
  * Sample UI to update a record.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Wrap the form in a div.
     $form = array('#prefix' => '<div id="updateform">', '#suffix' => '</div>');
     // Add some explanatory text to the form.
     $form['message'] = array('#markup' => $this->t('Demonstrates a database update operation.'));
     // Query for items to display.
     $entries = \Drupal::service('dbtng.storage')->load();
     // Tell the user if there is nothing to display.
     if (empty($entries)) {
         $form['no_values'] = array('#value' => $this->t('No entries exist in the table dbtng table.'));
         return $form;
     }
     $keyed_entries = array();
     foreach ($entries as $entry) {
         $options[$entry->pid] = t('@pid: @name @surname (@age)', array('@pid' => $entry->pid, '@name' => $entry->name, '@surname' => $entry->surname, '@age' => $entry->age));
         $keyed_entries[$entry->pid] = $entry;
     }
     // Grab the pid.
     $pid = $form_state->getValue('pid');
     // Use the pid to set the default entry for updating.
     $default_entry = !empty($pid) ? $keyed_entries[$pid] : $entries[0];
     // Save the entries into the $form_state. We do this so the AJAX callback
     // doesn't need to repeat the query.
     $form_state->setValue('entries', $keyed_entries);
     $form['pid'] = array('#type' => 'select', '#options' => $options, '#title' => $this->t('Choose entry to update'), '#default_value' => $default_entry->pid, '#ajax' => array('wrapper' => 'updateform', 'callback' => array($this, 'updateCallback')));
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Updated first name'), '#size' => 15, '#default_value' => $default_entry->name);
     $form['surname'] = array('#type' => 'textfield', '#title' => $this->t('Updated last name'), '#size' => 15, '#default_value' => $default_entry->surname);
     $form['age'] = array('#type' => 'textfield', '#title' => $this->t('Updated age'), '#size' => 4, '#default_value' => $default_entry->age, '#description' => $this->t('Values greater than 127 will cause an exception'));
     $form['submit'] = array('#type' => 'submit', '#value' => $this->t('Update'));
     return $form;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $account = $this->entity;
     $account->save();
     $form_state->setValue('uid', $account->id());
     drupal_set_message($this->t('The changes have been saved.'));
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $file_upload = $this->getRequest()->files->get('files[import_tarball]', NULL, TRUE);
     $has_upload = FALSE;
     if ($file_upload && $file_upload->isValid()) {
         // The sync directory must be empty if we are doing an upload.
         $form_state->setValue('import_tarball', $file_upload->getRealPath());
         $has_upload = TRUE;
     }
     $sync_directory = $form_state->getValue('sync_directory');
     // If we've customised the sync directory ensure its good to go.
     if ($sync_directory != config_get_config_directory(CONFIG_SYNC_DIRECTORY)) {
         // Ensure it exists and is writeable.
         if (!file_prepare_directory($sync_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
             $form_state->setErrorByName('sync_directory', t('The directory %directory could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the <a href="@handbook_url">online handbook</a>.', array('%directory' => $sync_directory, '@handbook_url' => 'http://drupal.org/server-permissions')));
         }
     }
     // If no tarball ensure we have files.
     if (!$form_state->hasAnyErrors() && !$has_upload) {
         $sync = new FileStorage($sync_directory);
         if (count($sync->listAll()) === 0) {
             $form_state->setErrorByName('sync_directory', t('No file upload provided and the sync directory is empty'));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Get an array of strings with the permissions names.
     $permissions = array_keys(array_filter($form_state->getValue('permissions')));
     $form_state->setValue('permissions', $permissions);
     parent::submitForm($form, $form_state);
 }
 /**
  * @covers ::setValue
  */
 public function testSetValue()
 {
     $key = 'FOO';
     $value = 'BAR';
     $this->decoratedFormState->setValue($key, $value)->shouldBeCalled();
     $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValue($key, $value));
 }
Example #10
0
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $cors_domains = $form_state->getValue('cors_domains', '');
     if (empty($cors_domains) && $cors_domains != $form['cors_domains']['#default_value']) {
         $form_state->setErrorByName('cors_domains', t('No domains provided.'));
         return;
     }
     $domains = explode("\r\n", $cors_domains);
     $settings = array();
     $errors = null;
     foreach ($domains as $domain) {
         if (empty($domain)) {
             continue;
         }
         $domain = explode("|", $domain, 2);
         if (empty($domain[0]) || empty($domain[1])) {
             $form_state->setErrorByName('cors_domains', t('Contains malformed entry.'));
             $errors = true;
         } else {
             $settings[$domain[0]] = isset($settings[$domain[0]]) ? $settings[$domain[0]] . ' ' : '';
             $settings[$domain[0]] .= trim($domain[1]);
         }
     }
     if ($settings && !$errors) {
         $form_state->setValue('settings', $settings);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Replace all contiguous whitespaces (including tabs and newlines) with a
     // single plain space.
     $form_state->setValue(['date_format'], trim(preg_replace('/\\s+/', ' ', $form_state->getValue(['date_format']))));
     // Validate the letters used in the scheduler date format. All punctuation
     // is accepted, so remove everything except word characters then check that
     // there is nothing else which is not in the list of acceptable date/time
     // letters.
     $no_punctuation = preg_replace('/[^\\w+]/', '', $form_state->getValue(['date_format']));
     if (preg_match_all('/[^' . SCHEDULER_DATE_LETTERS . SCHEDULER_TIME_LETTERS . ']/', $no_punctuation, $extra)) {
         $form_state->setErrorByName('date_format', $this->t('You may only use the letters $date_letters for the date and $time_letters for the time. Remove the extra characters $extra', ['$date_letters' => SCHEDULER_DATE_LETTERS, '$time_letters' => SCHEDULER_TIME_LETTERS, '$extra' => implode(' ', $extra[0])]));
     }
     // If date-only is enabled then check if a valid default time was entered.
     // Leading zeros and seconds can be omitted, eg. 6:30 is considered valid.
     if ($form_state->getValue(['allow_date_only'])) {
         $default_time = date_parse($form_state->getValue(['default_time']));
         if ($default_time['error_count']) {
             $form_state->setErrorByName('default_time', $this->t('The default time should be in the format HH:MM:SS'));
         } else {
             // Insert any possibly omitted leading zeroes.
             $unix_time = mktime($default_time['hour'], $default_time['minute'], $default_time['second']);
             $form_state->setValue(['default_time'], $this->dateFormatter->format($unix_time, 'custom', 'H:i:s'));
         }
     }
     // Check that either the date format has a time part or the date-only option
     // is turned on.
     $time_format = $this->getTimeOnlyFormat($form_state->getValue(['date_format']));
     if ($time_format == '' && !$form_state->getValue(['allow_date_only'])) {
         $form_state->setErrorByName('date_format', $this->t('You must either include a time within the date format or enable the date-only option.'));
     }
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('aircraft_type') === 'helicopters') {
         drupal_set_message($this->t('Helicopters are just rotorcraft.'), 'warning');
         $form_state->setValue('aircraft_type', 'rotorcraft');
     }
     parent::submitConfigurationForm($form, $form_state);
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $plugin_settings = (new FormState())->setValues($form_state->getValue('key_settings'));
     $plugin = $this->manager->createInstance($form_state->getValue('key_provider'), []);
     $plugin->submitConfigurationForm($form, $plugin_settings);
     $form_state->setValue('key_settings', $plugin->getConfiguration());
     parent::submitForm($form, $form_state);
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function buildEntity(array $form, FormStateInterface $form_state)
 {
     // Save period.
     $type = Schedule::getPeriodType($form_state->getValue('period_type'));
     $seconds = Schedule::periodToSeconds(['number' => $form_state->getValue('period_number'), 'type' => $type]);
     $form_state->setValue('period', $seconds);
     return parent::buildEntity($form, $form_state);
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     if ($form_state->hasValue('date')) {
         $userInput = $form_state->getUserInput();
         $userInput['result'] = 'Date Set';
         $form_state->setUserInput($userInput);
     } else {
         $form_state->setValue('date', date('Y-m-d', REQUEST_TIME));
         $form_state->setValue('result', 'date not set');
         $result = 'Date Not Set';
     }
     $form['ajax_wrapper'] = ['#type' => 'container', '#attributes' => ['id' => 'ajax_wrapper']];
     $form['ajax_wrapper']['date'] = ['#type' => 'date', '#title' => $this->t('Date')];
     $form['ajax_wrapper']['submit_button'] = ['#type' => 'submit', '#value' => 'Load', '#ajax' => ['callback' => [$this, 'ajaxFormCallback']]];
     $form['ajax_wrapper']['result'] = ['#type' => 'textfield', '#title' => $this->t('Result'), '#default_value' => $result];
     return $form;
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if (!($account = User::load($form_state->getValue('userid')))) {
         $form_state->setErrorByName('userid', $this->t('Username not found'));
     } else {
         $form_state->setValue('username', $account->getAccountName());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $file_upload = $this->getRequest()->files->get('files[import_tarball]', NULL, TRUE);
     if ($file_upload && $file_upload->isValid()) {
         $form_state->setValue('import_tarball', $file_upload->getRealPath());
     } else {
         $form_state->setErrorByName('import_tarball', $this->t('The import tarball could not be uploaded.'));
     }
 }
Example #18
0
 public function validateOptionsForm(&$form, FormStateInterface $form_state)
 {
     $role = $form_state->getValue(array('access_options', 'role'));
     $role = array_filter($role);
     if (!$role) {
         $form_state->setError($form['role'], $this->t('You must select at least one role if type is "by role"'));
     }
     $form_state->setValue(array('access_options', 'role'), $role);
 }
 /**
  * {@inheritdoc}
  */
 public function submitExposed(&$form, FormStateInterface $form_state)
 {
     $filter_value = $form_state->getValue($this->options['id']);
     if (empty($filter_value)) {
         // The exposed form is submitted on first view load, even when this
         // filter is hidden. To prevent a notice, a default value is provided.
         $form_state->setValue($this->options['id'], 'All');
     }
 }
Example #20
0
 protected function valueValidate($form, FormStateInterface $form_state)
 {
     $uids = [];
     if ($values = $form_state->getValue(array('options', 'value'))) {
         foreach ($values as $value) {
             $uids[] = $value['target_id'];
         }
         sort($uids);
     }
     $form_state->setValue(array('options', 'value'), $uids);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $all_files = $this->getRequest()->files->get('files', []);
     if (!empty($all_files['import_tarball'])) {
         $file_upload = $all_files['import_tarball'];
         if ($file_upload->isValid()) {
             $form_state->setValue('import_tarball', $file_upload->getRealPath());
             return;
         }
     }
     $form_state->setErrorByName('import_tarball', $this->t('The file could not be uploaded.'));
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     preg_match('#\\((.*?)\\)#', $form_state->getValue('formateur'), $co_resp);
     $form_state->setValue('formateur', $co_resp[1]);
     if (!is_numeric($co_resp[1])) {
         $form_state->setErrorByName('formateur', $this->t('Problème !'));
     }
     preg_match('#\\((.*?)\\)#', $form_state->getValue('lieu'), $co_lieu);
     $form_state->setValue('lieu', $co_lieu[1]);
     if (FALSE) {
         $form_state->setErrorByName('lieu', $this->t('Problème !'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     foreach (array('auto_import', 'auto_export') as $key) {
         $form_state->setValue($key, array_filter(preg_split("/\r\n/", $form_state->getValues()[$key])));
     }
     foreach ($form_state->getValues()['auto_import'] as $file) {
         $name = basename($file, '.' . FileStorage::getFileExtension());
         if (in_array($name, array('system.site', 'core.extension', 'simpletest.settings'))) {
             $form_state->setErrorByName('auto_import', $this->t('@name is not compatible with this module', array('@name' => $name)));
         }
     }
     parent::validateForm($form, $form_state);
 }
 public function submitRowForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     // Create an array of just the provider values
     $consumer_mappings = array();
     foreach ($values as $key => $value) {
         $consumer_mappings[] = $value['consumer_mappings'];
     }
     // Nuke our form_state leaving just the mapping
     // $form_state->setValues(array('consumer_mappings' => $consumer_mappings));
     $form_state->setValue('consumer_mappings', $consumer_mappings);
     parent::submitRowForm($form, $form_state);
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $user_id = $form_state->getValue('masquerade_as');
     if (empty($user_id)) {
         $form_state->setErrorByName('masquerade_as', $this->t('The user does not exist. Please enter a valid username.'));
         return;
     }
     $target_account = $this->entityManager->getStorage('user')->load($user_id);
     if ($error = masquerade_switch_user_validate($target_account)) {
         $form_state->setErrorByName('masquerade_as', $error);
     } else {
         $form_state->setValue('masquerade_target_account', $target_account);
     }
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config('simpletest.settings');
     // If a username was provided but a password wasn't, preserve the existing
     // password.
     if (!$form_state->isValueEmpty('simpletest_httpauth_username') && $form_state->isValueEmpty('simpletest_httpauth_password')) {
         $form_state->setValue('simpletest_httpauth_password', $config->get('httpauth.password'));
     }
     // If a password was provided but a username wasn't, the credentials are
     // incorrect, so throw an error.
     if ($form_state->isValueEmpty('simpletest_httpauth_username') && !$form_state->isValueEmpty('simpletest_httpauth_password')) {
         $form_state->setErrorByName('simpletest_httpauth_username', $this->t('HTTP authentication credentials must include a username in addition to a password.'));
     }
     parent::validateForm($form, $form_state);
 }
  protected function validatePdfUpload(array &$form, FormStateInterface &$form_state, UploadedFile $file_upload, $file_field_name) {
    /**
     * @var $file_upload \Symfony\Component\HttpFoundation\File\UploadedFile
     */
    if ($file_upload && $file_upload->isValid()) {
      // Move it to somewhere we know.
      $uploaded_filename = $file_upload->getClientOriginalName();

      // Ensure the destination is unique; we deliberately use managed files,
      // but they are keyed on file URI, so we can't save the same one twice.
      $scheme = $this->config('fillpdf.settings')->get('scheme');
      $destination = file_destination(FillPdf::buildFileUri($scheme, 'fillpdf/' . $uploaded_filename), FILE_EXISTS_RENAME);

      // Ensure our directory exists.
      $fillpdf_directory = FillPdf::buildFileUri($scheme, 'fillpdf');
      $directory_exists = file_prepare_directory($fillpdf_directory, FILE_CREATE_DIRECTORY + FILE_MODIFY_PERMISSIONS);

      if ($directory_exists) {
        $file_moved = $this->fileSystem->moveUploadedFile($file_upload->getRealPath(), $destination);

        if ($file_moved) {
          // Create a File object from the uploaded file.
          $new_file = File::create([
            'uri' => $destination,
            'uid' => $this->currentUser()->id(),
          ]);

          $errors = file_validate_extensions($new_file, 'pdf');

          if (count($errors)) {
            $form_state->setErrorByName('upload_pdf', $this->t('Only PDF files are supported, and they must end in .pdf.'));
          }
          else {
            $form_state->setValue('upload_pdf', $new_file);
          }
        }
        else {
          $form_state->setErrorByName('upload_pdf', $this->t("Could not move your uploaded file from PHP's temporary location to Drupal file storage."));
        }
      }
      else {
        $form_state->setErrorByName('upload_pdf', $this->t('Could not automatically create the <em>fillpdf</em> subdirectory. Please create this manually before uploading your PDF form.'));
      }
    }
    else {
      $form_state->setErrorByName('upload_pdf', $this->t('Your PDF could not be uploaded. Did you select one?'));
    }
  }
Example #28
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $value = $form_state->getValue('new');
     // try to parse the new provided value
     try {
         $parsed_value = Yaml::decode($value);
         // Config::setData needs array for the new configuration and
         // a simple string is valid YAML for any reason.
         if (is_array($parsed_value)) {
             $form_state->setValue('parsed_value', $parsed_value);
         } else {
             $form_state->setErrorByName('new', $this->t('Invalid input'));
         }
     } catch (InvalidDataTypeException $e) {
         $form_state->setErrorByName('new', $this->t('Invalid input: %error', array('%error' => $e->getMessage())));
     }
 }
Example #29
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $account = $this->entity;
     $pass = $account->getPassword();
     $admin = $form_state->getValue('administer_users');
     $notify = !$form_state->isValueEmpty('notify');
     // Save has no return value so this cannot be tested.
     // Assume save has gone through correctly.
     $account->save();
     $form_state->set('user', $account);
     $form_state->setValue('uid', $account->id());
     $this->logger('user')->notice('New user: %name %email.', array('%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => $account->link($this->t('Edit'), 'edit-form')));
     // Add plain text password into user account to generate mail tokens.
     $account->password = $pass;
     // New administrative account without notification.
     if ($admin && !$notify) {
         drupal_set_message($this->t('Created a new user account for <a href=":url">%name</a>. No email has been sent.', array(':url' => $account->url(), '%name' => $account->getUsername())));
     } elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) {
         _user_mail_notify('register_no_approval_required', $account);
         user_login_finalize($account);
         drupal_set_message($this->t('Registration successful. You are now logged in.'));
         $form_state->setRedirect('<front>');
     } elseif ($account->isActive() || $notify) {
         if (!$account->getEmail() && $notify) {
             drupal_set_message($this->t('The new user <a href=":url">%name</a> was created without an email address, so no welcome message was sent.', array(':url' => $account->url(), '%name' => $account->getUsername())));
         } else {
             $op = $notify ? 'register_admin_created' : 'register_no_approval_required';
             if (_user_mail_notify($op, $account)) {
                 if ($notify) {
                     drupal_set_message($this->t('A welcome message with further instructions has been emailed to the new user <a href=":url">%name</a>.', array(':url' => $account->url(), '%name' => $account->getUsername())));
                 } else {
                     drupal_set_message($this->t('A welcome message with further instructions has been sent to your email address.'));
                     $form_state->setRedirect('<front>');
                 }
             }
         }
     } else {
         _user_mail_notify('register_pending_approval', $account);
         drupal_set_message($this->t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, a welcome message with further instructions has been sent to your email address.'));
         $form_state->setRedirect('<front>');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $trigger = $form_state->getTriggeringElement();
     switch ($trigger['#name']) {
         case 'encrypt':
             if ($to_encrypt = $form_state->getValue('to_encrypt')) {
                 $encrypted_text = $this->encryptService->encrypt($to_encrypt, $this->entity);
                 if ($form_state->getValue('encrypt_base64')) {
                     $encrypted_text = base64_encode($encrypted_text);
                 }
                 $form_state->setValue('encrypted', $encrypted_text);
             }
             break;
         case 'decrypt':
             if ($to_decrypt = $form_state->getValue('to_decrypt')) {
                 if ($form_state->getValue('decrypt_base64')) {
                     $to_decrypt = base64_decode($to_decrypt);
                 }
                 $decrypted_text = $this->encryptService->decrypt($to_decrypt, $this->entity);
                 $form_state->setValue('decrypted', $decrypted_text);
             }
             break;
     }
     $form_state->setRebuild();
 }