Added another front page space for Yaffs info. Added roave security for composer.
[yaffs-website] / web / core / lib / Drupal / Core / Render / Element / Container.php
1 <?php
2
3 namespace Drupal\Core\Render\Element;
4
5 use Drupal\Component\Utility\Html as HtmlUtility;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Provides a render element that wraps child elements in a container.
10  *
11  * Surrounds child elements with a <div> and adds attributes such as classes or
12  * an HTML ID.
13  *
14  * Usage example:
15  * @code
16  * $form['needs_accommodation'] = array(
17  *   '#type' => 'checkbox',
18  *   '#title' => $this->t('Need Special Accommodations?'),
19  * );
20  *
21  * $form['accommodation'] = array(
22  *   '#type' => 'container',
23  *   '#attributes' => array(
24  *     'class' => 'accommodation',
25  *   ),
26  *   '#states' => array(
27  *     'invisible' => array(
28  *       'input[name="needs_accommodation"]' => array('checked' => FALSE),
29  *     ),
30  *   ),
31  * );
32  *
33  * $form['accommodation']['diet'] = array(
34  *   '#type' => 'textfield',
35  *   '#title' => $this->t('Dietary Restrictions'),
36  * );
37  * @endcode
38  *
39  * @RenderElement("container")
40  */
41 class Container extends RenderElement {
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getInfo() {
47     $class = get_class($this);
48     return [
49       '#process' => [
50         [$class, 'processGroup'],
51         [$class, 'processContainer'],
52       ],
53       '#pre_render' => [
54         [$class, 'preRenderGroup'],
55       ],
56       '#theme_wrappers' => ['container'],
57     ];
58   }
59
60   /**
61    * Processes a container element.
62    *
63    * @param array $element
64    *   An associative array containing the properties and children of the
65    *   container.
66    * @param \Drupal\Core\Form\FormStateInterface $form_state
67    *   The current state of the form.
68    * @param array $complete_form
69    *   The complete form structure.
70    *
71    * @return array
72    *   The processed element.
73    */
74   public static function processContainer(&$element, FormStateInterface $form_state, &$complete_form) {
75     // Generate the ID of the element if it's not explicitly given.
76     if (!isset($element['#id'])) {
77       $element['#id'] = HtmlUtility::getUniqueId(implode('-', $element['#parents']) . '-wrapper');
78     }
79     return $element;
80   }
81
82 }