AdminSettings.php in jEditable inline content editing 8
File
src/Form/AdminSettings.php
View source
<?php
namespace Drupal\jeditable\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
class AdminSettings extends ConfigFormBase {
public function getFormId() {
return 'jeditable_admin_settings';
}
protected function getEditableConfigNames() {
return [
'jeditable.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['jeditable_empty_placeholder'] = [
'#type' => 'textfield',
'#title' => $this
->t('Empty field placeholder'),
'#default_value' => $this
->config('jeditable.settings')
->get('jeditable_empty_placeholder'),
'#description' => $this
->t('Text, that will be shown if field is empty'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('jeditable.settings');
foreach (Element::children($form) as $variable) {
$config
->set($variable, $form_state
->getValue($form[$variable]['#parents']));
}
$config
->save();
if (method_exists($this, '_submitForm')) {
$this
->_submitForm($form, $form_state);
}
parent::submitForm($form, $form_state);
}
}