diff --git a/Civi/Api4/Service/Spec/SpecGatherer.php b/Civi/Api4/Service/Spec/SpecGatherer.php index 0e5225723dfe..e21223ccd478 100644 --- a/Civi/Api4/Service/Spec/SpecGatherer.php +++ b/Civi/Api4/Service/Spec/SpecGatherer.php @@ -97,7 +97,7 @@ private function addDAOFields(string $entityName, string $action, RequestSpec $s if (!empty($DAOField['component']) && !\CRM_Core_Component::isEnabled($DAOField['component'])) { continue; } - if ($DAOField['name'] == 'is_active' && empty($DAOField['default'])) { + if ($DAOField['name'] == 'is_active' && (!isset($DAOField['default']) || $DAOField['default'] === '')) { $DAOField['default'] = '1'; } $this->setDynamicFk($DAOField, $values); diff --git a/tests/phpunit/api/v4/Spec/SpecGathererTest.php b/tests/phpunit/api/v4/Spec/SpecGathererTest.php index 04de1c46a4f5..f879af8c18c0 100644 --- a/tests/phpunit/api/v4/Spec/SpecGathererTest.php +++ b/tests/phpunit/api/v4/Spec/SpecGathererTest.php @@ -65,4 +65,11 @@ public function testWithSpecProvider(): void { $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'); + } + }