52e572d3003deff9465b2021f0f65c60aaaaa119
[yaffs-website] / web / core / modules / inline_form_errors / inline_form_errors.module
1 <?php
2
3 /**
4  * @file
5  * Enables inline form errors.
6  */
7
8 use Drupal\Core\Routing\RouteMatchInterface;
9
10 /**
11  * Implements hook_help().
12  */
13 function inline_form_errors_help($route_name, RouteMatchInterface $route_match) {
14   switch ($route_name) {
15     case 'help.page.inline_form_errors':
16       $output = '';
17       $output .= '<h3>' . t('About') . '</h3>';
18       $output .= '<p>' . t('The Inline Form Errors module provides an experimental approach to form errors, placing the error messages next to the elements themselves. For more information, see the <a href=":inline_form_error">online documentation for the Inline Form Errors module</a>.', [':inline_form_error' => 'https://www.drupal.org/documentation/modules/inline_form_error']) . '</p>';
19       return $output;
20   }
21 }
22
23 /**
24  * Implements hook_preprocess_HOOK() for form element templates.
25  */
26 function inline_form_errors_preprocess_form_element(&$variables) {
27   _inline_form_errors_set_errors($variables);
28 }
29
30 /**
31  * Implements hook_preprocess_HOOK() for details element templates.
32  */
33 function inline_form_errors_preprocess_details(&$variables) {
34   _inline_form_errors_set_errors($variables);
35 }
36
37 /**
38  * Implements hook_preprocess_HOOK() for fieldset element templates.
39  */
40 function inline_form_errors_preprocess_fieldset(&$variables) {
41   _inline_form_errors_set_errors($variables);
42 }
43
44 /**
45  * Implements hook_preprocess_HOOK() for datetime form wrapper templates.
46  */
47 function inline_form_errors_preprocess_datetime_wrapper(&$variables) {
48   _inline_form_errors_set_errors($variables);
49 }
50
51 /**
52  * Populates form errors in the template.
53  */
54 function _inline_form_errors_set_errors(&$variables) {
55   $element = $variables['element'];
56   if (!empty($element['#errors']) && empty($element['#error_no_message'])) {
57     $variables['errors'] = $element['#errors'];
58   }
59 }