Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / inline_form_errors / src / RenderElementHelper.php
1 <?php
2
3 namespace Drupal\inline_form_errors;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * Provides functionality to process render elements.
9  */
10 class RenderElementHelper {
11
12   /**
13    * Alters the element type info.
14    *
15    * @param array $info
16    *   An associative array with structure identical to that of the return value
17    *   of \Drupal\Core\Render\ElementInfoManagerInterface::getInfo().
18    */
19   public function alterElementInfo(array &$info) {
20     foreach ($info as $element_type => $element_info) {
21       $info[$element_type]['#process'][] = [static::class, 'processElement'];
22     }
23   }
24
25   /**
26    * Process all render elements.
27    *
28    * @param array $element
29    *   An associative array containing the properties and children of the
30    *   element. Note that $element must be taken by reference here, so processed
31    *   child elements are taken over into $form_state.
32    * @param \Drupal\Core\Form\FormStateInterface $form_state
33    *   The current state of the form.
34    * @param array $complete_form
35    *   The complete form structure.
36    *
37    * @return array
38    *   The processed element.
39    */
40   public static function processElement(array &$element, FormStateInterface $form_state, array &$complete_form) {
41     // Prevent displaying inline form errors when disabled for the whole form.
42     if (!empty($complete_form['#disable_inline_form_errors'])) {
43       $element['#error_no_message'] = TRUE;
44     }
45
46     return $element;
47   }
48
49 }