3 namespace Drupal\inline_form_errors;
5 use Drupal\Core\Form\FormStateInterface;
8 * Provides functionality to process render elements.
10 class RenderElementHelper {
13 * Alters the element type info.
16 * An associative array with structure identical to that of the return value
17 * of \Drupal\Core\Render\ElementInfoManagerInterface::getInfo().
19 public function alterElementInfo(array &$info) {
20 foreach ($info as $element_type => $element_info) {
21 $info[$element_type]['#process'][] = [static::class, 'processElement'];
26 * Process all render elements.
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.
38 * The processed element.
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;