Skip to content

Commit

Permalink
Further fix - add the div options at the field level
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jan 3, 2025
1 parent 1c4e1f1 commit 564391b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 32 deletions.
9 changes: 8 additions & 1 deletion CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ public function __construct(
}
$this->_action = (int) $action;
$this->registerElementType('radio_with_div', 'CRM/Core/QuickForm/RadioWithDiv.php', 'CRM_Core_QuickForm_RadioWithDiv');
$this->registerElementType('group_with_div', 'CRM/Core/QuickForm/GroupWithDiv.php', 'CRM_Core_QuickForm_GroupWithDiv');
$this->registerRules();

// let the constructor initialize this, should happen only once
Expand Down Expand Up @@ -1497,7 +1498,13 @@ public function &addRadio($name, $title, $values, $attributes = [], $separator =
$element = $this->createElement('radio_with_div', NULL, NULL, $var, $key, $optAttributes);
$options[] = $element;
}
$group = $this->addGroup($options, $name, $title, $separator);
if (!empty($attributes['options_per_line'])) {
$group = $this->addElement('group_with_div', $name, $title, $options, $separator, TRUE);
$group->setAttribute('options_per_line', $attributes['options_per_line']);
}
else {
$group = $this->addGroup($options, $name, $title, $separator);
}

$optionEditKey = 'data-option-edit-path';
if (!empty($attributes[$optionEditKey])) {
Expand Down
41 changes: 41 additions & 0 deletions CRM/Core/QuickForm/GroupWithDiv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright U.S. PIRG Education Fund 2007
*
*/

require_once 'HTML/QuickForm/group.php';

/**
* Class CRM_Core_QuickForm_GroupWithDiv
*/
class CRM_Core_QuickForm_GroupWithDiv extends HTML_QuickForm_group {

/**
* Returns the group element in HTML
*
* @since 1.0
* @access public
* @return string
*/
public function toHtml(): string {
$html = parent::toHtml();
if (is_numeric($this->getAttribute('options_per_line'))) {
return '<div class="crm-multiple-checkbox-radio-options crm-options-per-line" style="--crm-opts-per-line:' . $this->getAttribute('options_per_line') . ';">' . $html . '</div>';
}
return $html;
}

}
7 changes: 3 additions & 4 deletions CRM/Core/QuickForm/RadioWithDiv.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ class CRM_Core_QuickForm_RadioWithDiv extends HTML_QuickForm_radio {
* @access public
* @return string
*/
function toHtml()
{
public function toHtml(): string {
$html = parent::toHtml();
if (is_numeric( $this->getAttribute('options_per_line'))) {
return '<div class="crm-option-label-pair" >' . $html. '</div>';
if (is_numeric($this->getAttribute('options_per_line'))) {
return '<div class="crm-option-label-pair" >' . $html . '</div>';
}
return $html;
}
Expand Down
28 changes: 5 additions & 23 deletions templates/CRM/Profile/Form/Dynamic.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
{/if}
{assign var="profileID" value=$field.group_id}
{assign var="profileFieldName" value=$field.name}
{assign var="formElement" value=$form.$profileFieldName}
{assign var="rowIdentifier" value=$field.name}

{if $field.groupTitle != $fieldset}
{if $mode neq 8 && $mode neq 4}
Expand Down Expand Up @@ -99,30 +101,10 @@
<div class="crm-section editrow_{$profileFieldName}-section form-item" id="editrow-{$profileFieldName}">
<div class="label">{$form.$profileFieldName.label}</div>
<div class="content edit-value">
{assign var="count" value=1}
{strip}
<table class="form-layout-compressed">
<tr>
{* sort by fails for option per line. Added a variable to iterate through the element array*}
{foreach name=outer key=key item=item from=$form.$profileFieldName}
{* There are both numeric and non-numeric keys mixed in here, where the non-numeric are metadata that aren't arrays with html members. *}
{if is_array($item) && array_key_exists('html', $item)}
<td class="labels font-light">{$form.$profileFieldName.$key.html}</td>
{if $count == $field.options_per_line}
</tr>
<tr>
{assign var="count" value=1}
{else}
{assign var="count" value=$count+1}
{/if}
{/if}
{/foreach}
</tr>
</table>
{/strip}
</div>
{$formElement.html}
</div>
<div class="clear"></div>
</div>{* end of main edit section div*}
</div>
{else}
<div id="editrow-{$profileFieldName}" class="crm-section editrow_{$profileFieldName}-section form-item">
<div class="label">
Expand Down
4 changes: 0 additions & 4 deletions templates/CRM/UF/Form/Fields.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
<div class="crm-multiple-checkbox-radio-options crm-options-per-line" style="--crm-opts-per-line:{$field.options_per_line};">
{$formElement.html}
</div>
{* Include the edit options list for admins *}
{if $formElement.html|strstr:"crm-option-edit-link"}
{$formElement.html|regex_replace:"@^.*(<a href=.*? class=.crm-option-edit-link.*?</a>)$@":"$1"}
{/if}
</div>
<div class="clear"></div>
</div>
Expand Down

0 comments on commit 564391b

Please sign in to comment.