From 8b49cb50d3fe31fd9aa86f72f72a33b6a16233be Mon Sep 17 00:00:00 2001 From: Olaf Buddenhagen Date: Fri, 11 Oct 2013 18:29:38 +0200 Subject: [PATCH] Make all Individual name fields configurable Adding a third block to the 'contact_edit_options' setting, to allow controlling which of the various name fields (prefix, formal title, first name, middle name, last name, suffix) show up on the contact edit forms. (Both main form and quick edit of the contact name.) For now, the name fields can only be enabled or disabled; there is no support for changing the order in which they appear on the edit forms. While this could be handled trivially in the configuration UI (the code is already there for the other parts of 'contact_edit_options'), it would require a major change to how the actual name edit forms are constructed -- and I'm not even sure there is an actual use case for that... Note: This change doesn't affect the Display Name -- that one is still configured using the token-based template. Also, it doesn't affect all the other places where name fields are used (soft credits, honoree, billing contacts etc.): there are way too many of them, each implemented separately (and inconsistently). Again, the way forward seems to be centralising all name field handling in a common piece of code, and invoking that in all places dealing with Individual name fields... After merging this, sql/civicrm_generated.sql needs to be regenerated, to pick up the new option values and default setting. --- CRM/Admin/Form/Preferences/Display.php | 3 ++ CRM/Contact/Form/Edit/Individual.php | 25 ++++++++++++---- CRM/Upgrade/Incremental/php/FourFive.php | 22 ++++++++++++++ .../Incremental/sql/4.5.alpha1.mysql.tpl | 14 ++++++++- .../CRM/Admin/Form/Preferences/Display.tpl | 15 ++++++++-- .../CRM/Contact/Form/Edit/Individual.tpl | 6 ++++ .../CRM/Contact/Form/Inline/ContactName.tpl | 30 +++++++++++-------- xml/templates/civicrm_data.tpl | 6 ++++ xml/templates/civicrm_navigation.tpl | 2 +- 9 files changed, 101 insertions(+), 22 deletions(-) diff --git a/CRM/Admin/Form/Preferences/Display.php b/CRM/Admin/Form/Preferences/Display.php index 6ec0ead111..5b205e0336 100644 --- a/CRM/Admin/Form/Preferences/Display.php +++ b/CRM/Admin/Form/Preferences/Display.php @@ -189,6 +189,9 @@ class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences { $contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1'); $this->assign('contactBlocks', $contactBlocks); + $nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2'); + $this->assign('nameFields', $nameFields); + $this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences')); parent::buildQuickForm(); diff --git a/CRM/Contact/Form/Edit/Individual.php b/CRM/Contact/Form/Edit/Individual.php index d87f7dddc4..692d8e5d31 100644 --- a/CRM/Contact/Form/Edit/Individual.php +++ b/CRM/Contact/Form/Edit/Individual.php @@ -55,28 +55,41 @@ class CRM_Contact_Form_Edit_Individual { $form->applyFilter('__ALL__', 'trim'); if ( !$inlineEditMode || $inlineEditMode == 1 ) { + $nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'contact_edit_options', TRUE, NULL, + FALSE, 'name', TRUE, 'AND v.filter = 2' + ); + //prefix $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); - if (!empty($prefix)) { + if (isset($nameFields['Prefix']) && !empty($prefix)) { $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix); } $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); - $form->addElement('text', 'formal_title', ts('Title'), $attributes['formal_title']); + if (isset($nameFields['Formal Title'])) { + $form->addElement('text', 'formal_title', ts('Title'), $attributes['formal_title']); + } // first_name - $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); + if (isset($nameFields['First Name'])) { + $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); + } //middle_name - $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']); + if (isset($nameFields['Middle Name'])) { + $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']); + } // last_name - $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']); + if (isset($nameFields['Last Name'])) { + $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']); + } // suffix $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'); - if ($suffix) { + if (isset($nameFields['Suffix']) && $suffix) { $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix); } } diff --git a/CRM/Upgrade/Incremental/php/FourFive.php b/CRM/Upgrade/Incremental/php/FourFive.php index 0f354b709e..c125053e71 100644 --- a/CRM/Upgrade/Incremental/php/FourFive.php +++ b/CRM/Upgrade/Incremental/php/FourFive.php @@ -65,6 +65,28 @@ class CRM_Upgrade_Incremental_php_FourFive { // task to process sql $this->addTask(ts('Upgrade DB to 4.5.alpha1: SQL'), 'task_4_5_x_runSql', $rev); + $this->addTask(ts('Set default for Individual name fields configuration'), 'addNameFieldOptions'); + + return TRUE; + } + + /** + * Add defaults for the newly introduced name fields configuration in 'contact_edit_options' setting + * + * @return bool TRUE for success + */ + static function addNameFieldOptions(CRM_Queue_TaskContext $ctx) { + $query = "SELECT `value` FROM `civicrm_setting` WHERE `group_name` = 'CiviCRM Preferences' AND `name` = 'contact_edit_options'"; + $dao = CRM_Core_DAO::executeQuery($query); + $dao->fetch(); + $oldValue = unserialize($dao->value); + + $newValue = $oldValue . '1214151617'; + + $query = "UPDATE `civicrm_setting` SET `value` = %1 WHERE `group_name` = 'CiviCRM Preferences' AND `name` = 'contact_edit_options'"; + $params = array(1 => array(serialize($newValue), 'String')); + CRM_Core_DAO::executeQuery($query, $params); + return TRUE; } diff --git a/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl index 3819bac89e..e1519fc9af 100644 --- a/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl @@ -36,4 +36,16 @@ VALUES ( {$domainID}, 'civicrm/admin/options/communication_style&group=communication_style&reset=1', '{ts escape="sql" skip="true"}Communication Style Options{/ts}', 'Communication Style Options', 'administer CiviCRM', '', @parent_id, '1', NULL, @add_weight ); -- CRM-9988 Change world region of Panama country to America South, Central, North and Caribbean -UPDATE `civicrm_country` SET `region_id` = 2 WHERE `id` = 1166; \ No newline at end of file +UPDATE `civicrm_country` SET `region_id` = 2 WHERE `id` = 1166; + +SELECT @option_group_id_contact_edit_options := max(id) from civicrm_option_group where name = 'contact_edit_options'; + +INSERT INTO + `civicrm_option_value` (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`) +VALUES + (@option_group_id_contact_edit_options, {localize}'{ts escape="sql"}Prefix{/ts}'{/localize} , 12, 'Prefix' , NULL, 2, NULL, 12, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_contact_edit_options, {localize}'{ts escape="sql"}Formal Title{/ts}'{/localize}, 13, 'Formal Title', NULL, 2, NULL, 13, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_contact_edit_options, {localize}'{ts escape="sql"}First Name{/ts}'{/localize} , 14, 'First Name' , NULL, 2, NULL, 14, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_contact_edit_options, {localize}'{ts escape="sql"}Middle Name{/ts}'{/localize} , 15, 'Middle Name' , NULL, 2, NULL, 15, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_contact_edit_options, {localize}'{ts escape="sql"}Last Name{/ts}'{/localize} , 16, 'Last Name' , NULL, 2, NULL, 16, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_contact_edit_options, {localize}'{ts escape="sql"}Suffix{/ts}'{/localize} , 17, 'Suffix' , NULL, 2, NULL, 17, NULL, 0, 0, 1, NULL, NULL); diff --git a/templates/CRM/Admin/Form/Preferences/Display.tpl b/templates/CRM/Admin/Form/Preferences/Display.tpl index 3f0e6e7e5d..104a07ea6b 100644 --- a/templates/CRM/Admin/Form/Preferences/Display.tpl +++ b/templates/CRM/Admin/Form/Preferences/Display.tpl @@ -57,9 +57,20 @@ {$form.contact_edit_options.label} - +
- + {/if} + {if $form.first_name} + {/if} + {if $form.middle_name} + {/if} + {if $form.last_name} + {/if} {if $form.suffix_id}
+ + {ts}Individual Name Fields{/ts} +
    + {foreach from=$nameFields item="title" key="opId"} +
  • + {$form.contact_edit_options.$opId.html} +
  • + {/foreach} +
+
{ts}Contact Details{/ts}
    {foreach from=$contactBlocks item="title" key="opId"} diff --git a/templates/CRM/Contact/Form/Edit/Individual.tpl b/templates/CRM/Contact/Form/Edit/Individual.tpl index 4fa5077911..add9e30811 100644 --- a/templates/CRM/Contact/Form/Edit/Individual.tpl +++ b/templates/CRM/Contact/Form/Edit/Individual.tpl @@ -92,18 +92,24 @@ cj(function($) { {$form.formal_title.html}
{$form.first_name.label}
{$form.first_name.html}
{$form.middle_name.label}
{$form.middle_name.html}
{$form.last_name.label}
{$form.last_name.html}
{$form.suffix_id.label}
diff --git a/templates/CRM/Contact/Form/Inline/ContactName.tpl b/templates/CRM/Contact/Form/Inline/ContactName.tpl index 9397bf9802..2a8c228192 100644 --- a/templates/CRM/Contact/Form/Inline/ContactName.tpl +++ b/templates/CRM/Contact/Form/Inline/ContactName.tpl @@ -42,18 +42,24 @@ {$form.formal_title.html} {/if} -
- {$form.first_name.label}
- {$form.first_name.html} -
-
- {$form.middle_name.label}
- {$form.middle_name.html} -
-
- {$form.last_name.label}
- {$form.last_name.html} -
+ {if $form.first_name} +
+ {$form.first_name.label}
+ {$form.first_name.html} +
+ {/if} + {if $form.middle_name} +
+ {$form.middle_name.label}
+ {$form.middle_name.html} +
+ {/if} + {if $form.last_name} +
+ {$form.last_name.label}
+ {$form.last_name.html} +
+ {/if} {if $form.suffix_id}
{$form.suffix_id.label}
diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index 121f4ffbf3..c067bd37dd 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -462,6 +462,12 @@ VALUES (@option_group_id_ceOpt, '{ts escape="sql"}Instant Messenger{/ts}' , 9, 'IM', NULL, 1, NULL, 9, NULL, 0, 0, 1, NULL, NULL), (@option_group_id_ceOpt, '{ts escape="sql"}Open ID{/ts}' , 10, 'OpenID', NULL, 1, NULL, 10, NULL, 0, 0, 1, NULL, NULL), (@option_group_id_ceOpt, '{ts escape="sql"}Website{/ts}' , 11, 'Website', NULL, 1, NULL, 11, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_ceOpt, '{ts escape="sql"}Prefix{/ts}' , 12, 'Prefix', NULL, 2, NULL, 12, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_ceOpt, '{ts escape="sql"}Formal Title{/ts}' , 13, 'Formal Title', NULL, 2, NULL, 13, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_ceOpt, '{ts escape="sql"}First Name{/ts}' , 14, 'First Name', NULL, 2, NULL, 14, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_ceOpt, '{ts escape="sql"}Middle Name{/ts}' , 15, 'Middle Name', NULL, 2, NULL, 15, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_ceOpt, '{ts escape="sql"}Last Name{/ts}' , 16, 'Last Name', NULL, 2, NULL, 16, NULL, 0, 0, 1, NULL, NULL), + (@option_group_id_ceOpt, '{ts escape="sql"}Suffix{/ts}' , 17, 'Suffix', NULL, 2, NULL, 17, NULL, 0, 0, 1, NULL, NULL), (@option_group_id_asOpt, '{ts escape="sql"}Address Fields{/ts}' , 1, 'location', NULL, 0, NULL, 1, NULL, 0, 0, 1, NULL, NULL), (@option_group_id_asOpt, '{ts escape="sql"}Custom Fields{/ts}' , 2, 'custom', NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL), diff --git a/xml/templates/civicrm_navigation.tpl b/xml/templates/civicrm_navigation.tpl index 8c9424a9f0..efffc96bc2 100644 --- a/xml/templates/civicrm_navigation.tpl +++ b/xml/templates/civicrm_navigation.tpl @@ -36,7 +36,7 @@ INSERT INTO civicrm_setting VALUES ( @domainID, NULL, 1, 'CiviCRM Preferences', 'contact_view_options', '{serialize}123456789101113{/serialize}' ), ( @domainID, NULL, 1, 'CiviCRM Preferences', 'contact_smart_group_display', '{serialize}1{/serialize}' ), - ( @domainID, NULL, 1, 'CiviCRM Preferences', 'contact_edit_options', '{serialize}12345678911{/serialize}' ), + ( @domainID, NULL, 1, 'CiviCRM Preferences', 'contact_edit_options', '{serialize}123456789111214151617{/serialize}' ), ( @domainID, NULL, 1, 'CiviCRM Preferences', 'advanced_search_options', '{serialize}123456789101112131516171819{/serialize}' ), ( @domainID, NULL, 1, 'CiviCRM Preferences', 'user_dashboard_options', '{serialize}1234578{/serialize}' ), ( @domainID, NULL, 1, 'CiviCRM Preferences', 'address_options', '{serialize}123456891011{/serialize}' ), -- 2.25.1