You are here

public function SettingsForm::buildForm in Layout Builder Base 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/SettingsForm.php, line 39

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\layout_builder_base\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config(static::SETTINGS);
  $form['lbb_settings'] = [
    '#type' => 'vertical_tabs',
    '#title' => $this
      ->t('Layout Builder Base Settings'),
  ];
  $form['default_values'] = [
    '#type' => 'details',
    '#title' => 'Default values',
    '#group' => 'lbb_settings',
    '#tree' => true,
  ];
  $form['override_options'] = [
    '#type' => 'details',
    '#title' => 'Override options',
    '#group' => 'lbb_settings',
    '#tree' => true,
  ];
  $form['default_values']['help'] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => $this
      ->t('Configuring the default settings here will apply to all the layouts. If you need custom logic per layout, you will have to create your own. Since the layouts can have any value for their options, you need to enter yourself the value of the selects.'),
  ];
  $form['default_values'] = array_merge($form['default_values'], $this
    ->getDetails());
  $form['override_options']['help'] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => $this
      ->t('Those fields allow you to override the options that the layouts are proposing. The options should be written with the following format: class|Label with one option per line. You can also use the value <none> in case you want to completely remove this option from the interface. If you want to keep some options from the module, just add them to the list in addition of yours. Example: layout--background--white|White'),
  ];
  $form['override_options'] = array_merge($form['override_options'], $this
    ->getDetails());
  $properties = $this
    ->getProperties();
  foreach ($properties as $property => $infos) {
    $form['default_values'][$infos['group']][$property] = [
      '#type' => 'textfield',
      '#title' => $infos['label'],
      '#size' => 64,
      '#default_value' => $config
        ->get($property),
    ];
  }
  foreach ($properties as $property => $infos) {
    $form['override_options'][$infos['group']][$property] = [
      '#type' => 'textarea',
      '#title' => $infos['label'],
      '#size' => 64,
      '#default_value' => $config
        ->get(self::getOverrideConfigName($property)),
    ];
  }
  return parent::buildForm($form, $form_state);
}