TextFieldKeyInput.php in Key 8
File
src/Plugin/KeyInput/TextFieldKeyInput.php
View source
<?php
namespace Drupal\key\Plugin\KeyInput;
use Drupal\Core\Form\FormStateInterface;
use Drupal\key\Plugin\KeyInputBase;
class TextFieldKeyInput extends KeyInputBase {
public function defaultConfiguration() {
return [
'key_value' => '',
'base64_encoded' => FALSE,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$key_value_data = $form_state
->get('key_value');
$key = $form_state
->getFormObject()
->getEntity();
$form['key_value'] = [
'#type' => 'textfield',
'#title' => $this
->t('Key value'),
'#required' => $key
->getKeyProvider()
->getPluginDefinition()['key_value']['required'],
'#maxlength' => 4096,
'#default_value' => $key_value_data['current'],
'#attributes' => [
'autocomplete' => 'off',
],
];
if ($key
->getKeyType()
->getPluginDefinition()['group'] == 'encryption') {
$form['base64_encoded'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Base64-encoded'),
'#description' => $this
->t('Check this if the key value being submitted has been Base64-encoded.'),
'#default_value' => $this
->getConfiguration()['base64_encoded'],
];
}
return $form;
}
}