Commit d8c56578 authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3268007 by RenatoG: Create the Settings to include the maxlength to be configurable

parent adfbf466
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
block_class.settings:
  path: '/admin/config/content/block-class/settings'
  defaults:
    _title: 'Block Class Settings'
    _form: 'Drupal\block_class\Form\BlockClassSettingsForm'
  requirements:
    _permission: 'administer block classes'
 No newline at end of file
+67 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\block_class\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Form for Block Class Settings.
 */
class BlockClassSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'block_class_admin_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'block_class.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    $config = $this->config('block_class.settings');

    $form['global_settings'] = [
      '#type' => 'details',
      '#title' => $this->t('Global Settings'),
      '#open' => TRUE,
    ];

    $maxlength_block_class_field = 255;

    if (!empty($config->get('maxlength_block_class_field'))) {
      $maxlength_block_class_field = $config->get('maxlength_block_class_field');
    }

    $form['global_settings']['maxlength_block_class_field'] = [
      '#title' => $this->t("Maxlength on block class field"),
      '#type' => 'number',
      '#description' => $this->t('This will be the default maxlength value for the "maxlength" field. The default is 255.'),
      '#default_value' => $maxlength_block_class_field,
    ];

    $form['actions'] = [
      '#type' => 'actions',
    ];

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Submit'),
    ];

    return $form;

  }
}