Put text inside label tags for recurring contribution selection
authorLars SG <lars@wildsight.ca>
Sat, 17 Apr 2021 15:22:09 +0000 (09:22 -0600)
committerLars SG <lars@wildsight.ca>
Sat, 17 Apr 2021 15:22:09 +0000 (09:22 -0600)
All text now inside label tags except for the "for" when offering instalments. This allows styling.

CRM/Contribute/Form/Contribution/Main.php
templates/CRM/Contribute/Form/Contribution/Main.tpl

index b6c29b41fcc0f6f6b5c01fb2b655daf7ef0b3992..64d7ee6df33eae3150719f2281759ecd5d6f0f6f 100644 (file)
@@ -730,17 +730,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       ]));
     }
 
-    $form->add('checkbox', 'is_recur', ts('I want to contribute this amount'), NULL);
-
-    if (!empty($form->_values['is_recur_interval']) || $className == 'CRM_Contribute_Form_Contribution') {
-      $form->add('text', 'frequency_interval', ts('Every'), $attributes['frequency_interval'] + ['aria-label' => ts('Every')]);
-      $form->addRule('frequency_interval', ts('Frequency must be a whole number (EXAMPLE: Every 3 months).'), 'integer');
-    }
-    else {
-      // make sure frequency_interval is submitted as 1 if given no choice to user.
-      $form->add('hidden', 'frequency_interval', 1);
-    }
-
     $frUnits = $form->_values['recur_frequency_unit'] ?? NULL;
     if (empty($frUnits) &&
       $className == 'CRM_Contribute_Form_Contribution'
@@ -752,6 +741,21 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
 
     $unitVals = explode(CRM_Core_DAO::VALUE_SEPARATOR, $frUnits);
 
+
+    // FIXME: Ideally we should freeze select box if there is only
+    // one option but looks there is some problem /w QF freeze.
+    //if ( count( $units ) == 1 ) {
+    //$frequencyUnit->freeze( );
+    //}
+
+    $form->add('text', 'installments', ts('installments'),
+      $attributes['installments']
+    );
+    $form->addRule('installments', ts('Number of installments must be a whole number.'), 'integer');
+
+    $is_recur_label = ts('I want to contribute this amount every');
+    $unit_label = ts('Every');
+
     // CRM 10860, display text instead of a dropdown if there's only 1 frequency unit
     if (count($unitVals) == 1) {
       $form->assign('one_frequency_unit', TRUE);
@@ -759,8 +763,13 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       $form->add('hidden', 'frequency_unit', $unit);
       if (!empty($form->_values['is_recur_interval']) || $className == 'CRM_Contribute_Form_Contribution') {
         $unit .= "(s)";
+        $form->assign('frequency_unit', $unit);
+      } else {
+        $is_recur_label = ts('I want to contribute this amount every %1',
+          [1 => $unit]
+        );
+        $form->assign('all_text_recur', TRUE);
       }
-      $form->assign('frequency_unit', $unit);
     }
     else {
       $form->assign('one_frequency_unit', FALSE);
@@ -771,22 +780,23 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
           $units[$val] = $frequencyUnits[$val];
           if (!empty($form->_values['is_recur_interval']) || $className == 'CRM_Contribute_Form_Contribution') {
             $units[$val] = "{$frequencyUnits[$val]}(s)";
+            $unit = ts('Every');
           }
         }
       }
       $frequencyUnit = &$form->addElement('select', 'frequency_unit', NULL, $units, ['aria-label' => ts('Frequency Unit')]);
     }
 
-    // FIXME: Ideally we should freeze select box if there is only
-    // one option but looks there is some problem /w QF freeze.
-    //if ( count( $units ) == 1 ) {
-    //$frequencyUnit->freeze( );
-    //}
+    if (!empty($form->_values['is_recur_interval']) || $className == 'CRM_Contribute_Form_Contribution') {
+      $form->add('text', 'frequency_interval', $unit, $attributes['frequency_interval'] + ['aria-label' => ts('Every')]);
+      $form->addRule('frequency_interval', ts('Frequency must be a whole number (EXAMPLE: Every 3 months).'), 'integer');
+    }
+    else {
+      // make sure frequency_interval is submitted as 1 if given no choice to user.
+      $form->add('hidden', 'frequency_interval', 1);
+    }
 
-    $form->add('text', 'installments', ts('installments'),
-      $attributes['installments']
-    );
-    $form->addRule('installments', ts('Number of installments must be a whole number.'), 'integer');
+    $form->add('checkbox', 'is_recur', $is_recur_label, NULL);
   }
 
   /**
index 1a8d2180539eaa113c6d2b478fe6c7b8ebcc3372..0157fd13a0b645705b74ff07f42b1e772ff712f9 100644 (file)
         <div class="crm-public-form-item crm-section {$form.is_recur.name}-section">
           <div class="label">&nbsp;</div>
           <div class="content">
-            {$form.is_recur.html} {$form.is_recur.label} {ts}every{/ts}
+            {$form.is_recur.html} {$form.is_recur.label}
             {if $is_recur_interval}
               {$form.frequency_interval.html}
             {/if}
-            {if $one_frequency_unit}
-              {$frequency_unit}
-            {else}
-              {$form.frequency_unit.html}
+            {if !$all_text_recur}
+              {if $one_frequency_unit}
+                {$form.frequency_interval.label}
+              {else}
+                {$form.frequency_unit.html}
+              {/if}
             {/if}
             {if $is_recur_installments}
               <span id="recur_installments_num">