Skip to content
Snippets Groups Projects
Commit 22877e0f authored by Seamus Lee's avatar Seamus Lee
Browse files

#1913 Allow for schemas to be added by extensions if they are in the...

#1913 Allow for schemas to be added by extensions if they are in the format of <entityname>Model

Update test doc blocks
parent 32961834
No related branches found
No related tags found
No related merge requests found
......@@ -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");
}
}
}
......
......@@ -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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment