class PhraseCaptchaSettingsForm in CAPTCHA Pack 8
Administration form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\phrase_captcha\Form\PhraseCaptchaSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of PhraseCaptchaSettingsForm
1 string reference to 'PhraseCaptchaSettingsForm'
- phrase_captcha.routing.yml in text_captcha/
modules/ phrase_captcha/ phrase_captcha.routing.yml - text_captcha/modules/phrase_captcha/phrase_captcha.routing.yml
File
- text_captcha/
modules/ phrase_captcha/ src/ Form/ PhraseCaptchaSettingsForm.php, line 12
Namespace
Drupal\phrase_captcha\FormView source
class PhraseCaptchaSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'phrase_captcha_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'phrase_captcha.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('phrase_captcha.settings');
drupal_set_message($this
->t('WARNING: this module is not completely ported to Drupal 8 and does not work yet.'), 'warning');
// Radio buttons for selecting the kind of words to use.
$form['phrase_captcha_words'] = [
'#type' => 'radios',
'#title' => $this
->t('Kind of words to use in the CAPTCHA phrase'),
'#options' => [
PHRASE_CAPTCHA_GENERATE_NONSENSE_WORDS => $this
->t('Generate nonsense words'),
PHRASE_CAPTCHA_USER_DEFINED_WORDS => $this
->t('Use user defined words'),
],
'#default_value' => $config
->get('phrase_captcha_words'),
'#required' => TRUE,
];
// Form elements for the word pools.
_text_captcha_word_pool_form_items($form, 'phrase_captcha_userdefined_word_pool', 'User defined word pool', 'Enter the words to use in the CAPTCHA phrase (space separated, no punctuation).', '');
// Select form element for the number of words in the CAPTCHA phrase.
$form['phrase_captcha_word_quantity'] = [
'#type' => 'select',
'#title' => $this
->t('Number of words in the CAPTCHA phrase'),
'#default_value' => $config
->get('phrase_captcha_word_quantity'),
'#options' => array_combine([
4,
5,
6,
7,
8,
9,
10,
], [
4,
5,
6,
7,
8,
9,
10,
]),
'#required' => TRUE,
];
// Select form element for the number of additional words.
$form['phrase_captcha_additional_word_quantity'] = [
'#type' => 'select',
'#title' => $this
->t('Maximum number of additional words to let the user choose from'),
'#default_value' => $config
->get('phrase_captcha_additional_word_quantity'),
'#options' => array_combine([
0,
1,
2,
3,
4,
5,
], [
0,
1,
2,
3,
4,
5,
]),
'#required' => TRUE,
];
$form['phrase_captcha_word_selection_challenges'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Word selection challenges'),
'#options' => _phrase_captcha_available_word_challenges(),
'#default_value' => _phrase_captcha_enabled_word_challenges(),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('phrase_captcha.settings');
$config
->set('phrase_captcha_word_selection_challenges', $form_state
->getValue('phrase_captcha_word_selection_challenges'))
->set('phrase_captcha_additional_word_quantity', $form_state
->getValue('phrase_captcha_additional_word_quantity'))
->set('phrase_captcha_word_quantity', $form_state
->getValue('phrase_captcha_word_quantity'));
foreach ($form_state
->getValues() as $label => $value) {
if (strpos($label, 'phrase_captcha_userdefined_word_pool') !== FALSE) {
$config
->set($label, $value);
}
}
$config
->save();
parent::SubmitForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getValue('phrase_captcha_words') == PHRASE_CAPTCHA_USER_DEFINED_WORDS) {
$word_count_minimum = $form_state
->getValue('phrase_captcha_word_quantity') + $form_state
->getValue('phrase_captcha_additional_word_quantity') + 2;
_text_captcha_word_pool_validate('phrase_captcha_userdefined_word_pool', $form_state, $word_count_minimum, NULL, NULL);
}
// Check word selection.
if (count(array_filter($form_state
->getValue('phrase_captcha_word_selection_challenges'))) < 1) {
$form_state
->setErrorByName('phrase_captcha_word_selection_challenges', $this
->t('You need to select at least one word selection criterium'));
}
parent::validateForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PhraseCaptchaSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
PhraseCaptchaSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
PhraseCaptchaSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
PhraseCaptchaSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PhraseCaptchaSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
PhraseCaptchaSettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |