protected function InlineParagraphsWidget::buildAddActions

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

Return value

array The form element array.

1 call to InlineParagraphsWidget::buildAddActions()

File

paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 977

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();
}