From 3d7554d65f22611e6236c4d245a6d431ef4e42bc Mon Sep 17 00:00:00 2001
From: Daniel Harper <dan@hrpr.co.uk>
Date: Tue, 25 Feb 2025 13:45:28 +0000
Subject: [PATCH 1/2] Initialise properties of form before checking them.

---
 themable_forms.module | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/themable_forms.module b/themable_forms.module
index 686710b..20a5b69 100644
--- a/themable_forms.module
+++ b/themable_forms.module
@@ -47,6 +47,14 @@ function themable_forms_preprocess_form_element(array &$variables) {
     return;
   }
 
+  // Initialize the properties
+  if (!isset($variables['label']['#form_id'])) {
+    $variables['label']['#form_id'] = NULL;
+  }
+  if (!isset($variables['label']['#form_element_type'])) {
+    $variables['label']['#form_element_type'] = NULL;
+  }
+
   if (isset($variables['element']['#form_id'])) {
     $variables['label']['#form_id'] = $variables['element']['#form_id'];
   }
-- 
GitLab


From 633463728924f817c8ae220c04ae4ba6d3b25540 Mon Sep 17 00:00:00 2001
From: Daniel Harper <dan@hrpr.co.uk>
Date: Tue, 25 Feb 2025 14:01:38 +0000
Subject: [PATCH 2/2] Rewrote the patch from the ticket on DO.

---
 themable_forms.module | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/themable_forms.module b/themable_forms.module
index 20a5b69..3fa8993 100644
--- a/themable_forms.module
+++ b/themable_forms.module
@@ -47,14 +47,6 @@ function themable_forms_preprocess_form_element(array &$variables) {
     return;
   }
 
-  // Initialize the properties
-  if (!isset($variables['label']['#form_id'])) {
-    $variables['label']['#form_id'] = NULL;
-  }
-  if (!isset($variables['label']['#form_element_type'])) {
-    $variables['label']['#form_element_type'] = NULL;
-  }
-
   if (isset($variables['element']['#form_id'])) {
     $variables['label']['#form_id'] = $variables['element']['#form_id'];
   }
@@ -66,7 +58,7 @@ function themable_forms_preprocess_form_element(array &$variables) {
 /**
  * Implements hook_form_alter().
  */
-function themable_forms_form_alter(&$form, FormStateInterface $form_state, $form_id) {
+function themable_forms_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
   themable_forms_attach_form_id($form, $form_id);
 }
 
@@ -80,8 +72,8 @@ function themable_forms_form_alter(&$form, FormStateInterface $form_state, $form
  */
 function themable_forms_attach_form_id(array &$form, $form_id) {
   foreach (Element::children($form) as $child) {
-    if (!isset($form[$child]['#form_id'])) {
-      $form[$child]['#form_id'] = $form_id;
+    if (!isset($form[$child]['#attached']['data']['form_id'])) {
+      $form[$child]['#attached']['data']['form_id'] = $form_id;
     }
     themable_forms_attach_form_id($form[$child], $form_id);
   }
-- 
GitLab