class ClientsideValidationjQuerySettingsForm in Clientside Validation 8
Same name and namespace in other branches
- 8.2 clientside_validation_jquery/src/Form/ClientsideValidationjQuerySettingsForm.php \Drupal\clientside_validation_jquery\Form\ClientsideValidationjQuerySettingsForm
- 3.0.x clientside_validation_jquery/src/Form/ClientsideValidationjQuerySettingsForm.php \Drupal\clientside_validation_jquery\Form\ClientsideValidationjQuerySettingsForm
- 2.0.x clientside_validation_jquery/src/Form/ClientsideValidationjQuerySettingsForm.php \Drupal\clientside_validation_jquery\Form\ClientsideValidationjQuerySettingsForm
Class ClientsideValidationjQuerySettingsForm.
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\clientside_validation_jquery\Form\ClientsideValidationjQuerySettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of ClientsideValidationjQuerySettingsForm
1 string reference to 'ClientsideValidationjQuerySettingsForm'
- clientside_validation_jquery.routing.yml in clientside_validation_jquery/
clientside_validation_jquery.routing.yml - clientside_validation_jquery/clientside_validation_jquery.routing.yml
File
- clientside_validation_jquery/
src/ Form/ ClientsideValidationjQuerySettingsForm.php, line 11
Namespace
Drupal\clientside_validation_jquery\FormView source
class ClientsideValidationjQuerySettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'clientside_validation_jquery_settings_form';
}
/**
* {@inheritdoc}
*/
public function getEditableConfigNames() {
return [
'clientside_validation_jquery.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('clientside_validation_jquery.settings');
$form['use_cdn'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use JS from CDN'),
'#description' => $this
->t('CDN is used by default if JS not added into libraries.'),
'#default_value' => $config
->get('use_cdn'),
];
$form['cdn_base_url'] = [
'#type' => 'textfield',
'#title' => $this
->t('CDN Base URL'),
'#description' => $this
->t('CDN to use (along with version in URL). E.g. @url', [
'@url' => '//cdn.jsdelivr.net/npm/jquery-validation@1.17.0/dist/',
]),
'#required' => TRUE,
'#default_value' => $config
->get('cdn_base_url'),
];
$form['validate_all_ajax_forms'] = [
'#type' => 'select',
'#options' => [
1 => $this
->t('Yes'),
2 => $this
->t('No'),
],
'#title' => $this
->t('Validate all forms before AJAX submit'),
'#description' => $this
->t('All forms with class "cv-validate-before-ajax" will be validated by default'),
'#required' => TRUE,
'#default_value' => $config
->get('validate_all_ajax_forms'),
];
$form['force_validate_on_blur'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Validate on Blur/focusout'),
'#default_value' => $config
->get('force_validate_on_blur'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('clientside_validation_jquery.settings');
$config
->set('use_cdn', $form_state
->getValue('use_cdn'));
$config
->set('cdn_base_url', $form_state
->getValue('cdn_base_url'));
$config
->set('validate_all_ajax_forms', $form_state
->getValue('validate_all_ajax_forms'));
$config
->set('force_validate_on_blur', $form_state
->getValue('force_validate_on_blur'));
$config
->save();
return parent::submitForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
if ($form_state
->getErrors()) {
return;
}
$values = $form_state
->getValues();
// Validate if library exists if use CDN is set to false.
if (empty($values['use_cdn'])) {
$library_exists = file_exists('libraries/jqueryvalidate/dist/jquery.validate.js');
if (empty($library_exists)) {
$form_state
->setErrorByName('use_cdn', $this
->t('Please make sure JS is available in Drupal Libraries. Check README in module folder for more details.'));
}
}
// Validate if the CDN url is proper.
$cdn_url = $values['cdn_base_url'] . 'jquery.validate.min.js';
if (file_get_contents($cdn_url) === FALSE) {
$form_state
->setErrorByName('cdn_base_url', $this
->t('CDN URL seems invalid. @file not accessible on @url. Use the URL in this format @format.', [
'@file' => 'jquery.validate.min.js',
'@url' => $cdn_url,
'@format' => '//cdn.jsdelivr.net/npm/jquery-validation@1.17.0/dist/',
]));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientsideValidationjQuerySettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
ClientsideValidationjQuerySettingsForm:: |
public | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
ClientsideValidationjQuerySettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ClientsideValidationjQuerySettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
ClientsideValidationjQuerySettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
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. | |
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. |