comparison core/includes/form.inc @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
421 * This can be useful in cases such as the password_confirm element, which 421 * This can be useful in cases such as the password_confirm element, which
422 * creates children elements that have their own labels and required markers, 422 * creates children elements that have their own labels and required markers,
423 * but the parent element should have neither. Use this carefully because a 423 * but the parent element should have neither. Use this carefully because a
424 * field without an associated label can cause accessibility challenges. 424 * field without an associated label can cause accessibility challenges.
425 * 425 *
426 * To associate the label with a different field, set the #label_for property
427 * to the ID of the desired field.
428 *
426 * @param array $variables 429 * @param array $variables
427 * An associative array containing: 430 * An associative array containing:
428 * - element: An associative array containing the properties of the element. 431 * - element: An associative array containing the properties of the element.
429 * Properties used: #title, #title_display, #description, #id, #required, 432 * Properties used: #title, #title_display, #description, #id, #required,
430 * #children, #type, #name. 433 * #children, #type, #name, #label_for.
431 */ 434 */
432 function template_preprocess_form_element(&$variables) { 435 function template_preprocess_form_element(&$variables) {
433 $element = &$variables['element']; 436 $element = &$variables['element'];
434 437
435 // This function is invoked as theme wrapper, but the rendered form element 438 // This function is invoked as theme wrapper, but the rendered form element
437 // \Drupal::formBuilder()->doBuildForm(). 440 // \Drupal::formBuilder()->doBuildForm().
438 $element += [ 441 $element += [
439 '#title_display' => 'before', 442 '#title_display' => 'before',
440 '#wrapper_attributes' => [], 443 '#wrapper_attributes' => [],
441 '#label_attributes' => [], 444 '#label_attributes' => [],
445 '#label_for' => NULL,
442 ]; 446 ];
443 $variables['attributes'] = $element['#wrapper_attributes']; 447 $variables['attributes'] = $element['#wrapper_attributes'];
444 448
445 // Add element #id for #type 'item'. 449 // Add element #id for #type 'item'.
446 if (isset($element['#markup']) && !empty($element['#id'])) { 450 if (isset($element['#markup']) && !empty($element['#id'])) {
485 // Add label_display and label variables to template. 489 // Add label_display and label variables to template.
486 $variables['label_display'] = $element['#title_display']; 490 $variables['label_display'] = $element['#title_display'];
487 $variables['label'] = ['#theme' => 'form_element_label']; 491 $variables['label'] = ['#theme' => 'form_element_label'];
488 $variables['label'] += array_intersect_key($element, array_flip(['#id', '#required', '#title', '#title_display'])); 492 $variables['label'] += array_intersect_key($element, array_flip(['#id', '#required', '#title', '#title_display']));
489 $variables['label']['#attributes'] = $element['#label_attributes']; 493 $variables['label']['#attributes'] = $element['#label_attributes'];
494 if (!empty($element['#label_for'])) {
495 $variables['label']['#for'] = $element['#label_for'];
496 if (!empty($element['#id'])) {
497 $variables['label']['#id'] = $element['#id'] . '--label';
498 }
499 }
490 500
491 $variables['children'] = $element['#children']; 501 $variables['children'] = $element['#children'];
492 } 502 }
493 503
494 /** 504 /**
505 * empty #title, this will output the required marker alone within the label. 515 * empty #title, this will output the required marker alone within the label.
506 * The label will use the #id to associate the marker with the field that is 516 * The label will use the #id to associate the marker with the field that is
507 * required. That is especially important for screenreader users to know 517 * required. That is especially important for screenreader users to know
508 * which field is required. 518 * which field is required.
509 * 519 *
520 * To associate the label with a different field, set the #for property to the
521 * ID of the desired field.
522 *
510 * @param array $variables 523 * @param array $variables
511 * An associative array containing: 524 * An associative array containing:
512 * - element: An associative array containing the properties of the element. 525 * - element: An associative array containing the properties of the element.
513 * Properties used: #required, #title, #id, #value, #description. 526 * Properties used: #required, #title, #id, #value, #description, #for.
514 */ 527 */
515 function template_preprocess_form_element_label(&$variables) { 528 function template_preprocess_form_element_label(&$variables) {
516 $element = $variables['element']; 529 $element = $variables['element'];
517 // If title and required marker are both empty, output no label. 530 // If title and required marker are both empty, output no label.
518 if (isset($element['#title']) && $element['#title'] !== '') { 531 if (isset($element['#title']) && $element['#title'] !== '') {
822 // environments. 835 // environments.
823 \Drupal::moduleHandler()->alter('batch', $batch); 836 \Drupal::moduleHandler()->alter('batch', $batch);
824 837
825 // Assign an arbitrary id: don't rely on a serial column in the 'batch' 838 // Assign an arbitrary id: don't rely on a serial column in the 'batch'
826 // table, since non-progressive batches skip database storage completely. 839 // table, since non-progressive batches skip database storage completely.
827 $batch['id'] = db_next_id(); 840 $batch['id'] = \Drupal::database()->nextId();
828 841
829 // Move operations to a job queue. Non-progressive batches will use a 842 // Move operations to a job queue. Non-progressive batches will use a
830 // memory-based queue. 843 // memory-based queue.
831 foreach ($batch['sets'] as $key => $batch_set) { 844 foreach ($batch['sets'] as $key => $batch_set) {
832 _batch_populate_queue($batch, $key); 845 _batch_populate_queue($batch, $key);