You are here

public function SettingsForm::buildForm in Textimage 8.4

Same name and namespace in other branches
  1. 8.3 src/Form/SettingsForm.php \Drupal\textimage\Form\SettingsForm::buildForm()

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/SettingsForm.php, line 87

Class

SettingsForm
Main Textimage settings admin form.

Namespace

Drupal\textimage\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('textimage.settings');
  $form['settings'] = [
    '#type' => 'container',
    '#tree' => TRUE,
    '#attributes' => [
      'id' => 'textimage-settings-main',
    ],
  ];

  // Main part of settings form.
  $form['settings']['main'] = [
    '#type' => 'details',
    '#open' => TRUE,
    '#title' => $this
      ->t('Main settings'),
  ];

  // Default image file format/extension.
  $extensions = $this->imageFactory
    ->getSupportedExtensions();
  $options = array_combine($extensions, $extensions);
  $form['settings']['main']['default_extension'] = [
    '#type' => 'select',
    '#options' => $options,
    '#title' => $this
      ->t('Default image file extension'),
    '#default_value' => $config
      ->get('default_extension'),
    '#required' => TRUE,
    '#description' => $this
      ->t('Select the default extension of the image files produced by Textimage. This can be overridden by image style effects that specify a format conversion like e.g. <em>Convert</em>. This setting does not affect image derivatives created by the Image module.'),
  ];

  // Default font.
  $font_plugin = $this->fontManager
    ->getPlugin($this
    ->config('image_effects.settings')
    ->get('font_selector.plugin_id'));
  $form['settings']['main']['default_font_uri'] = $font_plugin
    ->selectionElement([
    '#title' => $this
      ->t('Default font'),
    '#description' => $this
      ->t('Select the default font to be used by Textimage.'),
    '#default_value' => $config
      ->get('default_font.uri'),
  ]);

  // URL generation.
  $form['settings']['url_generation'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('URL generation'),
    '#open' => TRUE,
  ];
  $form['settings']['url_generation']['enabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enabled'),
    '#description' => $this
      ->t("When selected, direct generation of Textimage images is enabled for users having the 'Generate Textimage URL derivatives' permission."),
    '#default_value' => $config
      ->get('url_generation.enabled'),
  ];
  $form['settings']['url_generation']['text_separator'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Text separator'),
    '#maxlength' => 5,
    '#required' => TRUE,
    '#description' => $this
      ->t("Indicate the sequence of characters to be used to split the URL text string in separate strings. Each string will be consumed by a 'Text overlay' effect in the sequence specified within the image style. Note that slashes '/' and plus '+' characters are not allowed."),
    '#default_value' => $config
      ->get('url_generation.text_separator'),
  ];

  // Maintenance.
  $form['settings']['maintenance'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Maintenance'),
  ];
  $form['settings']['maintenance']['debug'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display debugging information'),
    '#default_value' => $config
      ->get('debug'),
    '#description' => $this
      ->t("Logs Textimage debug messages and shows them to users with the '%permission' permissions.", [
      '%permission' => implode(', ', [
        $this
          ->t('Administer site configuration'),
        $this
          ->t('Administer image styles'),
      ]),
    ]),
  ];
  $form['settings']['maintenance']['flush_all_label'] = [
    '#markup' => $this
      ->t('Remove all image files generated via Textimage, flush all the image styles, and clear the Textimage cache.') . '<br/>',
  ];
  $form['settings']['maintenance']['flush_all'] = [
    '#type' => 'submit',
    '#name' => 'flush_all',
    '#value' => $this
      ->t('Cleanup Textimage'),
  ];
  return parent::buildForm($form, $form_state);
}