Allow custom fields to have custom fields
authorColeman Watts <coleman@civicrm.org>
Wed, 13 Jul 2022 21:30:02 +0000 (17:30 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 13 Jul 2022 21:30:02 +0000 (17:30 -0400)
Theoretically a custom field could have custom fields! Trippy...
Fixes dev/core#3731

CRM/Core/BAO/CustomField.php

index bfde273fb1af21cd3c066c6f2f5befe926468dbb..e8a3b612c57083229c1e4185a9737864758e8ef7 100644 (file)
@@ -226,7 +226,12 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     Civi::cache('metadata')->clear();
 
     foreach ($customFields as $index => $customField) {
-      CRM_Utils_Hook::post(empty($records[$index]['id']) ? 'create' : 'edit', 'CustomField', $customField->id, $customField);
+      $op = empty($records[$index]['id']) ? 'create' : 'edit';
+      // Theoretically a custom field could have custom fields! Trippy...
+      if (!empty($records[$index]['custom']) && is_array($records[$index]['custom'])) {
+        CRM_Core_BAO_CustomValueTable::store($records[$index]['custom'], static::$_tableName, $customField->id, $op);
+      }
+      CRM_Utils_Hook::post($op, 'CustomField', $customField->id, $customField);
     }
     return $customFields;
   }