Build drop button.
array $elements: Elements for drop button.
array Drop button array.
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;
}