You are here

protected function InlineParagraphsWidget::buildAddActions in Paragraphs 8

Add 'add more' button, if not working with a programmed form.

Return value

array The form element array.

1 call to InlineParagraphsWidget::buildAddActions()
InlineParagraphsWidget::formMultipleElements in src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Special handling to create form elements for multiple values.

File

src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 970

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

protected function buildAddActions() {
  if (count($this
    ->getAccessibleOptions()) === 0) {
    if (count($this
      ->getAllowedTypes()) === 0) {
      $add_more_elements['info'] = [
        '#type' => 'container',
        '#markup' => $this
          ->t('You are not allowed to add any of the @title types.', [
          '@title' => $this
            ->getSetting('title'),
        ]),
        '#attributes' => [
          'class' => [
            'messages',
            'messages--warning',
          ],
        ],
      ];
    }
    else {
      $add_more_elements['info'] = [
        '#type' => 'container',
        '#markup' => $this
          ->t('You did not add any @title types yet.', [
          '@title' => $this
            ->getSetting('title'),
        ]),
        '#attributes' => [
          'class' => [
            'messages',
            'messages--warning',
          ],
        ],
      ];
    }
    return $add_more_elements;
  }
  if ($this
    ->getSetting('add_mode') == 'button' || $this
    ->getSetting('add_mode') == 'dropdown') {
    return $this
      ->buildButtonsAddMode();
  }
  return $this
    ->buildSelectAddMode();
}