Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
ed88949c
Commit
ed88949c
authored
3 years ago
by
Eileen McNaughton
Browse files
Options
Downloads
Patches
Plain Diff
Add enough hack-handling to make this PR not change outputs
parent
0432df8d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Civi/Token/TokenCompatSubscriber.php
+72
-0
72 additions, 0 deletions
Civi/Token/TokenCompatSubscriber.php
tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php
+1
-1
1 addition, 1 deletion
tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php
with
73 additions
and
1 deletion
Civi/Token/TokenCompatSubscriber.php
+
72
−
0
View file @
ed88949c
...
...
@@ -307,6 +307,8 @@ class TokenCompatSubscriber implements EventSubscriberInterface {
if
(
empty
(
$messageTokens
))
{
return
;
}
$this
->
fieldMetadata
=
(
array
)
civicrm_api4
(
'Contact'
,
'getfields'
,
[
'checkPermissions'
=>
FALSE
],
'name'
);
foreach
(
$e
->
getRows
()
as
$row
)
{
if
(
empty
(
$row
->
context
[
'contactId'
]))
{
continue
;
...
...
@@ -318,6 +320,7 @@ class TokenCompatSubscriber implements EventSubscriberInterface {
if
(
empty
(
$row
->
context
[
'contact'
]))
{
$row
->
context
[
'contact'
]
=
$this
->
getContact
(
$row
->
context
[
'contactId'
],
$messageTokens
);
}
foreach
(
$messageTokens
as
$token
)
{
if
(
$token
===
'checksum'
)
{
$cs
=
\CRM_Contact_BAO_Contact_Utils
::
generateChecksum
(
$row
->
context
[
'contactId'
],
...
...
@@ -328,6 +331,22 @@ class TokenCompatSubscriber implements EventSubscriberInterface {
$row
->
format
(
'text/html'
)
->
tokens
(
'contact'
,
$token
,
"cs=
{
$cs
}
"
);
}
elseif
(
!
empty
(
$row
->
context
[
'contact'
][
$token
])
&&
$this
->
isDateField
(
$token
)
)
{
// Handle dates here, for now. Standardise with other token entities next round
$row
->
format
(
'text/plain'
)
->
tokens
(
'contact'
,
$token
,
\CRM_Utils_Date
::
customFormat
(
$row
->
context
[
'contact'
][
$token
]));
}
elseif
(
(
$row
->
context
[
'contact'
][
$token
]
??
''
)
==
0
&&
$this
->
isBooleanField
(
$token
))
{
// Note this will be the default behaviour once we fetch with apiv4.
$row
->
format
(
'text/plain'
)
->
tokens
(
'contact'
,
$token
,
''
);
}
elseif
(
$token
===
'signature_html'
)
{
$text
=
html_entity_decode
(
$row
->
context
[
'contact'
][
$token
]);
$row
->
format
(
'text/html'
)
->
tokens
(
'contact'
,
$token
,
$value
);
}
else
{
$row
->
format
(
'text/html'
)
->
tokens
(
'contact'
,
$token
,
$row
->
context
[
'contact'
][
$token
]
??
''
);
...
...
@@ -336,6 +355,59 @@ class TokenCompatSubscriber implements EventSubscriberInterface {
}
}
/**
* Is the given field a boolean field.
*
* @param string $fieldName
*
* @return bool
*/
public
function
isBooleanField
(
string
$fieldName
):
bool
{
// no metadata for these 2 non-standard fields
// @todo - fix to api v4 & have metadata for all fields. Migrate contact_is_deleted
// to {contact.is_deleted}. on hold feels like a token that exists by
// accident & could go.... since it's not from the main entity.
if
(
in_array
(
$fieldName
,
[
'contact_is_deleted'
,
'on_hold'
]))
{
return
TRUE
;
}
if
(
empty
(
$this
->
getFieldMetadata
()[
$fieldName
]))
{
return
FALSE
;
}
return
$this
->
getFieldMetadata
()[
$fieldName
][
'data_type'
]
===
'Boolean'
;
}
/**
* Is the given field a date field.
*
* @param string $fieldName
*
* @return bool
*/
public
function
isDateField
(
string
$fieldName
):
bool
{
if
(
empty
(
$this
->
getFieldMetadata
()[
$fieldName
]))
{
return
FALSE
;
}
return
in_array
(
$this
->
getFieldMetadata
()[
$fieldName
][
'data_type'
],
[
'Timestamp'
,
'Date'
],
TRUE
);
}
/**
* Get the metadata for the available fields.
*
* @return array
*/
protected
function
getFieldMetadata
():
array
{
if
(
empty
(
$this
->
fieldMetadata
))
{
try
{
// Tests fail without checkPermissions = FALSE
$this
->
fieldMetadata
=
(
array
)
civicrm_api4
(
'Contact'
,
'getfields'
,
[
'checkPermissions'
=>
FALSE
],
'name'
);
}
catch
(
\API_Exception
$e
)
{
$this
->
fieldMetadata
=
[];
}
}
return
$this
->
fieldMetadata
;
}
/**
* Apply the various CRM_Utils_Token helpers.
*
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php
+
1
−
1
View file @
ed88949c
...
...
@@ -768,7 +768,7 @@ state_province:TX
country:United States
phone:123-456
phone_ext:77
phone_type_id:
phone_type_id:
2
phone_type:Mobile
email:anthony_anderson@civicrm.org
on_hold:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment