Added another front page space for Yaffs info. Added roave security for composer.
[yaffs-website] / web / core / lib / Drupal / Core / Render / Element / Dropbutton.php
1 <?php
2
3 namespace Drupal\Core\Render\Element;
4
5 /**
6  * Provides a render element for a set of links rendered as a drop-down button.
7  *
8  * By default, this element sets #theme so that the 'links' theme hook is used
9  * for rendering, with suffixes so that themes can override this specifically
10  * without overriding all links theming. If the #subtype property is provided in
11  * your render array with value 'foo', #theme is set to links__dropbutton__foo;
12  * if not, it's links__dropbutton; both of these can be overridden by setting
13  * the #theme property in your render array. See template_preprocess_links()
14  * for documentation on the other properties used in theming; for instance, use
15  * element property #links to provide $variables['links'] for theming.
16  *
17  * Properties:
18  * - #links: An array of links to actions. See template_preprocess_links() for
19  *   documentation the properties of links in this array.
20  *
21  * Usage Example:
22  * @code
23  * $form['actions']['extra_actions'] = array(
24  *   '#type' => 'dropbutton',
25  *   '#links' => array(
26  *     'simple_form' => array(
27  *       'title' => $this->t('Simple Form'),
28  *       'url' => Url::fromRoute('fapi_example.simple_form'),
29  *     ),
30  *     'demo' => array(
31  *       'title' => $this->t('Build Demo'),
32  *       'url' => Url::fromRoute('fapi_example.build_demo'),
33  *     ),
34  *   ),
35  * );
36  * @endcode
37  *
38  * @see \Drupal\Core\Render\Element\Operations
39  *
40  * @RenderElement("dropbutton")
41  */
42 class Dropbutton extends RenderElement {
43
44   /**
45    * {@inheritdoc}
46    */
47   public function getInfo() {
48     $class = get_class($this);
49     return [
50       '#pre_render' => [
51         [$class, 'preRenderDropbutton'],
52       ],
53       '#theme' => 'links__dropbutton',
54     ];
55   }
56
57   /**
58    * Pre-render callback: Attaches the dropbutton library and required markup.
59    */
60   public static function preRenderDropbutton($element) {
61     $element['#attached']['library'][] = 'core/drupal.dropbutton';
62     $element['#attributes']['class'][] = 'dropbutton';
63     if (!isset($element['#theme_wrappers'])) {
64       $element['#theme_wrappers'] = [];
65     }
66     array_unshift($element['#theme_wrappers'], 'dropbutton_wrapper');
67
68     // Enable targeted theming of specific dropbuttons (e.g., 'operations' or
69     // 'operations__node').
70     if (isset($element['#subtype'])) {
71       $element['#theme'] .= '__' . $element['#subtype'];
72     }
73
74     return $element;
75   }
76
77 }