You are here

function key_input_generate_process_submitted_key_value in Key 7.3

Generate a key value using the selected key type settings.

Return value

array

  • 'submitted': The original submitted value.
  • 'processed_submitted': The processed value.
1 string reference to 'key_input_generate_process_submitted_key_value'
generate.inc in plugins/key_input/generate.inc

File

plugins/key_input/generate.inc, line 81

Code

function key_input_generate_process_submitted_key_value(&$form_state) {
  $key_input_settings = $form_state['values'];
  $key_value_data = $form_state['storage']['key_value'];
  $config = $form_state['storage']['key_config'];

  // If the key value has already been generated, use the existing value.
  // Otherwise, generate a key.
  if ($key_input_settings['generated']) {
    $processed_values = array(
      'submitted' => $key_value_data['current'],
      'processed_submitted' => $key_value_data['current'],
    );
  }
  else {
    $key_type = key_get_plugin('key_type', $config['key_type']);
    $generate_function = ctools_plugin_get_function($key_type, 'generate key value');
    $key_value = $generate_function($config);
    $form_state['values']['generated'] = TRUE;
    $processed_values = array(
      'submitted' => $key_value,
      'processed_submitted' => $key_value,
    );

    // If the user requested to display the generated password.
    if ($key_input_settings['display_once']) {
      drupal_set_message(t('A key value of the requested type has been generated and is displayed below as a Base64-encoded string. You will need to decode it to get the actual key value, which may or may not be human-readable. The key value will not be displayed again, so take note of it now, if necessary.<br>%key_value', array(
        '%key_value' => base64_encode($key_value),
      )), $type = 'status');
    }
  }
  return $processed_values;
}