public static Checkboxes::processCheckboxes(&$element, FormStateInterface $form_state, &$complete_form)
Processes a checkboxes form element.
File
- core/lib/Drupal/Core/Render/Element/Checkboxes.php, line 55
Class
- Checkboxes
- Provides a form element for a set of checkboxes.
Namespace
Drupal\Core\Render\Element
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | public static function processCheckboxes(& $element , FormStateInterface $form_state , & $complete_form ) { $value = is_array ( $element [ '#value' ]) ? $element [ '#value' ] : array (); $element [ '#tree' ] = TRUE; if ( count ( $element [ '#options' ]) > 0) { if (!isset( $element [ '#default_value' ]) || $element [ '#default_value' ] == 0) { $element [ '#default_value' ] = array (); } $weight = 0; foreach ( $element [ '#options' ] as $key => $choice ) { // Integer 0 is not a valid #return_value, so use '0' instead. // @see \Drupal\Core\Render\Element\Checkbox::valueCallback(). // @todo For Drupal 8, cast all integer keys to strings for consistency // with \Drupal\Core\Render\Element\Radios::processRadios(). if ( $key === 0) { $key = '0' ; } // Maintain order of options as defined in #options, in case the element // defines custom option sub-elements, but does not define all option // sub-elements. $weight += 0.001; $element += array ( $key => array ()); $element [ $key ] += array ( '#type' => 'checkbox' , '#title' => $choice , '#return_value' => $key , '#default_value' => isset( $value [ $key ]) ? $key : NULL, '#attributes' => $element [ '#attributes' ], '#ajax' => isset( $element [ '#ajax' ]) ? $element [ '#ajax' ] : NULL, // Errors should only be shown on the parent checkboxes element. '#error_no_message' => TRUE, '#weight' => $weight , ); } } return $element ; } |
Please login to continue.