protected function ParagraphsWidget::buildDropbutton

Build drop button.

Parameters

array $elements: Elements for drop button.

Return value

array Drop button array.

1 call to ParagraphsWidget::buildDropbutton()
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 1816

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

protected function buildDropbutton(array $elements = []) {
  $build = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'paragraphs-dropbutton-wrapper',
      ],
    ],
  ];
  $operations = [];

  // Because we are cloning the elements into title sub element we need to
  // sort children first.
  foreach (Element::children($elements, TRUE) as $child) {

    // Clone the element as an operation.
    $operations[$child] = [
      'title' => $elements[$child],
    ];

    // Flag the original element as printed so it doesn't render twice.
    $elements[$child]['#printed'] = TRUE;
  }
  $build['operations'] = [
    '#type' => 'paragraph_operations',
    // Even though operations are run through the "links" element type, the
    // theme system will render any render array passed as a link "title".
    '#links' => $operations,
    '#dropbutton_type' => 'small',
  ];
  return $build + $elements;
}