You are here

public function KeyInputBase::processSubmittedKeyValue in Key 8

Process a submitted key value.

Parameters

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

Return value

array The submitted value (with index "submitted") and the processed value (with index "processed_submitted").

Overrides KeyInputInterface::processSubmittedKeyValue

2 methods override KeyInputBase::processSubmittedKeyValue()
GenerateKeyInput::processSubmittedKeyValue in src/Plugin/KeyInput/GenerateKeyInput.php
Process a submitted key value.
NoneKeyInput::processSubmittedKeyValue in src/Plugin/KeyInput/NoneKeyInput.php
Process a submitted key value.

File

src/Plugin/KeyInputBase.php, line 28

Class

KeyInputBase
Defines a base class for Key Type plugins.

Namespace

Drupal\key\Plugin

Code

public function processSubmittedKeyValue(FormStateInterface $form_state) {

  // This is the default behavior. If a field named 'key_value' exists in
  // the key input settings, remove it from the settings and return it as
  // the submitted value. If the key value is Base64-encoded, decode it and
  // return the result as the processed_submitted value. Input plugins can
  // override this behavior to perform more complex processing.
  $processed_values = [
    'submitted' => NULL,
    'processed_submitted' => NULL,
  ];
  $key_input_settings = $form_state
    ->getValues();
  $key_value_data = $form_state
    ->get('key_value');
  if (isset($key_input_settings['key_value'])) {

    // If the submitted key value is not empty and equal to the obscured
    // value.
    if (!empty($key_input_settings['key_value']) && $key_input_settings['key_value'] == $key_value_data['obscured']) {

      // Use the processed original value as the submitted value.
      $processed_values['submitted'] = $key_value_data['processed_original'];
    }
    else {
      $processed_values['submitted'] = $key_input_settings['key_value'];
    }
    if (isset($key_input_settings['base64_encoded']) && $key_input_settings['base64_encoded'] == TRUE) {
      $processed_values['processed_submitted'] = base64_decode($processed_values['submitted']);
    }
    else {
      $processed_values['processed_submitted'] = $processed_values['submitted'];
    }
    unset($key_input_settings['key_value']);
    $form_state
      ->setValues($key_input_settings);
  }
  return $processed_values;
}