You are here

public function UeditorGlobalSettingsForm::submitForm in UEditor - 百度编辑器 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/UeditorGlobalSettingsForm.php, line 215
Contains \Drupal\ueditor\Form\UeditorGlobalSettingsForm.

Class

UeditorGlobalSettingsForm

Namespace

Drupal\ueditor\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Set & save the configuration : get the $config object.
  $config = $this
    ->config('ueditor.settings');
  $values = $form_state
    ->getValues();
  if (file_exists('modules/ueditor/lib/kityformula-plugin/kityformula/js/kityformula-editor.all.min.js')) {
    $kityformula_installed = TRUE;
  }
  else {
    $kityformula_installed = FALSE;
  }
  if ($values['enable_formula_editor'] == 1) {
    if (!$kityformula_installed) {
      $this
        ->messenger()
        ->addError(t('Please install the @kityformula_link library at first, and the place should be like this: <i>modules/ueditor/lib/kityformula-plugin/kityformula/js/kityformula-editor.all.min.js</i>', [
        '@kityformula_link' => Link::fromTextAndUrl(t('KityFormula'), Url::fromUri('http://ueditor.baidu.com/download/kityformula-plugin.zip'))
          ->toString(),
      ]));
    }
    else {
      $config
        ->set('ueditor_global_settings.ueditor_enable_formula_editor', $values['enable_formula_editor']);
    }
  }
  if (!empty($values['watermark_upload'])) {
    $filename = file_unmanaged_copy($values['watermark_upload']
      ->getFileUri(), NULL, FileSystemInterface::EXISTS_REPLACE);
    $values['watermark_path'] = $filename;
  }
  unset($values['watermark_upload']);
  if (!empty($values['watermark_path'])) {
    $values['watermark_path'] = $this
      ->validatePath($values['watermark_path']);
  }
  $config
    ->set('ueditor_global_settings.ueditor_highlighting_format', $values['highlighting_format']);
  $config
    ->set('ueditor_global_settings.ueditor_watermark', $values['watermark']);
  $config
    ->set('ueditor_global_settings.ueditor_watermark_type', $values['watermark_type']);
  $config
    ->set('ueditor_global_settings.ueditor_watermark_path', $values['watermark_path']);
  $config
    ->set('ueditor_global_settings.ueditor_watermark_alpha', $values['watermark_alpha']);
  $config
    ->set('ueditor_global_settings.ueditor_watermark_textcontent', $values['watermark_textcontent']);
  $config
    ->set('ueditor_global_settings.ueditor_watermark_textfontsize', $values['watermark_textfontsize']);
  $config
    ->set('ueditor_global_settings.ueditor_watermark_textcolor', $values['watermark_textcolor']);
  $config
    ->set('ueditor_global_settings.ueditor_watermark_place', $values['watermark_place']);
  $config
    ->set('ueditor_global_settings.ueditor_image_maxsize', $values['image_size']);
  $config
    ->set('ueditor_global_settings.ueditor_file_maxsize', $values['file_size']);
  $config
    ->set('ueditor_global_settings.ueditor_video_maxsize', $values['video_size']);
  $config
    ->save();
}