protected function ParagraphsWidget::buildModalAddForm

Builds an add paragraph button for opening of modal form.

Parameters

array $element: Render element.

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

File

paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 1167

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' => [
        'field-add-more-submit',
        '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';
  }
}