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 - hide disabled contact types & entities from disabled components/extensions #20283

Merged
merged 1 commit into from
May 13, 2021
Merged
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
38 changes: 19 additions & 19 deletions ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,27 @@ public static function getAfformEntity($entityName) {
}

/**
* @param $entityName
* @return array
* Get info about an api entity, with special handling for contact types
* @param string $entityName
* @return array|null
*/
public static function getApiEntity($entityName) {
if (in_array($entityName, ['Individual', 'Household', 'Organization'])) {
$contactTypes = \CRM_Contact_BAO_ContactType::basicTypeInfo();
public static function getApiEntity(string $entityName) {
$contactTypes = \CRM_Contact_BAO_ContactType::basicTypeInfo();
if (isset($contactTypes[$entityName])) {
return [
'entity' => 'Contact',
'contact_type' => $entityName,
'label' => $contactTypes[$entityName]['label'],
];
}
$info = \Civi\Api4\Entity::get(FALSE)
->addWhere('name', '=', $entityName)
->addSelect('title', 'icon')
->execute()->first();
if (!$info) {
// Disabled contact type or nonexistent api entity
return NULL;
}
return [
'entity' => $entityName,
'label' => $info['title'],
Expand Down Expand Up @@ -127,21 +133,15 @@ public static function getGuiSettings() {
if (is_dir($dir)) {
// Scan for entities
foreach (glob($dir . 'afformEntities/*.php') as $file) {
$entity = include $file;
$afformEntity = basename($file, '.php');
// Contact pseudo-entities (Individual, Organization, Household) get special treatment,
// notably their fields are pre-loaded since they are both commonly-used and nonstandard
if (!empty($entity['contact_type'])) {
// Skip disabled contact types
if (!isset($contactTypes[$entity['contact_type']])) {
continue;
}
$entity['label'] = $contactTypes[$entity['contact_type']]['label'];
}
elseif (empty($entity['label']) || empty($entity['icon'])) {
$entity += self::getApiEntity($entity['entity']);
$entityInfo = include $file;
$entityName = basename($file, '.php');
$apiInfo = self::getApiEntity($entityInfo['entity'] ?? $entityName);
// Skip disabled contact types & entities from disabled components/extensions
if (!$apiInfo) {
continue;
}
$data['entities'][$afformEntity] = $entity;
$entityInfo += $apiInfo;
$data['entities'][$entityName] = $entityInfo;
}
// Scan for input types
foreach (glob($dir . 'ang/afGuiEditor/inputType/*.html') as $file) {
Expand Down
1 change: 0 additions & 1 deletion ext/afform/admin/afformEntities/Activity.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
return [
'entity' => 'Activity',
'defaults' => "{'url-autofill': '1'}",
'boilerplate' => [
['#tag' => 'af-field', 'name' => 'subject'],
Expand Down
2 changes: 0 additions & 2 deletions ext/afform/admin/afformEntities/Household.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
return [
'entity' => 'Contact',
'contact_type' => 'Household',
'defaults' => "{
data: {
contact_type: 'Household',
Expand Down
2 changes: 0 additions & 2 deletions ext/afform/admin/afformEntities/Individual.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
return [
'entity' => 'Contact',
'contact_type' => 'Individual',
'defaults' => "{
data: {
contact_type: 'Individual',
Expand Down
2 changes: 0 additions & 2 deletions ext/afform/admin/afformEntities/Organization.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
return [
'entity' => 'Contact',
'contact_type' => 'Organization',
'defaults' => "{
data: {
contact_type: 'Organization',
Expand Down