Skip to content
Snippets Groups Projects
Commit 58b196e5 authored by Viktor Holovachek's avatar Viktor Holovachek
Browse files

Issue #3500158 - Allow users to bypass

parent 6b5583b8
No related branches found
Tags 7.x-5.7
1 merge request!23Issue #3500158 - Allow users to bypass
Pipeline #403868 passed with warnings
manage fapi validation settings:
title: 'Manage fapi validation settings'
description: 'Allows a user to manage fapi validation settings.'
fapi_validation.settings:
path: '/admin/config/system/fapi'
defaults:
_form: '\Drupal\fapi_validation\Form\FapiValidationForm'
_title: 'Form API Validation settings'
requirements:
_permission: 'manage fapi validation settings'
<?php
namespace Drupal\fapi_validation\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Form handler for adding fapi validation settings.
*/
class FapiValidationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'fapi_validation_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'fapi_validation.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->configFactory->getEditable('fapi_validation.settings');
$form['bypass'] = [
'#type' => 'checkbox',
'#title' => $this->t('Bypass validations'),
'#description' => $this->t('Allows a user to bypass Form API validations by having the required permission.'),
'#default_value' => $config->get('bypass') ?? FALSE,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory->getEditable('fapi_validation.settings')
->set('bypass', (bool) $form_state->getValue('bypass'))
->save();
parent::submitForm($form, $form_state);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment