Skip to content

Commit

Permalink
DomainEmailAddress - Add search display and formbuilder form
Browse files Browse the repository at this point in the history
Removes unused handling from the quickform
  • Loading branch information
colemanw committed Jan 31, 2025
1 parent 0b16f4e commit 8d98958
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 55 deletions.
25 changes: 0 additions & 25 deletions CRM/Admin/Form/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ public function buildQuickForm(): void {
'email_greeting',
'postal_greeting',
'addressee',
'from_email_address',
'case_status',
'encounter_medium',
'case_type',
Expand Down Expand Up @@ -439,18 +438,6 @@ public static function formRule($fields, $files, $self) {

}

if ($optionGroupName === 'from_email_address') {
$formEmail = CRM_Utils_Mail::pluckEmailFromHeader($fields['label']);
if (!CRM_Utils_Rule::email($formEmail)) {
$errors['label'] = ts('Please enter a valid email address.');
}

$formName = explode('"', $fields['label']);
if (empty($formName[1]) || count($formName) != 3) {
$errors['label'] = ts('Please follow the proper format for From Email Address');
}
}

$dataType = self::getOptionGroupDataType($optionGroupName);
if ($dataType && $optionGroupName !== 'activity_type') {
$validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE);
Expand Down Expand Up @@ -528,10 +515,6 @@ public function postProcess() {
$params['filter'] = $params['contact_type_id'];
}

//make sure we only have a single space, CRM-6977 and dev/mail/15
if ($this->_gName == 'from_email_address') {
$params['label'] = $this->sanitizeFromEmailAddress($params['label']);
}
// set value of filter if not present in params
if ($this->_id && !array_key_exists('filter', $params)) {
if ($this->_gName == 'participant_role') {
Expand Down Expand Up @@ -560,11 +543,6 @@ public function postProcess() {
}
}

public function sanitizeFromEmailAddress($email) {
preg_match("/^\"(.*)\" *<([^@>]*@[^@>]*)>$/", $email, $parts);
return "\"{$parts[1]}\" <$parts[2]>";
}

/**
* Is the option group one of our greetings.
*
Expand All @@ -579,9 +557,6 @@ protected function isGreetingOptionGroup(): bool {
* @return array
*/
protected function getFieldsToExcludeFromPurification(): array {
if ($this->_gName === 'from_email_address') {
return ['label'];
}
return [];
}

Expand Down
12 changes: 12 additions & 0 deletions ang/afform/afformSiteEmailAddress.aff.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<af-form ctrl="afform">
<af-entity actions="{create: true, update: true}" type="DomainEmailAddress" name="email" label="Site Email Address 1" security="RBAC" url-autofill="1" />
<fieldset af-fieldset="email" class="af-container" af-title="Site Email Address 1">
<div class="af-container af-layout-inline">
<af-field name="name" />
<af-field name="email" />
</div>
<af-field name="description" />
<af-field name="is_default" />
</fieldset>
<button class="af-button btn btn-primary" crm-icon="fa-check" ng-click="afform.submit()" ng-if="afform.showSubmitButton">Submit</button>
</af-form>
11 changes: 11 additions & 0 deletions ang/afform/afformSiteEmailAddress.aff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'type' => 'form',
'title' => ts('Site Email Address'),
'icon' => 'fa-list-alt',
'server_route' => 'civicrm/admin/form/site-email-address',
'permission' => [
'administer CiviCRM system',
],
];
3 changes: 3 additions & 0 deletions ang/afform/afsearchSiteEmailAddresses.aff.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div af-fieldset="">
<crm-search-display-table search-name="Site_Email_Addresses" display-name="Site_Email_Addresses"></crm-search-display-table>
</div>
11 changes: 11 additions & 0 deletions ang/afform/afsearchSiteEmailAddresses.aff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'type' => 'search',
'title' => ts('Site Email Addresses'),
'icon' => 'fa-list-alt',
'server_route' => 'civicrm/admin/options/from_email_address',
'permission' => [
'administer CiviCRM system',
],
];
179 changes: 179 additions & 0 deletions managed/administer/SavedSearch_Site_Email_Addresses.mgd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

return [
[
'name' => 'SavedSearch_Site_Email_Addresses',
'entity' => 'SavedSearch',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'name' => 'Site_Email_Addresses',
'label' => ts('Site Email Addresses'),
'api_entity' => 'DomainEmailAddress',
'api_params' => [
'version' => 4,
'select' => [
'name',
'email',
'description',
'is_active',
'is_default',
],
'orderBy' => [],
'where' => [
['domain_id:name', '=', 'current_domain'],
],
'groupBy' => [],
'join' => [],
'having' => [],
],
],
'match' => ['name'],
],
],
[
'name' => 'SavedSearch_Site_Email_Addresses_SearchDisplay_Site_Email_Addresses',
'entity' => 'SearchDisplay',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'name' => 'Site_Email_Addresses',
'label' => ts('Site Email Addresses'),
'saved_search_id.name' => 'Site_Email_Addresses',
'type' => 'table',
'settings' => [
'description' => ts('You can use this page to define one or more general Email Addresses that can be selected as the From Address.'),
'sort' => [],
'limit' => 50,
'pager' => [
'hide_single' => TRUE,
'show_count' => TRUE,
],
'placeholder' => 5,
'columns' => [
[
'type' => 'field',
'key' => 'name',
'dataType' => 'String',
'label' => ts('Display Name'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'email',
'dataType' => 'String',
'label' => ts('Email'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'description',
'dataType' => 'Text',
'label' => ts('Description'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'is_active',
'dataType' => 'Boolean',
'label' => ts('Enabled'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'is_default',
'dataType' => 'Boolean',
'label' => ts('Default'),
'sortable' => TRUE,
'icons' => [
[
'icon' => 'fa-circle-check',
'side' => 'left',
'if' => ['is_default', '=', TRUE],
],
],
'rewrite' => ' ',
],
[
'text' => ts(''),
'style' => 'default',
'size' => 'btn-xs',
'icon' => 'fa-bars',
'links' => [
[
'entity' => 'DomainEmailAddress',
'action' => 'update',
'join' => '',
'target' => 'crm-popup',
'icon' => 'fa-pencil',
'text' => ts('Edit Email Address'),
'style' => 'default',
'path' => '',
'task' => '',
'condition' => [],
],
[
'task' => 'disable',
'entity' => 'DomainEmailAddress',
'join' => '',
'target' => 'crm-popup',
'icon' => 'fa-toggle-off',
'text' => ts('Disable Email Addresses'),
'style' => 'default',
'path' => '',
'action' => '',
'condition' => [],
],
[
'task' => 'enable',
'entity' => 'DomainEmailAddress',
'join' => '',
'target' => 'crm-popup',
'icon' => 'fa-toggle-on',
'text' => ts('Enable Email Addresses'),
'style' => 'default',
'path' => '',
'action' => '',
'condition' => [],
],
],
'type' => 'menu',
'alignment' => 'text-right',
],
],
'actions' => FALSE,
'classes' => [
'table',
'table-striped',
'crm-sticky-header',
],
'toolbar' => [
[
'entity' => 'DomainEmailAddress',
'text' => ts('Add Email Address'),
'icon' => 'fa-plus',
'target' => 'crm-popup',
'action' => 'add',
'style' => 'primary',
'join' => '',
'path' => '',
'task' => '',
'condition' => [],
],
],
'cssRules' => [
['disabled', 'is_active', '=', FALSE],
],
],
],
'match' => [
'saved_search_id',
'name',
],
],
],
];
6 changes: 5 additions & 1 deletion schema/Core/DomainEmailAddress.entityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
'icon' => 'fa-envelope',
'label_field' => 'name',
],
'getPaths' => fn() => [],
'getPaths' => fn() => [
'browse' => 'civicrm/admin/options/from_email_address',
'add' => 'civicrm/admin/form/site-email-address',
'update' => 'civicrm/admin/form/site-email-address#?email=[id]',
],
'getIndices' => fn() => [
'UI_domain_id_is_default' => [
'fields' => [
Expand Down
7 changes: 0 additions & 7 deletions templates/CRM/Admin/Form/Options.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
<span class="description">{ts}Enter the "class path" for this custom search here.{/ts}
</td>
</tr>
{elseif $gName eq 'from_email_address'}
<tr class="crm-admin-options-form-block-from_email_address">
<td class="label">{ts}FROM Email Address{/ts} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_option_value' field='label' id=$id}{/if}</td>
<td>{$form.label.html}<br />
<span class="description">{ts}Include double-quotes (&quot;) around the name and angle-brackets (&lt; &gt;) around the email address.<br />EXAMPLE: <em>&quot;Client Services&quot; &lt;[email protected]&gt;</em>{/ts}<span>
</td>
</tr>
{elseif $gName eq 'redaction_rule'}
<tr class="crm-admin-options-form-block-expression">
<td class="label">{ts}Match Value or Expression{/ts} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_option_value' field='label' id=$id}{/if}</td>
Expand Down
6 changes: 0 additions & 6 deletions templates/CRM/Admin/Page/Options.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@
{ts}Define participant roles for events here (e.g. Attendee, Host, Speaker...). You can then assign roles and search for participants by role.{/ts}
{elseif $gName eq 'participant_status'}
{ts}Define statuses for event participants here (e.g. Registered, Attended, Cancelled...). You can then assign statuses and search for participants by status.{/ts} {ts}"Counted?" controls whether a person with that status is counted as participant for the purpose of controlling the Maximum Number of Participants.{/ts}
{elseif $gName eq 'from_email_address'}
{if $allowLoggedIn}
{ts}By default, CiviCRM uses the primary email address of the logged in user as the FROM address when sending emails to contacts. However, you can use this page to define one or more general Email Addresses that can be selected as an alternative. EXAMPLE: <em>"Client Services" &lt;[email protected]&gt;</em>{/ts}
{else}
{ts}You can use this page to define one or more general Email Addresses that can be selected as the From Address. EXAMPLE: <em>"Client Services" &lt;[email protected]&gt;</em>{/ts}
{/if}
{elseif $isLocked}
{ts}This option group is reserved for system use. You cannot add or delete options in this list.{/ts}
{else}
Expand Down
16 changes: 0 additions & 16 deletions tests/phpunit/CRM/Core/OptionGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,6 @@ public function testsOptionGroupDataType($optionGroup, $expectedDataType) {
}
}

public function emailAddressTests() {
$tests[] = ['"Name"<[email protected]>', '"Name" <[email protected]>'];
$tests[] = ['"Name" <[email protected]>', '"Name" <[email protected]>'];
$tests[] = ['"Name" <[email protected]>', '"Name" <[email protected]>'];
return $tests;
}

/**
* @dataProvider emailAddressTests
*/
public function testSanitizeFromEmailAddress($dirty, $clean) {
$form = new CRM_Admin_Form_Options();
$actual = $form->sanitizeFromEmailAddress($dirty);
$this->assertEquals($actual, $clean);
}

public static function orderByCases(): array {
return [
['weight', FALSE],
Expand Down

0 comments on commit 8d98958

Please sign in to comment.