You are here

public function GlobalSettingsForm::buildForm in Layout Builder Component Attributes 1.0.x

Same name and namespace in other branches
  1. 1.2.x src/Form/GlobalSettingsForm.php \Drupal\layout_builder_component_attributes\Form\GlobalSettingsForm::buildForm()
  2. 1.1.x src/Form/GlobalSettingsForm.php \Drupal\layout_builder_component_attributes\Form\GlobalSettingsForm::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/GlobalSettingsForm.php, line 39

Class

GlobalSettingsForm
Global settings form.

Namespace

Drupal\layout_builder_component_attributes\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config(static::SETTINGS)
    ->get();

  // Convert the true/false values back into a format FAPI expects.
  // attribute => attribute (for true).
  // attribute => 0 (for false).
  foreach ($config as $category => $cat_config) {
    foreach ($cat_config as $attribute => $value) {
      $config[$category][$attribute] = $value ? $attribute : 0;
    }
  }
  $options = [
    'id' => $this
      ->t('ID'),
    'class' => $this
      ->t('Class(es)'),
    'style' => $this
      ->t('Inline CSS styles'),
    'data' => $this
      ->t('Custom data-* attributes'),
  ];
  $form['intro'] = [
    '#markup' => $this
      ->t('<p>Attributes can be added to 1) the block (outer) element, 2) the block title, and 3) the block content (inner) element. Control which attributes are made available to content editors below:</p>'),
  ];
  $form['allowed_block_attributes'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Allowed block attributes'),
    '#options' => $options,
    '#default_value' => $config['allowed_block_attributes'],
  ];
  $form['allowed_block_title_attributes'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Allowed block title attributes'),
    '#options' => $options,
    '#default_value' => $config['allowed_block_title_attributes'],
  ];
  $form['allowed_block_content_attributes'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Allowed block content attributes'),
    '#options' => $options,
    '#default_value' => $config['allowed_block_content_attributes'],
    '#description' => $this
      ->t('In order for attributes to be rendered on the the block content (inner) element, the active front-end theme must support <code>content_attributes</code> in its block.html.twig file. See README.md for more information.'),
  ];
  return parent::buildForm($form, $form_state);
}