You are here

public static function ParagraphsWidget::expandButton in Paragraphs 8

Expand button base array into a paragraph widget action button.

Parameters

array $button_base: Button base render array.

Return value

array Button render array.

5 calls to ParagraphsWidget::expandButton()
ParagraphsWidget::buildButtonsAddMode in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Builds dropdown button for adding new paragraph.
ParagraphsWidget::buildHeaderActions in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Builds header actions.
ParagraphsWidget::formElement in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Uses a similar approach to populate a new translation.
ParagraphsWidget::formMultipleElements in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Special handling to create form elements for multiple values.
paragraphs_test_paragraphs_widget_actions_alter in tests/modules/paragraphs_test/paragraphs_test.module
Implements hook_paragraphs_widget_actions_alter().

File

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

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public static function expandButton(array $button_base) {

  // Do not expand elements that do not have submit handler.
  if (empty($button_base['#submit'])) {
    return $button_base;
  }
  $button = $button_base + [
    '#type' => 'submit',
    '#theme_wrappers' => [
      'input__submit__paragraph_action',
    ],
  ];

  // Html::getId will give us '-' char in name but we want '_' for now so
  // we use strtr to search&replace '-' to '_'.
  $button['#name'] = strtr(Html::getId($button_base['#name']), '-', '_');
  $button['#id'] = Html::getUniqueId($button['#name']);
  if (isset($button['#ajax'])) {
    $button['#ajax'] += [
      'effect' => 'fade',
      // Since a normal throbber is added inline, this has the potential to
      // break a layout if the button is located in dropbuttons. Instead,
      // it's safer to just show the fullscreen progress element instead.
      'progress' => [
        'type' => 'fullscreen',
      ],
    ];
  }
  return $button;
}