You are here

protected function ParagraphsWidget::buildModalAddForm in Paragraphs 8

Builds an add paragraph button for opening of modal form.

Parameters

array $element: Render element.

1 call to ParagraphsWidget::buildModalAddForm()
ParagraphsWidget::buildButtonsAddMode in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Builds dropdown button for adding new paragraph.

File

src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 931

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

protected function buildModalAddForm(array &$element) {

  // Attach the theme for the dialog template.
  $element['#theme'] = 'paragraphs_add_dialog';
  $element['add_modal_form_area'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'paragraph-type-add-modal',
        'first-button',
      ],
    ],
    '#access' => $this
      ->allowReferenceChanges(),
    '#weight' => -2000,
  ];
  $element['add_modal_form_area']['add_more'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add @title', [
      '@title' => $this
        ->getSetting('title'),
    ]),
    '#name' => 'button_add_modal',
    '#attributes' => [
      'class' => [
        'paragraph-type-add-modal-button',
        'js-show',
        'button--small',
      ],
    ],
  ];
  $element['#attached']['library'][] = 'paragraphs/drupal.paragraphs.modal';
  if ($this
    ->isFeatureEnabled('add_above')) {
    $element['#attached']['library'][] = 'paragraphs/drupal.paragraphs.add_above_button';
  }
}