You are here

public function ConfigureStyles::buildForm in Block Style Plugins 8.2

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/ConfigureStyles.php, line 123

Class

ConfigureStyles
Provides a form to configure styles.

Namespace

Drupal\block_style_plugins\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $uuid = NULL, $plugin_id = NULL) {
  $this->sectionStorage = $section_storage;
  $this->delta = $delta;
  $this->uuid = $uuid;
  $block_styles = $this
    ->getComponent()
    ->getThirdPartySetting('block_style_plugins', $plugin_id, []);
  $this->blockStyles = $this->blockStyleManager
    ->createInstance($plugin_id);
  $this->blockStyles
    ->setConfiguration($block_styles);
  $form['#tree'] = TRUE;
  $form['settings'] = [];
  if ($this->blockStyles instanceof PluginFormInterface) {
    $subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
    $form['settings'] = $this
      ->getPluginForm($this->blockStyles)
      ->buildConfigurationForm($form['settings'], $subform_state);
  }
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $block_styles ? $this
      ->t('Update') : $this
      ->t('Add Styles'),
    '#button_type' => 'primary',
  ];
  $form['back_button'] = [
    '#type' => 'link',
    '#url' => Url::fromRoute('block_style_plugins.layout_builder.styles', [
      'section_storage_type' => $section_storage
        ->getStorageType(),
      'section_storage' => $section_storage
        ->getStorageId(),
      'delta' => $delta,
      'uuid' => $uuid,
    ]),
    '#title' => $this
      ->t('Back'),
  ];
  $form['#attributes']['data-layout-builder-target-highlight-id'] = $this
    ->blockUpdateHighlightId($this->uuid);
  if ($this
    ->isAjax()) {
    $form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
    $form['back_button']['#attributes'] = [
      'class' => [
        'use-ajax',
      ],
      'data-dialog-type' => 'dialog',
      'data-dialog-renderer' => 'off_canvas',
    ];
  }
  return $form;
}