Skip to content

Commit

Permalink
allow is_active field to default to '0'
Browse files Browse the repository at this point in the history
  • Loading branch information
semseysandor committed Oct 9, 2023
1 parent 1f76d7c commit 9db25df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Civi/Api4/Service/Spec/SpecGatherer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions tests/phpunit/api/v4/Spec/SpecGathererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

}

0 comments on commit 9db25df

Please sign in to comment.