APIv4 Explorer - Format array params using add methods instead of set when available
authorColeman Watts <coleman@civicrm.org>
Wed, 5 Jan 2022 16:06:24 +0000 (11:06 -0500)
committerColeman Watts <coleman@civicrm.org>
Wed, 5 Jan 2022 16:06:24 +0000 (11:06 -0500)
Improves OOP generated code by using sugar methods `addGroupBy()` and `addRecords()`

ang/api4Explorer/Explorer.js

index b85f4734f07c4ec02c5a57c3a532d942f477fdb3..dcfc702e2695fa680f321635d3cc17a7e7a5a41c 100644 (file)
     // Format oop params
     function formatOOP(entity, action, params, indent) {
       var info = getEntity(entity),
+        arrayParams = ['groupBy', 'records'],
         newLine = "\n" + _.repeat(' ', indent),
         code = '\\' + info.class + '::' + action + '(',
         perm = params.checkPermissions === false ? 'FALSE' : '';
             val = phpFormat(index) + ', ' + phpFormat(item, 2 + indent);
             code += newLine + "->add" + ucfirst(key).replace(/s$/, '') + '(' + val + ')';
           });
+        } else if (_.includes(arrayParams, key)) {
+          _.each(param, function(item) {
+            code += newLine + "->add" + ucfirst(key).replace(/s$/, '') + '(' + phpFormat(item, 2 + indent) + ')';
+          });
         } else if (key === 'where') {
           _.each(param, function (clause) {
             if (clause[0] === 'AND' || clause[0] === 'OR' || clause[0] === 'NOT') {