allow is_active field to default to '0'
authorSandor Semsey <sandor@es-progress.hu>
Thu, 21 Sep 2023 23:01:58 +0000 (01:01 +0200)
committercolemanw <coleman@civicrm.org>
Tue, 17 Oct 2023 21:42:20 +0000 (17:42 -0400)
Civi/Api4/Service/Spec/SpecGatherer.php
tests/phpunit/api/v4/Spec/SpecGathererTest.php

index 0e5225723dfe1dcf9b345156d48f0abb60db1565..d77e3a8bc49b226c77432a9c91da0697b1492901 100644 (file)
@@ -97,9 +97,6 @@ class SpecGatherer extends AutoService {
       if (!empty($DAOField['component']) && !\CRM_Core_Component::isEnabled($DAOField['component'])) {
         continue;
       }
-      if ($DAOField['name'] == 'is_active' && empty($DAOField['default'])) {
-        $DAOField['default'] = '1';
-      }
       $this->setDynamicFk($DAOField, $values);
       $field = SpecFormatter::arrayToField($DAOField, $entityName);
       $spec->addFieldSpec($field);
index 04de1c46a4f59a4f1886ebfb77d95999e6277687..f879af8c18c0d013fccae095fea1483c678bd965 100644 (file)
@@ -65,4 +65,11 @@ class SpecGathererTest extends Api4TestBase {
     $this->assertContains('foo', $fieldNames);
   }
 
+  public function testIsActiveFieldCanDefaultToFalse(): void {
+    $gatherer = new SpecGatherer();
+    // Use Dashboard as it has is_active field and that defaults to 0 (according to schema)
+    $specs = $gatherer->getSpec('Dashboard', 'create', FALSE);
+    self::assertFalse($specs->getFieldByName('is_active')->getDefaultValue(), 'Default value for "is_active" field is not false');
+  }
+
 }