You are here

public function InlineBlockUX::buildConfigurationForm in Layout Builder UX 8

Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements.

Overrides InlineBlock::buildConfigurationForm

See also

\Drupal\Core\Block\BlockBase::blockForm()

File

src/Plugin/Block/InlineBlockUX.php, line 34

Class

InlineBlockUX
Alters the inline block form.

Namespace

Drupal\lb_ux\Plugin\Block

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);

  // Hide the label field when the label display is unchecked.
  $form['label']['#states']['invisible'][':input[name="settings[label_display]"]']['checked'] = FALSE;
  if ($this->isNew) {

    // Uncheck the label display checkbox for new blocks.
    $form['label_display']['#default_value'] = FALSE;

    // Prefill the label field for new blocks.
    $form['label']['#default_value'] = $this
      ->t('@label @count', [
      '@label' => $this
        ->label(),
      '@count' => $this
        ->getNextInlineBlockNumber($form_state),
    ]);
  }
  return $form;
}