You are here

public function ModuleSettingsForm::buildForm in Layout Builder Styles 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 FormInterface::buildForm

File

src/Form/ModuleSettingsForm.php, line 48

Class

ModuleSettingsForm
Class ModuleSettingsForm.

Namespace

Drupal\layout_builder_styles\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->configFactory()
    ->get('layout_builder_styles.settings');
  $form['multiselect'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Multiple styles'),
    '#default_value' => $config
      ->get('multiselect'),
    '#options' => [
      'single' => $this
        ->t('Limit one style per given section or block.'),
      'multiple' => $this
        ->t('Allow multiple styles to be selected on a given section or block.'),
    ],
    '#description' => $this
      ->t('Limiting to one style per section or block is useful for sites which need each style choice to dictate the markup of the template. When this option is chosen, a corresponding block theme hook suggestion is provided. Allowing multiple styles is useful for sites whose style declarations correspond wholly to CSS modifications, and whose styles are designed to be used in conjunction. <strong>Note</strong>: if you switch this setting from "multiple" to "single" after Layout Builder Styles is already in use, any blocks that had been assigned multiple styles will initially continue to render with multiple styles until the block form is revisted; at that point, the Layout Builder Style options will be reset to no selections, and content editors should take care to reapply the single style they want to use.'),
  ];
  $form['form_type'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Form element for multiple styles'),
    '#default_value' => $config
      ->get('form_type'),
    '#options' => [
      'checkboxes' => $this
        ->t('Checkboxes'),
      'multiple-select' => $this
        ->t('Select (multiple) box'),
    ],
    '#description' => $this
      ->t('Choose whether the styles selector should display as multiple checkboxes or a select (multiple) box.'),
    '#states' => [
      'visible' => [
        ':input[name="multiselect"]' => [
          'value' => 'multiple',
        ],
      ],
    ],
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save configuration'),
  ];
  return $form;
}