Partial converstion of Profile form to be an entity form, fixes translatability for...
authoreileen <emcnaughton@wikimedia.org>
Thu, 15 Nov 2018 22:44:39 +0000 (11:44 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 15 Nov 2018 23:00:59 +0000 (12:00 +1300)
CRM/Core/DAO/UFGroup.php
CRM/UF/Form/Group.php
templates/CRM/UF/Form/Group.tpl
xml/schema/Core/UFGroup.xml

index 1480a27e7b2e7c0f2578b4c27c4a20bab79e3560..4667ad2c48c929b611eba39ee110cd67760326a2 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Core/UFGroup.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:a48f9522d0bd2e1d485064ebfc66f9a2)
+ * (GenCodeChecksum:d0a806459507dc6b32ba955e4e899358)
  */
 
 /**
@@ -291,7 +291,7 @@ class CRM_Core_DAO_UFGroup extends CRM_Core_DAO {
         'title' => [
           'name' => 'title',
           'type' => CRM_Utils_Type::T_STRING,
-          'title' => ts('Title'),
+          'title' => ts('Profile Name'),
           'description' => ts('Form title.'),
           'required' => TRUE,
           'maxlength' => 64,
@@ -300,11 +300,14 @@ class CRM_Core_DAO_UFGroup extends CRM_Core_DAO {
           'entity' => 'UFGroup',
           'bao' => 'CRM_Core_BAO_UFGroup',
           'localizable' => 1,
+          'html' => [
+            'type' => 'Text',
+          ],
         ],
         'frontend_title' => [
           'name' => 'frontend_title',
           'type' => CRM_Utils_Type::T_STRING,
-          'title' => ts('Frontend Title'),
+          'title' => ts('Public Title'),
           'description' => ts('Profile Form Public title'),
           'maxlength' => 64,
           'size' => CRM_Utils_Type::BIG,
@@ -312,6 +315,9 @@ class CRM_Core_DAO_UFGroup extends CRM_Core_DAO {
           'entity' => 'UFGroup',
           'bao' => 'CRM_Core_BAO_UFGroup',
           'localizable' => 1,
+          'html' => [
+            'type' => 'Text',
+          ],
         ],
         'description' => [
           'name' => 'description',
index 9fcb8341766d4ee2fdef0e26e4735edbc17d14ee..933cfc537faed02aaea62709e58ef717860bad5f 100644 (file)
  *
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2018
- * $Id$
- *
  */
 
 /**
- *  This class is for UF Group
+ *  This class is for UF Group (Profile) configuration.
  */
 class CRM_UF_Form_Group extends CRM_Core_Form {
 
+  use CRM_Core_Form_EntityFormTrait;
+
+  /**
+   * Fields for the entity to be assigned to the template.
+   *
+   * Fields may have keys
+   *  - name (required to show in tpl from the array)
+   *  - description (optional, will appear below the field)
+   *  - not-auto-addable - this class will not attempt to add the field using addField.
+   *    (this will be automatically set if the field does not have html in it's metadata
+   *    or is not a core field on the form's entity).
+   *  - help (option) add help to the field - e.g ['id' => 'id-source', 'file' => 'CRM/Contact/Form/Contact']]
+   *  - template - use a field specific template to render this field
+   *  - required
+   *  - is_freeze (field should be frozen).
+   *
+   * @var array
+   */
+  protected $entityFields = [];
+
+  /**
+   * Set entity fields to be assigned to the form.
+   */
+  protected function setEntityFields() {
+    $this->entityFields = [
+      'title' => ['name' => 'title'],
+      'frontend_title' => ['name' => 'frontend_title'],
+      'description' => ['name' => 'description', 'help' => ['id' => 'id-description', 'file' => 'CRM/UF/Form/Group.hlp']],
+    ];
+  }
+
+  /**
+   * Explicitly declare the entity api name.
+   */
+  public function getDefaultEntity() {
+    return 'UFGroup';
+  }
+
   /**
    * The form id saved to the session for an update.
    *
@@ -57,8 +93,6 @@ class CRM_UF_Form_Group extends CRM_Core_Form {
 
   /**
    * Set variables up before form is built.
-   *
-   * @return void
    */
   public function preProcess() {
     // current form id
@@ -111,6 +145,7 @@ class CRM_UF_Form_Group extends CRM_Core_Form {
    * @return void
    */
   public function buildQuickForm() {
+    self::buildQuickEntityForm();
     if ($this->_action & (CRM_Core_Action::DISABLE | CRM_Core_Action::DELETE)) {
       if ($this->_action & (CRM_Core_Action::DISABLE)) {
         $display = 'Disable Profile';
@@ -132,12 +167,6 @@ class CRM_UF_Form_Group extends CRM_Core_Form {
       ));
       return;
     }
-    $this->applyFilter('__ALL__', 'trim');
-
-    // title
-    $this->add('text', 'title', ts('Profile Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'title'), TRUE);
-    $this->add('text', 'frontend_title', ts('Public Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'frontend_title'));
-    $this->add('textarea', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'description'));
 
     //add checkboxes
     $uf_group_type = array();
@@ -335,7 +364,7 @@ class CRM_UF_Form_Group extends CRM_Core_Form {
     }
     else {
       // get the submitted form values.
-      $params = $ids = array();
+      $ids = array();
       $params = $this->controller->exportValues($this->_name);
 
       if (!array_key_exists('is_active', $params)) {
@@ -386,4 +415,11 @@ class CRM_UF_Form_Group extends CRM_Core_Form {
     CRM_Utils_System::updateCategories();
   }
 
+  /**
+   * Set the delete message.
+   *
+   * We do this from the constructor in order to do a translation.
+   */
+  public function setDeleteMessage() {}
+
 }
index 5af929ddc6cdaf4c03bb163a98c68db263b221ce..6e86a4e8b27e07965c0e29421ada2b7921dc5844 100644 (file)
     </div>
 {else}
     <table class="form-layout">
-        <tr class="crm-uf_group-form-block-title">
-            <td class="label">{$form.title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_uf_group' field='title' id=$gid}{/if}</td>
-            <td class="html-adjust">{$form.title.html}</td>
-        </tr>
-        <tr class="crm-uf_group-form-block-frontend_title">
-            <td class="label">{$form.frontend_title.label}</td>
-            <td class="html-adjust">{$form.frontend_title.html}</td>
-        </tr>
-        <tr class="crm-uf_group-form-block-description">
-            <td class="label">{$form.description.label} {help id='id-description' file="CRM/UF/Form/Group.hlp"}</td>
-            <td class="html-adjust">{$form.description.html}</td>
+      {foreach from=$entityFields item=fieldSpec}
+        {assign var=fieldName value=$fieldSpec.name}
+        <tr class="crm-{$entityInClassFormat}-form-block-{$fieldName}">
+          {include file="CRM/Core/Form/Field.tpl"}
         </tr>
+      {/foreach}
         <tr class="crm-uf_group-form-block-uf_group_type">
             <td class="label">{$form.uf_group_type.label} {help id='id-used_for' file="CRM/UF/Form/Group.hlp"}</td>
             <td class="html-adjust">{$form.uf_group_type.html}&nbsp;{$otherModuleString}</td>
index 6339d9c6cfd3c88dbfae6899ed3772de8c9594cb..350273655b0e08f429ac1ecbe05b02b966df059c 100644 (file)
   </field>
   <field>
     <name>title</name>
+    <title>Profile Name</title>
     <type>varchar</type>
     <length>64</length>
     <localizable>true</localizable>
     <required>true</required>
+    <html>
+      <type>Text</type>
+    </html>
     <comment>Form title.</comment>
     <add>1.1</add>
   </field>
   <field>
     <name>frontend_title</name>
+    <title>Public Title</title>
     <type>varchar</type>
     <length>64</length>
     <localizable>true</localizable>
     <comment>Profile Form Public title</comment>
+    <html>
+      <type>Text</type>
+    </html>
     <add>4.7</add>
   </field>
   <field>