CkeditorConfigForm.php in CKEditor custom config 8
File
src/Form/CkeditorConfigForm.php
View source
<?php
namespace Drupal\ckeditor_config\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class CkeditorConfigForm extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'ckeditor_config.config_form',
];
}
public function getFormId() {
return 'ckeditor_config_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('ckeditor_config.config_form');
$form['config'] = [
'#type' => 'textarea',
'#title' => $this
->t('CKEditor Custom Configuration'),
'#description' => $this
->t("Each row is configuration set in format key=value. Don't use quotes for string values."),
'#default_value' => $config
->get('config'),
];
$manualText = "<code>\n format_tags=p;h2;h4<br>\n language = de<br>\n forcePasteAsPlainText = true<br>\n uiColor = #AADC6E</code>";
$form['manual'] = [
'#prefix' => '<h3>' . $this
->t('Example') . '</h3>',
'#markup' => '<p>' . $manualText . '</p>',
];
$reference_url = 'https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.config';
$form['reference'] = [
'#prefix' => '<h3>CKEditor reference</h3>',
'#markup' => '<p>' . $this
->t('For more information, visit CKEditor config reference <a href=":reference">@reference</a>', [
':reference' => $reference_url,
'@reference' => $reference_url,
]) . '</p>',
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('ckeditor_config.config_form')
->set('config', $form_state
->getValue('config'))
->save();
}
}