Skip to content

Commit

Permalink
Merge pull request #20283 from colemanw/afformEnabledEntities
Browse files Browse the repository at this point in the history
Afform - hide disabled contact types & entities from disabled components/extensions
  • Loading branch information
seamuslee001 authored May 13, 2021
2 parents 175b0a0 + 7ed57b0 commit 69cc131
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
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

0 comments on commit 69cc131

Please sign in to comment.