Repository URL to install this package:
|
Version:
1.48.1 ▾
|
<?php
namespace Drupal\customeredit\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\customeredit_pages\CustomerPagesBuilder;
use Drupal\node\Entity\NodeType;
class TextsSettingsForm extends ConfigFormBase {
public function getFormId() {
return 'TextsSettingsForm';
}
protected function getEditableConfigNames() {
return [
'customeredit.texts.settings'
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('customeredit.texts.settings');
$options = [];
foreach(filter_formats() as $id => $format) {
$options[$id] = $format->label();
}
$form['text_format'] = array(
'#type' => 'select',
'#title' => $this->t('Text format'),
'#description' => $this->t(''),
'#options' => $options,
'#default_value' => $config->get('text_format') ?: "full_html"
);
return parent::buildform($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$discarded = array(
'submit',
'form_build_id',
'form_token',
'form_id',
'op'
);
$config = $this->config('customeredit.texts.settings');
foreach ($form_state->getValues() as $key => $value) {
if (!in_array($key, $discarded)) {
$config->set($key, $value);
}
}
$config->save();
parent::submitForm($form, $form_state);
/** @var CustomerPagesBuilder $builder */
$builder = \Drupal::service('customeredit.texts.builder');
$builder->rebuild();
}
}