APIv4 - Rename 'controlField' property to 'control_field' for consistency
authorColeman Watts <coleman@civicrm.org>
Mon, 1 Mar 2021 03:53:11 +0000 (22:53 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 1 Mar 2021 03:55:21 +0000 (22:55 -0500)
By convention, all keys returned from the api should be lowercase.

Civi/Api4/Generic/AbstractAction.php
Civi/Api4/Service/Spec/SpecFormatter.php
ext/afform/core/ang/af/afField.component.js

index 8ac54c577438864ae38e76e4818ecbdff80391cc..2103f319c211e5c498667104fa2156459fbbdc3e 100644 (file)
@@ -498,7 +498,7 @@ abstract class AbstractAction implements \ArrayAccess {
             'val' => $record[$expr],
             'field' => $field,
             'suffix' => substr($expr, $suffix + 1),
-            'depends' => $field['input_attrs']['controlField'] ?? NULL,
+            'depends' => $field['input_attrs']['control_field'] ?? NULL,
           ];
           unset($record[$expr]);
         }
index a860e60b0bb61d0c073fb89794269ef535cbc5ad..dad0c20caaad7493f1eccb8281babcbd1c94382a 100644 (file)
@@ -172,6 +172,14 @@ class SpecFormatter {
         }
       }
     }
+    // Ensure all keys use lower_case not camelCase
+    foreach ($inputAttrs as $key => $val) {
+      if ($key !== strtolower($key)) {
+        unset($inputAttrs[$key]);
+        $key = strtolower(preg_replace('/(?=[A-Z])/', '_$0', $key));
+        $inputAttrs[$key] = $val;
+      }
+    }
     $fieldSpec
       ->setInputType($inputType)
       ->setInputAttrs($inputAttrs);
index 385038294f66a7e6f507767f00897c40843c45d2..439f3ddcfe5ca62cac141cc82bce9f8f507090bb 100644 (file)
@@ -45,7 +45,7 @@
 
         // ChainSelect - watch control field & reload options as needed
         if (ctrl.defn.input_type === 'ChainSelect') {
-          $scope.$watch('dataProvider.getFieldData()[defn.input_attrs.controlField]', function(val) {
+          $scope.$watch('dataProvider.getFieldData()[defn.input_attrs.control_field]', function(val) {
             if (val) {
               var params = {
                 where: [['name', '=', ctrl.fieldName]],
@@ -53,7 +53,7 @@
                 loadOptions: ['id', 'label'],
                 values: {}
               };
-              params.values[ctrl.defn.input_attrs.controlField] = val;
+              params.values[ctrl.defn.input_attrs.control_field] = val;
               crmApi4($scope.dataProvider.getEntityType(), 'getFields', params, 0)
                 .then(function(data) {
                   ctrl.defn.options = data.options;