Skip to content

Commit

Permalink
Merge pull request #13110 from eileenmcnaughton/profile_translate
Browse files Browse the repository at this point in the history
dev/core#527 Permit translation of Public Title field for Profiles
  • Loading branch information
eileenmcnaughton authored Nov 16, 2018
2 parents 9ab0b9f + cbd71f7 commit 36c5896
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 42 deletions.
12 changes: 9 additions & 3 deletions CRM/Core/DAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/UFGroup.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:a48f9522d0bd2e1d485064ebfc66f9a2)
* (GenCodeChecksum:d0a806459507dc6b32ba955e4e899358)
*/

/**
Expand Down Expand Up @@ -291,7 +291,7 @@ public static function &fields() {
'title' => [
'name' => 'title',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Title'),
'title' => ts('Profile Name'),
'description' => ts('Form title.'),
'required' => TRUE,
'maxlength' => 64,
Expand All @@ -300,18 +300,24 @@ public static function &fields() {
'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,
'table_name' => 'civicrm_uf_group',
'entity' => 'UFGroup',
'bao' => 'CRM_Core_BAO_UFGroup',
'localizable' => 1,
'html' => [
'type' => 'Text',
],
],
'description' => [
'name' => 'description',
Expand Down
88 changes: 65 additions & 23 deletions CRM/UF/Form/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,52 @@
*
* @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']],
'uf_group_type' => ['name' => 'uf_group_type', 'not-auto-addable' => TRUE, 'help' => ['id' => 'id-used_for', 'file' => 'CRM/UF/Form/Group.hlp'], 'post_html_text' => ' ' . $this->getOtherModuleString()]
];
}

/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'UFGroup';
}

/**
* The form id saved to the session for an update.
*
Expand All @@ -57,8 +94,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
Expand Down Expand Up @@ -111,6 +146,7 @@ public function preProcess() {
* @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';
Expand All @@ -132,12 +168,6 @@ public function buildQuickForm() {
));
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();
Expand Down Expand Up @@ -237,17 +267,6 @@ public function setDefaultValues() {
}
$defaults['uf_group_type'] = isset($checked) ? $checked : "";

//get the uf join records for current uf group other than default modules
$otherModules = array();
$otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id, TRUE, TRUE);
if (!empty($otherModules)) {
$otherModuleString = NULL;
foreach ($otherModules as $key) {
$otherModuleString .= " [ x ] <label>" . $key . "</label>";
}
$this->assign('otherModuleString', $otherModuleString);
}

$showAdvanced = 0;
$advFields = array(
'group',
Expand Down Expand Up @@ -335,7 +354,7 @@ public function postProcess() {
}
else {
// get the submitted form values.
$params = $ids = array();
$ids = array();
$params = $this->controller->exportValues($this->_name);

if (!array_key_exists('is_active', $params)) {
Expand Down Expand Up @@ -386,4 +405,27 @@ public function postProcess() {
CRM_Utils_System::updateCategories();
}

/**
* Set the delete message.
*
* We do this from the constructor in order to do a translation.
*/
public function setDeleteMessage() {}

/**
* Get the string to display next to the used for field indicating unchangeable uses.
*
* @return string
*/
protected function getOtherModuleString() {
$otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id, TRUE, TRUE);
if (!empty($otherModules)) {
$otherModuleString = NULL;
foreach ($otherModules as $key) {
$otherModuleString .= " [ x ] <label>" . $key . "</label>";
}
}
return $otherModuleString;
}

}
2 changes: 1 addition & 1 deletion templates/CRM/Core/Form/Field.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{/capture}{help id=$help.id file=$help.file}{/if}
{if $action == 2 && $fieldSpec.is_add_translate_dialog}{include file='CRM/Core/I18n/Dialog.tpl' table=$entityTable field=$fieldName id=$entityID}{/if}
</td>
<td>{if $form.$fieldName.html}{if $fieldSpec.formatter === 'crmMoney'}{$form.$fieldName.html|crmMoney}{else}{$form.$fieldName.html}{/if}{else}{$fieldSpec.place_holder}{/if}<br />
<td>{$fieldSpec.pre_html_text}{if $form.$fieldName.html}{if $fieldSpec.formatter === 'crmMoney'}{$form.$fieldName.html|crmMoney}{else}{$form.$fieldName.html}{/if}{else}{$fieldSpec.place_holder}{/if}{$fieldSpec.post_html_text}<br />
{if $fieldSpec.description}<span class="description">{$fieldSpec.description}</span>{/if}
{if $fieldSpec.documentation_link}{docURL page=$fieldSpec.documentation_link.page resource=$fieldSpec.documentation_link.resource}{/if}
</td>
Expand Down
20 changes: 5 additions & 15 deletions templates/CRM/UF/Form/Group.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,12 @@
</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>
</tr>
<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>
{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-weight" >
<td class="label">{$form.weight.label}{if $config->userSystem->is_drupal EQ '1'} {help id='id-profile_weight' file="CRM/UF/Form/Group.hlp"}{/if}</td>
<td class="html-adjust">{$form.weight.html}</td>
Expand Down
11 changes: 11 additions & 0 deletions xml/schema/Core/UFGroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,27 @@
</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>
Expand Down Expand Up @@ -112,6 +120,9 @@
<type>int</type>
<required>true</required>
<default>1</default>
<html>
<type>Text</type>
</html>
<comment>Controls display order when multiple user framework groups are setup for concurrent display.</comment>
<add>1.2</add>
<drop>1.3</drop>
Expand Down

0 comments on commit 36c5896

Please sign in to comment.