5 * Enables inline form errors.
8 use Drupal\Core\Routing\RouteMatchInterface;
11 * Implements hook_help().
13 function inline_form_errors_help($route_name, RouteMatchInterface $route_match) {
14 switch ($route_name) {
15 case 'help.page.inline_form_errors':
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>';
24 * Implements hook_preprocess_HOOK() for form element templates.
26 function inline_form_errors_preprocess_form_element(&$variables) {
27 _inline_form_errors_set_errors($variables);
31 * Implements hook_preprocess_HOOK() for details element templates.
33 function inline_form_errors_preprocess_details(&$variables) {
34 _inline_form_errors_set_errors($variables);
38 * Implements hook_preprocess_HOOK() for fieldset element templates.
40 function inline_form_errors_preprocess_fieldset(&$variables) {
41 _inline_form_errors_set_errors($variables);
45 * Implements hook_preprocess_HOOK() for datetime form wrapper templates.
47 function inline_form_errors_preprocess_datetime_wrapper(&$variables) {
48 _inline_form_errors_set_errors($variables);
52 * Populates form errors in the template.
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'];