Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] APIv4: allow a field named "is_active" to default to false #27764

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CRM/ACL/DAO/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/ACL/ACL.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:56266204b43a487af7bf9963d23e0556)
* (GenCodeChecksum:d49159426e04e1bab16768e2f7ed9551)
*/

/**
Expand Down Expand Up @@ -135,7 +135,7 @@ class CRM_ACL_DAO_ACL extends CRM_Core_DAO {
/**
* Is this property active?
*
* @var bool|string|null
* @var bool|string
* (SQL type: tinyint)
* Note that values will be retrieved from the database as a string.
*/
Expand Down Expand Up @@ -425,13 +425,15 @@ public static function &fields() {
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('ACL Is Active?'),
'description' => ts('Is this property active?'),
'required' => TRUE,
'usage' => [
'import' => FALSE,
'export' => FALSE,
'duplicate_matching' => FALSE,
'token' => FALSE,
],
'where' => 'civicrm_acl.is_active',
'default' => '1',
'table_name' => 'civicrm_acl',
'entity' => 'ACL',
'bao' => 'CRM_ACL_BAO_ACL',
Expand Down
3 changes: 0 additions & 3 deletions Civi/Api4/Service/Spec/SpecGatherer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ 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'])) {
$DAOField['default'] = '1';
}
$this->setDynamicFk($DAOField, $values);
$field = SpecFormatter::arrayToField($DAOField, $entityName);
$spec->addFieldSpec($field);
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');
}

}
2 changes: 2 additions & 0 deletions xml/schema/ACL/ACL.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@
<name>is_active</name>
<title>ACL Is Active?</title>
<type>boolean</type>
<required>true</required>
<default>1</default>
<comment>Is this property active?</comment>
<add>1.6</add>
<html>
Expand Down