Update contactType form to support icons and deprecate image_URL
authorColeman Watts <coleman@civicrm.org>
Sat, 2 Apr 2022 16:13:47 +0000 (12:13 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 4 Apr 2022 01:33:49 +0000 (21:33 -0400)
CRM/Admin/Form/ContactType.php
templates/CRM/Admin/Form/ContactType.tpl
templates/CRM/Admin/Page/ContactType.hlp

index ac90dbeace908586991d7b86561f97919fe201f9..386bd4785c49c0799a828d148a90ee53d7e0a327 100644 (file)
@@ -51,7 +51,15 @@ class CRM_Admin_Form_ContactType extends CRM_Admin_Form {
         $enabled->freeze();
       }
     }
-    $this->addElement('text', 'image_URL', ts('Image URL'));
+    // TODO: Remove when dropping image_URL column
+    if ($this->_id) {
+      $imageUrl = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $this->_id, 'image_URL');
+      if ($imageUrl) {
+        $this->addElement('text', 'image_URL', ts('Image URL'));
+      }
+    }
+    $this->assign('hasImageUrl', !empty($imageUrl));
+    $this->add('text', 'icon', ts('Icon'), ['class' => 'crm-icon-picker', 'title' => ts('Choose Icon'), 'allowClear' => TRUE]);
     $this->add('text', 'description', ts('Description'),
       CRM_Core_DAO::getAttribute('CRM_Contact_DAO_ContactType', 'description')
     );
@@ -122,6 +130,11 @@ class CRM_Admin_Form_ContactType extends CRM_Admin_Form {
       }
     }
 
+    // If icon is set, it overrides image_URL
+    if (!empty($params['icon'])) {
+      $params['image_URL'] = '';
+    }
+
     $contactType = CRM_Contact_BAO_ContactType::add($params);
     CRM_Core_Session::setStatus(ts("The Contact Type '%1' has been saved.",
       [1 => $contactType->label]
index 4ecf6016501ac2909e9c6fe90cedd22e1c2a941a..527eec758c395af155724019972ccdb3fc7c7d6b 100644 (file)
              <td>{ts}{$contactTypeName}{/ts} {ts}(built-in){/ts}</td>
            {/if}
    </tr>
-   <tr class="crm-contact-type-form-block-image_URL">
-      <td class="label">{$form.image_URL.label} {help id="id-image_URL"}</td>
-      <td>{$form.image_URL.html|crmAddClass:'huge40'}</td>
+   {if $hasImageUrl}
+     <tr class="crm-contact-type-form-block-image_URL">
+        <td class="label">{$form.image_URL.label}</td>
+        <td>{$form.image_URL.html|crmAddClass:'huge40'}</td>
+     </tr>
+     <tr class="description status-warning">
+       <td></td><td>{ts}Support for Image URL will be dropped in the future. Please select an icon instead.{/ts}</td>
+     </tr>
+   {/if}
+   <tr class="crm-contact-type-form-block-icon">
+     <td class="label">{$form.icon.label}</td>
+     <td>{$form.icon.html}</td>
    </tr>
    <tr class="crm-contact-type-form-block-description">
      <td class="label">{$form.description.label}
index 0643d015d66f0ac99787476fd81a48975fd71a25..a0ce38eb24eed3e795a2f1caab8e9f061d8f3484 100644 (file)
 {htxt id="id-contactSubtype-intro"}
 {ts}CiviCRM comes with 3 basic (built-in) contact types: Individual, Household, and Organization. You can create additional contact types based on these basic types to further differentiate contacts (for example you might create Student, Parent, Staff, and /or Volunteer "subtypes" from the basic Individual type...). You can also re-name the built-in types. Contact subtypes are especially useful when you need to collect and display different sets of custom data for different types of contacts.{/ts}
 {/htxt}
-
-{htxt id="id-image_URL-title"}
-  {ts}Contact Type Icon{/ts}
-{/htxt}
-{htxt id="id-image_URL"}
-<div>{ts 1='<span class="font-italic">sites/.../files</span>' 2='<span class="font-italic">media</span>'}Use this field to set your own icon for this Contact Type. Icon images should be 16 x 16 pixels for best fit. Enter a relative or complete URL to the image file location. Use a location outside of your CiviCRM code directory to reduce the likelihood of losing your image files during an upgrade. (For Drupal sites, you might want to use the %1 directory. For Joomla sites, the consider using the %2 directory.){/ts}</div>
- Examples:
-  <ul>
-    <li>{ts}Relative URL for a default Drupal site:{/ts}<br /><span class="font-italic">../../../default/files/volunteer_contact_icon.png</span></li>
-    <li>{ts}Complete URL for icon accessible from an external location:{/ts}<br /><span class="font-italic">http://www.example.com/images/new_icon.gif</span></li>
-  </ul>
-{/htxt}