dev/core#1913 Allow for schemas to be added by extensions if they are in the format...
authorSeamus Lee <seamuslee001@gmail.com>
Tue, 28 Jul 2020 23:52:31 +0000 (09:52 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Wed, 29 Jul 2020 00:33:45 +0000 (10:33 +1000)
Update test doc blocks

CRM/UF/Page/ProfileEditor.php
tests/phpunit/CRM/UF/Page/ProfileEditorTest.php

index 466278a3fa460bd9860a9363fb660cb353f680d5..061b7ce742bc9082e922f67ce3c2d33bf5e6eeee 100644 (file)
@@ -192,7 +192,20 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page {
           break;
 
         default:
-          throw new CRM_Core_Exception("Unrecognized entity type: $entityType");
+          if (strpos($entityType, 'Model') !== FALSE) {
+            $entity = str_replace('Model', '', $entityType);
+            $backboneModel = self::convertCiviModelToBackboneModel(
+              $entity,
+              ts('%1', [1 => $entity]),
+              $availableFields
+            );
+            if (!empty($backboneModel['schema'])) {
+              $civiSchema[$entityType] = $backboneModel;
+            }
+          }
+          if (!isset($civiSchema[$entityType])) {
+            throw new CRM_Core_Exception("Unrecognized entity type: $entityType");
+          }
       }
     }
 
index 6ee808a4356161ad6d23ba03d79d33f9bd11f39b..7ea035594e0d4d89fdd0c2eacfa270b9d8bd8f0a 100644 (file)
@@ -45,4 +45,28 @@ class CRM_UF_Page_ProfileEditorTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * Test that with an extension adding in UF Fields for an enttiy that isn't supplied by Core e.g. Grant
+   * That an appropriate entitytype can be specfied in the backbone.marionette profile editor e.g. GrantModel
+   */
+  public function testGetSchemaWithHooks() {
+    CRM_Utils_Hook::singleton()->setHook('civicrm_alterUFFields', [$this, 'hook_civicrm_alterUFFIelds']);
+    $schema = CRM_UF_Page_ProfileEditor::getSchema(['IndividualModel', 'GrantModel']);
+    $this->assertEquals('Grant', $schema['GrantModel']['schema']['grant_decision_date']['civiFieldType']);
+  }
+
+  /**
+   * Tries to load up the profile schema for a model where there is no corresponding set of fields avaliable.
+   *
+   * @expectedException \CRM_Core_Exception
+   */
+  public function testGetSchemaWithHooksWithInvalidModel() {
+    CRM_Utils_Hook::singleton()->setHook('civicrm_alterUFFields', [$this, 'hook_civicrm_alterUFFIelds']);
+    $schema = CRM_UF_Page_ProfileEditor::getSchema(['IndividualModel', 'GrantModel', 'PledgeModel']);
+  }
+
+  public function hook_civicrm_alterUFFIelds(&$fields) {
+    $fields['Grant'] = CRM_Grant_BAO_Grant::exportableFields();
+  }
+
 }