You are here

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

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

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

Class

UeditorGlobalSettingsForm

Namespace

Drupal\ueditor\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // This is how you call a $config object to get all the settings of your module calling module_name.settings.
  $config = $this
    ->config('ueditor.settings');
  $form['global']['highlighting_format'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable Highlighting Code Format'),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_highlighting_format'),
    '#description' => t('If enabled, when you insert code, the code will highlighting.'),
  );
  $form['global']['enable_formula_editor'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable Formula in ueditor'),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_enable_formula_editor'),
    '#description' => $this
      ->t('If you want to use KityFormula in the ueditor, you must 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(),
    ]),
  );

  //ueditor watermark support
  $form['global']['watermark'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use watermark when upload'),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_watermark'),
    '#tree' => FALSE,
    '#description' => $this
      ->t('Check here if you want use watermark when upload.'),
  );
  $form['global']['watermark_settings'] = array(
    '#type' => 'container',
    '#states' => array(
      'invisible' => array(
        'input[name="watermark"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['global']['watermark_settings']['watermark_type'] = array(
    '#type' => 'select',
    '#title' => 'The type of watermark',
    '#options' => array(
      'image' => 'Image',
      'text' => 'Text',
    ),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_watermark_type'),
  );
  $form['global']['watermark_settings']['watermark_image'] = array(
    '#type' => 'container',
    '#states' => array(
      'invisible' => array(
        '#edit-watermark-type' => array(
          'value' => 'text',
        ),
      ),
    ),
  );
  $form['global']['watermark_settings']['watermark_image']['watermark_path'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Path to custom watermark'),
    '#description' => $this
      ->t('The path to the file you would like to use as watermark image.'),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_watermark_path'),
  );
  $validators = array(
    'file_validate_extensions' => array(
      'jpg png',
    ),
    'file_validate_size' => array(
      Environment::getUploadMaxSize(),
    ),
  );
  $form['global']['watermark_settings']['watermark_image']['watermark_upload'] = array(
    '#type' => 'file',
    '#title' => $this
      ->t('Upload watermark image'),
    '#size' => 50,
    '#upload_validators' => $validators,
    '#description' => $this
      ->t("If you don't have direct file access to the server, use this field to upload watermark image.only support : jpg png"),
  );
  $form['global']['watermark_settings']['watermark_image']['watermark_alpha'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Watermark Alpha'),
    '#options' => array_combine(array(
      30,
      50,
      80,
      100,
    ), array(
      30,
      50,
      80,
      100,
    )),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_watermark_alpha'),
  );
  $form['global']['watermark_settings']['watermark_text'] = array(
    '#type' => 'container',
    '#states' => array(
      'invisible' => array(
        '#edit-watermark-type' => array(
          'value' => 'image',
        ),
      ),
    ),
  );
  $form['global']['watermark_settings']['watermark_text']['watermark_textcontent'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Watermark Text'),
    '#description' => $this
      ->t('The path to the file you would like to use as watermark image.'),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_watermark_textcontent'),
  );
  $form['global']['watermark_settings']['watermark_text']['watermark_textfontsize'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Watermark Text Font Size'),
    '#options' => array_combine(array(
      12,
      16,
      18,
      24,
      36,
      48,
      60,
    ), array(
      12,
      16,
      18,
      24,
      36,
      48,
      60,
    )),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_watermark_textfontsize'),
  );
  $form['global']['watermark_settings']['watermark_text']['watermark_textcolor'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Watermark Text Color'),
    '#description' => $this
      ->t('The path to the file you would like to use as watermark image.'),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_watermark_textcolor'),
  );
  $form['global']['watermark_settings']['watermark_place'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Watermark Place'),
    '#options' => array(
      '0' => 'Random',
      '1' => 'Top Left',
      '2' => 'Top Center',
      '3' => 'Top Right',
      '4' => 'Middle Left',
      '5' => 'Middle Center',
      '6' => 'Middle Right',
      '7' => 'Bottom Left',
      '8' => 'Bottom Center',
      '9' => 'Bottom Right',
    ),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_watermark_place'),
  );

  //file/image/video upload max size
  $form['maxsize']['image_size'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Image upload size'),
    '#description' => $this
      ->t('The maxsize of upload image. unit: KB'),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_image_maxsize'),
  );
  $form['maxsize']['file_size'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('File upload size'),
    '#description' => $this
      ->t('The maxsize of upload file. unit: KB'),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_file_maxsize'),
  );
  $form['maxsize']['video_size'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Video upload size'),
    '#description' => $this
      ->t('The maxsize of upload video. unit: KB'),
    '#default_value' => $config
      ->get('ueditor_global_settings.ueditor_video_maxsize'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#button_type' => 'primary',
  );
  return $form;
}