$entityTypes = array_unique($entityTypes);
$availableFields = NULL;
+ $civiSchema = array();
foreach ($entityTypes as $entityType) {
if (!$availableFields) {
$availableFields = CRM_Core_BAO_UFField::getAvailableFieldsFlat();
- //dpm($availableFields);
}
switch ($entityType) {
case 'IndividualModel':
}
}
+ // Adding the oddball "formatting" field here because there's no other place to put it
+ foreach (array('Individual', 'Organization', 'Household') as $type) {
+ if (isset($civiSchema[$type . 'Model'])) {
+ $civiSchema[$type . 'Model']['schema'] += array(
+ 'formatting' => array(
+ 'type' => 'Markup',
+ 'title' => ts('Free HTML'),
+ 'civiFieldType' => 'Formatting',
+ 'section' => 'formatting',
+ ),
+ );
+ $civiSchema[$type . 'Model']['sections'] += array(
+ 'formatting' => array(
+ 'title' => ts('Formatting'),
+ 'is_addable' => FALSE,
+ ),
+ );
+ }
+ }
+
return $civiSchema;
}
$location_type_id = CRM_Utils_Array::value('location_type_id', $params, CRM_Utils_Array::value('website_type_id', $params));
$phone_type = CRM_Utils_Array::value('phone_type_id', $params, CRM_Utils_Array::value('phone_type', $params));
- if (!CRM_Core_BAO_UFField::isValidFieldName($field_name)) {
+ if (strpos($field_name, 'formatting') !== 0 && !CRM_Core_BAO_UFField::isValidFieldName($field_name)) {
throw new API_Exception('The field_name is not valid');
}
$params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
label: this.getLabel(),
entity_name: this.get('entityName'),
field_type: this.getFieldSchema().civiFieldType,
- field_name: this.get('fieldName')
+ // For some reason the 'formatting' field gets a random number appended in core so we mimic that here.
+ // TODO: Why?
+ field_name: this.get('fieldName') == 'formatting' ? 'formatting_' + (Math.floor(Math.random() * 8999) + 1000) : this.get('fieldName')
});
return model;
}
* @return {CRM.Designer.PaletteFieldModel}
*/
getFieldByName: function(entityName, fieldName) {
+ if (fieldName.indexOf('formatting') === 0) {
+ fieldName = 'formatting';
+ }
return this.find(function(paletteFieldModel) {
return ((!entityName || paletteFieldModel.get('entityName') == entityName) && paletteFieldModel.get('fieldName') == fieldName);
});
case 'Individual':
case 'Organization':
case 'Household':
+ case 'Formatting':
return 'contact_1';
case 'Activity':
return 'activity_1';
}
},
initialize: function() {
+ if (this.get('field_name').indexOf('formatting') === 0) {
+ this.schema.help_pre.title = ts('Markup');
+ }
this.set('entity_name', CRM.UF.guessEntityName(this.get('field_type')));
this.on("rel:ufGroupModel", this.applyDefaults, this);
this.on('change', watchChanges);
var entity_name = ufFieldModel.get('entity_name'),
field_name = ufFieldModel.get('field_name'),
fieldSchema = this.getRel('ufGroupModel').getFieldSchema(ufFieldModel.get('entity_name'), ufFieldModel.get('field_name'));
-
+ if (field_name.indexOf('formatting') === 0) {
+ return true;
+ }
if (! fieldSchema) {
return false;
}
return ufEntity.getModelClass();
},
getFieldSchema: function(entity_name, field_name) {
+ if (field_name.indexOf('formatting') === 0) {
+ field_name = 'formatting';
+ }
var modelClass = this.getModelClass(entity_name);
var fieldSchema = modelClass.prototype.schema[field_name];
if (!fieldSchema) {
- if (console.log) {
- console.log('Failed to locate field: ' + entity_name + "." + field_name);
- }
+ CRM.console('warn', 'Failed to locate field: ' + entity_name + "." + field_name);
return null;
}
return fieldSchema;
if (!this.options.fieldSchema.civiIsMultiple) {
fields = _.without(fields, 'is_multi_summary');
}
+ if (this.options.fieldSchema.type == 'Markup') {
+ fields = _.without(fields, 'is_required', 'is_view', 'visibility', 'in_selector', 'is_searchable', 'help_post');
+ }
this.form = new Backbone.Form({
model: this.model,
if (!this.model.isInSelectorAllowed() && this.model.get('in_selector') != "0") {
this.model.set('in_selector', "0");
- this.form.setValue('in_selector', "0");
+ if (this.form.fields.in_selector) {
+ this.form.setValue('in_selector', "0");
+ }
// TODO: It might be nicer if we didn't completely discard in_selector -- e.g.
// if the value could be restored when the user isInSelectorAllowed becomes true
// again. However, I haven't found a simple way to do this.