Make all Individual name fields configurable
authorOlaf Buddenhagen <antrik@digitalcourage.de>
Fri, 11 Oct 2013 16:29:38 +0000 (18:29 +0200)
committerOlaf Buddenhagen <antrik@digitalcourage.de>
Fri, 11 Oct 2013 17:16:54 +0000 (19:16 +0200)
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
CRM/Contact/Form/Edit/Individual.php
CRM/Upgrade/Incremental/php/FourFive.php
CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl
templates/CRM/Admin/Form/Preferences/Display.tpl
templates/CRM/Contact/Form/Edit/Individual.tpl
templates/CRM/Contact/Form/Inline/ContactName.tpl
xml/templates/civicrm_data.tpl
xml/templates/civicrm_navigation.tpl

index 6ec0ead1118291e338d5d9de66a9def7b8682300..5b205e0336392d0456cb14a05c719887f2053955 100644 (file)
@@ -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();
index d87f7dddc49a00fa6aa593b0749eebedb6db079c..692d8e5d3193a2b5a5b90494ab0f65da588cddaa 100644 (file)
@@ -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);
       }
     }
index 0f354b709e8470fec60f64a1835f4dd544a9e5c6..c125053e714a730907f47d695f8f70572b08315b 100644 (file)
@@ -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 . '12\ 114\ 115\ 116\ 117\ 1';
+
+    $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;
   }
 
index 3819bac89e4715803bc3dd2ee7def6199ed09c6a..e1519fc9af3a32167204ccacee55253fcc10fbba 100644 (file)
@@ -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);
index 3f0e6e7e5d705b00eae712abf469ad470d8d2191..104a07ea6b952b874347aec4de1aa68de48ee860 100644 (file)
     <tr class="crm-preferences-display-form-block-contact_edit_options">
       <td class="label">{$form.contact_edit_options.label}</td>
       <td>
-        <table style="width:80%">
+        <table style="width:90%">
           <tr>
-            <td style="width:40%">
+            <td style="width:30%">
+              <span class="label"><strong>{ts}Individual Name Fields{/ts}</strong></span>
+              <ul id="contactEditNameFields">
+                {foreach from=$nameFields item="title" key="opId"}
+                  <li id="preference-{$opId}-contactedit" class="ui-state-default ui-corner-all"
+                      style="padding-left:1px;">
+                    <span>{$form.contact_edit_options.$opId.html}</span>
+                  </li>
+                {/foreach}
+              </ul>
+            </td>
+            <td style="width:30%">
               <span class="label"><strong>{ts}Contact Details{/ts}</strong></span>
               <ul id="contactEditBlocks">
                 {foreach from=$contactBlocks item="title" key="opId"}
index 4fa5077911130b5f32a71fcd7ab3621258b1cda4..add9e30811f32b688576b718895a60574d342c8c 100644 (file)
@@ -92,18 +92,24 @@ cj(function($) {
       {$form.formal_title.html}
     </td>
     {/if}
+    {if $form.first_name}
     <td>
       {$form.first_name.label}<br /> 
       {$form.first_name.html}
     </td>
+    {/if}
+    {if $form.middle_name}
     <td>
       {$form.middle_name.label}<br />
       {$form.middle_name.html}
     </td>
+    {/if}
+    {if $form.last_name}
     <td>
       {$form.last_name.label}<br />
       {$form.last_name.html}
     </td>
+    {/if}
     {if $form.suffix_id}
     <td>
       {$form.suffix_id.label}<br/>
index 9397bf9802b3b37b5b4dfb5db1048949d899f04c..2a8c228192a15b1d4712073b0b653377ef4cea69 100644 (file)
         {$form.formal_title.html}
       </div>
     {/if}
-    <div class="crm-inline-edit-field">
-      {$form.first_name.label}<br /> 
-      {$form.first_name.html}
-    </div>
-    <div class="crm-inline-edit-field">
-      {$form.middle_name.label}<br />
-      {$form.middle_name.html}
-    </div>
-    <div class="crm-inline-edit-field">
-      {$form.last_name.label}<br />
-      {$form.last_name.html}
-    </div>
+    {if $form.first_name}
+      <div class="crm-inline-edit-field">
+        {$form.first_name.label}<br /> 
+        {$form.first_name.html}
+      </div>
+    {/if}
+    {if $form.middle_name}
+      <div class="crm-inline-edit-field">
+        {$form.middle_name.label}<br />
+        {$form.middle_name.html}
+      </div>
+    {/if}
+    {if $form.last_name}
+      <div class="crm-inline-edit-field">
+        {$form.last_name.label}<br />
+        {$form.last_name.html}
+      </div>
+    {/if}
     {if $form.suffix_id}
       <div class="crm-inline-edit-field">
         {$form.suffix_id.label}<br/>
index 121f4ffbf3d3a4549d3caa94184874ebda274222..c067bd37ddc66a84d574d631c50ad09db55ca8df 100644 (file)
@@ -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),
index 8c9424a9f030f15444f1f63a9f90731c80390228..efffc96bc2c72511698b122a06ba59c015ad1b55 100644 (file)
@@ -36,7 +36,7 @@ INSERT INTO civicrm_setting
 VALUES
   ( @domainID, NULL, 1, 'CiviCRM Preferences', 'contact_view_options', '{serialize}\ 11\ 12\ 13\ 14\ 15\ 16\ 17\ 18\ 19\ 110\ 111\ 113\ 1{/serialize}' ),
   ( @domainID, NULL, 1, 'CiviCRM Preferences', 'contact_smart_group_display', '{serialize}1{/serialize}' ),
-  ( @domainID, NULL, 1, 'CiviCRM Preferences', 'contact_edit_options', '{serialize}\ 11\ 12\ 13\ 14\ 15\ 16\ 17\ 18\ 19\ 111\ 1{/serialize}' ),
+  ( @domainID, NULL, 1, 'CiviCRM Preferences', 'contact_edit_options', '{serialize}\ 11\ 12\ 13\ 14\ 15\ 16\ 17\ 18\ 19\ 111\ 112\ 114\ 115\ 116\ 117\ 1{/serialize}' ),
   ( @domainID, NULL, 1, 'CiviCRM Preferences', 'advanced_search_options', '{serialize}\ 11\ 12\ 13\ 14\ 15\ 16\ 17\ 18\ 19\ 110\ 111\ 112\ 113\ 115\ 116\ 117\ 118\ 119\ 1{/serialize}' ),
   ( @domainID, NULL, 1, 'CiviCRM Preferences', 'user_dashboard_options', '{serialize}\ 11\ 12\ 13\ 14\ 15\ 17\ 18\ 1{/serialize}' ),
   ( @domainID, NULL, 1, 'CiviCRM Preferences', 'address_options', '{serialize}\ 11\ 12\ 13\ 14\ 15\ 16\ 18\ 19\ 110\ 111\ 1{/serialize}' ),