You are here

function _key_set_key_value_data in Key 7.3

Set the key value data.

Parameters

array $config: The key configuration.

Return value

array The key value data.

1 call to _key_set_key_value_data()
key_config_form in includes/key.admin.inc
Form constructor for the key configuration form.

File

includes/key.admin.inc, line 526
Administrative functionality for managing key configurations.

Code

function _key_set_key_value_data($config = array()) {
  $key_value_data = array(
    'original' => NULL,
    'processed_original' => NULL,
    'obscured' => NULL,
    'current' => '',
  );

  // If this is a new key being added, return the defaults.
  if (empty($config['id'])) {
    return $key_value_data;
  }
  $key_type = key_get_plugin('key_type', $config['key_type']);
  $key_provider = key_get_plugin('key_provider', $config['key_provider']);
  $key_input = key_get_plugin('key_input', $config['key_input']);
  $obscure_options = array();

  // Add settings from plugins.
  $obscure_options['key_type_id'] = $key_type['name'];
  $obscure_options['key_type_group'] = $key_type['group'];
  $obscure_options['key_provider_id'] = $key_provider['name'];
  $key_value = array();

  // Get the existing key value.
  $key_value['original'] = key_get_key_value($config['id']);

  // Process the original key value.
  if ($process_function = ctools_plugin_get_function($key_input, 'process existing key value')) {
    $key_value['processed_original'] = $process_function($config['key_input_settings'], $key_value['original']);
  }
  else {
    $key_value['processed_original'] = $key_value['original'];
  }

  // Obscure the processed key value.
  if ($obscured_function = ctools_plugin_get_function($key_provider, 'obscure key value')) {
    $obscured_key_value = $obscured_function($key_value['processed_original'], $obscure_options);
  }
  else {
    $obscured_key_value = $key_value['processed_original'];
  }
  if ($obscured_key_value != $key_value['processed_original']) {
    $key_value['obscured'] = $obscured_key_value;
  }
  else {
    $key_value['obscured'] = '';
  }

  // Set the current value.
  $key_value['current'] = !empty($key_value['obscured']) ? $key_value['obscured'] : $key_value['processed_original'];
  return $key_value;
}