From 0103eaf090d0824a3a341d545267bef43414e9a6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 8 Jul 2015 13:52:13 -0400 Subject: [PATCH] CRM-16811 - Support markup fields in popup profile editor --- CRM/UF/Page/ProfileEditor.php | 22 +++++++++++++++++++++- api/v3/UFField.php | 2 +- js/model/crm.designer.js | 7 ++++++- js/model/crm.uf.js | 15 +++++++++++---- js/view/crm.designer.js | 7 ++++++- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/CRM/UF/Page/ProfileEditor.php b/CRM/UF/Page/ProfileEditor.php index dec8daa8d9..4a3709832d 100644 --- a/CRM/UF/Page/ProfileEditor.php +++ b/CRM/UF/Page/ProfileEditor.php @@ -102,10 +102,10 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page { $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': @@ -177,6 +177,26 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page { } } + // 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; } diff --git a/api/v3/UFField.php b/api/v3/UFField.php index 0db78222f5..bcb58c0f40 100644 --- a/api/v3/UFField.php +++ b/api/v3/UFField.php @@ -54,7 +54,7 @@ function civicrm_api3_uf_field_create($params) { $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); diff --git a/js/model/crm.designer.js b/js/model/crm.designer.js index 2553b157f6..752cf86415 100644 --- a/js/model/crm.designer.js +++ b/js/model/crm.designer.js @@ -70,7 +70,9 @@ 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; } @@ -95,6 +97,9 @@ * @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); }); diff --git a/js/model/crm.uf.js b/js/model/crm.uf.js index cc81507931..99d456e539 100644 --- a/js/model/crm.uf.js +++ b/js/model/crm.uf.js @@ -97,6 +97,7 @@ case 'Individual': case 'Organization': case 'Household': + case 'Formatting': return 'contact_1'; case 'Activity': return 'activity_1'; @@ -223,6 +224,9 @@ } }, 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); @@ -312,7 +316,9 @@ 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; } @@ -673,12 +679,13 @@ 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; diff --git a/js/view/crm.designer.js b/js/view/crm.designer.js index 1dc087c6b0..0be0f21340 100644 --- a/js/view/crm.designer.js +++ b/js/view/crm.designer.js @@ -761,6 +761,9 @@ 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, @@ -785,7 +788,9 @@ 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. -- 2.25.1