'dropbutton', * '#links' => array( * 'simple_form' => array( * 'title' => $this->t('Simple Form'), * 'url' => Url::fromRoute('fapi_example.simple_form'), * ), * 'demo' => array( * 'title' => $this->t('Build Demo'), * 'url' => Url::fromRoute('fapi_example.build_demo'), * ), * ), * ); * @endcode * * @see \Drupal\Core\Render\Element\Operations * * @RenderElement("dropbutton") */ class Dropbutton extends RenderElement { /** * {@inheritdoc} */ public function getInfo() { $class = get_class($this); return [ '#pre_render' => [ [$class, 'preRenderDropbutton'], ], '#theme' => 'links__dropbutton', ]; } /** * Pre-render callback: Attaches the dropbutton library and required markup. */ public static function preRenderDropbutton($element) { $element['#attached']['library'][] = 'core/drupal.dropbutton'; $element['#attributes']['class'][] = 'dropbutton'; if (!isset($element['#theme_wrappers'])) { $element['#theme_wrappers'] = []; } array_unshift($element['#theme_wrappers'], 'dropbutton_wrapper'); // Enable targeted theming of specific dropbuttons (e.g., 'operations' or // 'operations__node'). if (isset($element['#subtype'])) { $element['#theme'] .= '__' . $element['#subtype']; } return $element; } }