children(TRUE) as $key => $child) { if ($dropbutton = $child->getProperty('dropbutton')) { // If there is no dropbutton for this button group yet, create one. if (!isset($dropbuttons->$dropbutton)) { $dropbuttons->$dropbutton = ['#type' => 'dropbutton']; } $dropbuttons[$dropbutton]['#links'][$key] = ['title' => $child->getArray()]; // Remove original child from the element so it's not rendered twice. $child->setProperty('printed', TRUE); } } $element->exchangeArray($dropbuttons->getArray() + $element->getArray()); } }