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

Afform - switch entity declaration to standard metadata #31072

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
18 changes: 13 additions & 5 deletions CRM/Core/DAO/AllCoreTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public static function flush(): void {
* [EntityName => [table => table_name, class => CRM_DAO_ClassName]][]
*/
public static function getEntities(): array {
return EntityRepository::getEntities();
$allEntities = EntityRepository::getEntities();
// Filter out entities without a table
$tables = EntityRepository::getTableIndex();
// Filter out entities without a class
$classes = EntityRepository::getClassIndex();
return array_intersect_key($allEntities, array_flip($tables), array_flip($classes));
}

/**
Expand Down Expand Up @@ -166,7 +171,8 @@ public static function multilingualize($class, $originalIndices) {
* [EntityName => CRM_DAO_ClassName]
*/
public static function daoToClass() {
return array_combine(array_keys(self::getEntities()), array_column(self::getEntities(), 'class'));
$entities = self::getEntities();
return array_combine(array_keys($entities), array_column($entities, 'class'));
}

/**
Expand Down Expand Up @@ -296,9 +302,11 @@ public static function getClasses() {
public static function getBaoClasses() {
$r = [];
foreach (self::getEntities() as $name => $entity) {
$baoClass = str_replace('_DAO_', '_BAO_', $entity['class']);
if (class_exists($baoClass)) {
$r[$name] = $baoClass;
if (!empty($entity['class'])) {
$baoClass = str_replace('_DAO_', '_BAO_', $entity['class']);
if (class_exists($baoClass)) {
$r[$name] = $baoClass;
}
}
}
return $r;
Expand Down
4 changes: 2 additions & 2 deletions Civi/Schema/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ private static function loadAll(): void {
// Extensions should be online when we're called.
\CRM_Utils_Hook::entityTypes($entityTypes);
self::$entities = array_column($entityTypes, NULL, 'name');
self::$tableIndex = array_column($entityTypes, 'name', 'table');
self::$classIndex = array_column($entityTypes, 'name', 'class');
self::$tableIndex = array_column(array_filter($entityTypes, fn($entityType) => !empty($entityType['table'])), 'name', 'table');
self::$classIndex = array_column(array_filter($entityTypes, fn($entityType) => !empty($entityType['class'])), 'name', 'class');
}

private static function loadCoreEntities(): array {
Expand Down
206 changes: 2 additions & 204 deletions ext/afform/core/Civi/Api4/Afform.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Civi\Api4;

use Civi\Api4\Generic\AutocompleteAction;
use Civi\Api4\Generic\BasicGetFieldsAction;
use CRM_Afform_ExtensionUtil as E;

/**
Expand Down Expand Up @@ -138,209 +137,8 @@ public static function revert($checkPermissions = TRUE) {
* @return Generic\BasicGetFieldsAction
*/
public static function getFields($checkPermissions = TRUE) {
return (new Generic\BasicGetFieldsAction('Afform', __FUNCTION__, function(BasicGetFieldsAction $self) {
$fields = [
[
'name' => 'name',
'title' => E::ts('Name'),
],
[
'name' => 'type',
'title' => E::ts('Type'),
'pseudoconstant' => ['optionGroupName' => 'afform_type'],
'default_value' => 'form',
],
[
'name' => 'requires',
'title' => E::ts('Requires'),
'data_type' => 'Array',
],
[
'name' => 'entity_type',
'title' => E::ts('Block Entity'),
'description' => 'Block used for this entity type',
],
[
'name' => 'join_entity',
'title' => E::ts('Join Entity'),
'description' => 'Used for blocks that join a sub-entity (e.g. Emails for a Contact)',
],
[
'name' => 'title',
'title' => E::ts('Title'),
'required' => $self->getAction() === 'create',
],
[
'name' => 'description',
'title' => E::ts('Description'),
],
[
'name' => 'placement',
'title' => E::ts('Placement'),
'pseudoconstant' => ['optionGroupName' => 'afform_placement'],
'data_type' => 'Array',
],
[
'name' => 'summary_contact_type',
'title' => E::ts('Summary Contact Type'),
'data_type' => 'Array',
'options' => \CRM_Contact_BAO_ContactType::contactTypePairs(),
],
[
'name' => 'summary_weight',
'title' => E::ts('Order'),
'data_type' => 'Integer',
],
[
'name' => 'icon',
'title' => E::ts('Icon'),
'description' => 'Icon shown in the contact summary tab',
],
[
'name' => 'server_route',
'title' => E::ts('Page Route'),
],
[
'name' => 'is_public',
'title' => E::ts('Is Public'),
'data_type' => 'Boolean',
'default_value' => FALSE,
],
[
'name' => 'permission',
'title' => E::ts('Permission'),
'data_type' => 'Array',
'default_value' => ['access CiviCRM'],
],
[
'name' => 'permission_operator',
'title' => E::ts('Permission Operator'),
'data_type' => 'String',
'default_value' => 'AND',
'options' => \CRM_Core_SelectValues::andOr(),
],
[
'name' => 'redirect',
'title' => E::ts('Post-Submit Page'),
],
[
'name' => 'submit_enabled',
'title' => E::ts('Allow Submissions'),
'data_type' => 'Boolean',
'default_value' => TRUE,
],
[
'name' => 'submit_limit',
'title' => E::ts('Maximum Submissions'),
'data_type' => 'Integer',
],
[
'name' => 'create_submission',
'title' => E::ts('Log Submissions'),
'data_type' => 'Boolean',
],
[
'name' => 'manual_processing',
'data_type' => 'Boolean',
],
[
'name' => 'allow_verification_by_email',
'data_type' => 'Boolean',
],
[
'name' => 'email_confirmation_template_id',
'data_type' => 'Integer',
],
[
'name' => 'navigation',
'title' => E::ts('Navigation Menu'),
'data_type' => 'Array',
'description' => 'Insert into navigation menu {parent: string, label: string, weight: int}',
],
[
'name' => 'layout',
'title' => E::ts('Layout'),
'data_type' => 'Array',
'description' => 'HTML form layout; format is controlled by layoutFormat param',
],
[
'name' => 'modified_date',
'title' => E::ts('Date Modified'),
'data_type' => 'Timestamp',
'readonly' => TRUE,
],
];
// Calculated fields returned by get action
if ($self->getAction() === 'get') {
$fields[] = [
'name' => 'module_name',
'type' => 'Extra',
'description' => 'Name of generated Angular module (CamelCase)',
'readonly' => TRUE,
];
$fields[] = [
'name' => 'directive_name',
'type' => 'Extra',
'description' => 'Html tag name to invoke this form (dash-case)',
'readonly' => TRUE,
];
$fields[] = [
'name' => 'submission_count',
'type' => 'Extra',
'data_type' => 'Integer',
'input_type' => 'Number',
'description' => 'Number of submission records for this form',
'readonly' => TRUE,
];
$fields[] = [
'name' => 'submission_date',
'type' => 'Extra',
'data_type' => 'Timestamp',
'input_type' => 'Date',
'description' => 'Date & time of last form submission',
'readonly' => TRUE,
];
$fields[] = [
'name' => 'submit_currently_open',
'type' => 'Extra',
'data_type' => 'Boolean',
'input_type' => 'Select',
'description' => 'Based on settings and current submission count, is the form open for submissions',
'readonly' => TRUE,
];
$fields[] = [
'name' => 'has_local',
'type' => 'Extra',
'data_type' => 'Boolean',
'description' => 'Whether a local copy is saved on site',
'readonly' => TRUE,
];
$fields[] = [
'name' => 'has_base',
'type' => 'Extra',
'data_type' => 'Boolean',
'description' => 'Is provided by an extension',
'readonly' => TRUE,
];
$fields[] = [
'name' => 'base_module',
'type' => 'Extra',
'data_type' => 'String',
'description' => 'Name of extension which provides this form',
'readonly' => TRUE,
'pseudoconstant' => ['callback' => ['CRM_Core_BAO_Managed', 'getBaseModules']],
];
$fields[] = [
'name' => 'search_displays',
'type' => 'Extra',
'data_type' => 'Array',
'readonly' => TRUE,
'description' => 'Embedded search displays, formatted like ["search-name.display-name"]',
];
}

return $fields;
}))->setCheckPermissions($checkPermissions);
return (new Generic\DAOGetFieldsAction('Afform', __FUNCTION__))
->setCheckPermissions($checkPermissions);
}

/**
Expand Down
Loading