JstimerAdminSettings.php in Javascript Timer 8
File
src/Form/JstimerAdminSettings.php
View source
<?php
namespace Drupal\jstimer\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
class JstimerAdminSettings extends ConfigFormBase {
public function getFormId() {
return 'jstimer_admin_settings';
}
protected function getEditableConfigNames() {
return [
'jstimer.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->configFactory
->get('jstimer.settings');
$form = [];
$form = parent::buildForm($form, $form_state);
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->configFactory
->getEditable('jstimer.settings');
$config
->save();
if (method_exists($this, '_submitForm')) {
$this
->_submitForm($form, $form_state);
}
parent::submitForm($form, $form_state);
}
public function validateForm(array &$form, FormStateInterface $form_state) {
foreach ($form_state
->getValues() as $key => $value) {
if (substr($key, 0, 11) == "jstimer_js_") {
if (!strpos($value, "'") === FALSE) {
$form_state
->setErrorByName($key, $this
->t("Javascript Timer admin settings may not contain single quotes(')."));
}
}
}
}
public function _submitForm(array &$form, FormStateInterface $form_state) {
jstimer_build_js_cache();
drupal_clear_js_cache();
}
}