Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
justinfreeman (Agileware)
Core
Commits
fd36866a
Commit
fd36866a
authored
11 years ago
by
colemanw
Browse files
Options
Downloads
Patches
Plain Diff
CRM-13966 - Change contactRef to entityRef
parent
f7305cbc
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
CRM/Activity/Form/Activity.php
+1
-1
1 addition, 1 deletion
CRM/Activity/Form/Activity.php
CRM/Core/Form.php
+20
-12
20 additions, 12 deletions
CRM/Core/Form.php
with
21 additions
and
13 deletions
CRM/Activity/Form/Activity.php
+
1
−
1
View file @
fd36866a
...
...
@@ -780,7 +780,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
);
$this
->
assign
(
'tokenUrl'
,
$tokenUrl
);
$sourceContactField
=
$this
->
add
Contact
Ref
(
$sourceContactField
=
$this
->
add
Entity
Ref
(
'source_contact_id'
,
$this
->
_fields
[
'source_contact_id'
][
'label'
],
array
(
'class'
=>
'huge'
),
...
...
This diff is collapsed.
Click to expand it.
CRM/Core/Form.php
+
20
−
12
View file @
fd36866a
...
...
@@ -1211,12 +1211,15 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
* @param string $name
* @param string $label
* @param array $props mix of html and widget properties, including:
* - required
* - select - params to give to select2, notably "multiple"
* - api - array of data for the api, keys include "entity", "action", "params", "search", "key", "label"
* - select - params to give to select2 widget
* - api - array of settings for the api, keys include "entity", "action", "params", "search", "key", "label"
* - placeholder - string
* - multiple - bool
* - class, etc. - other html properties
* @param bool $required
* @return HTML_QuickForm_Element
*/
function
add
Contact
Ref
(
$name
,
$label
,
$props
=
array
(),
$required
=
FALSE
)
{
function
add
Entity
Ref
(
$name
,
$label
,
$props
=
array
(),
$required
=
FALSE
)
{
$props
[
'class'
]
=
isset
(
$props
[
'class'
])
?
$props
[
'class'
]
.
' crm-select2'
:
'crm-select2'
;
$props
[
'select'
]
=
CRM_Utils_Array
::
value
(
'select'
,
$props
,
array
())
+
array
(
...
...
@@ -1237,7 +1240,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
'key'
=>
'id'
,
);
$this
->
entityReferenceFields
[
$name
]
=
$props
;
$this
->
entityReferenceFields
[
]
=
$name
;
$this
->
formatReferenceFieldAttributes
(
$props
);
return
$this
->
add
(
'text'
,
$name
,
$label
,
$props
,
$required
);
}
...
...
@@ -1248,13 +1251,16 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
private
function
formatReferenceFieldAttributes
(
&
$props
)
{
$props
[
'data-select-params'
]
=
json_encode
(
$props
[
'select'
]);
$props
[
'data-api-params'
]
=
json_encode
(
$props
[
'api'
]);
CRM_Utils_Array
::
remove
(
$props
,
'multiple'
,
'select'
,
'api'
);
CRM_Utils_Array
::
remove
(
$props
,
'multiple'
,
'select'
,
'api'
,
'placeholder'
);
}
/**
* Convert IDs to values and format for display
*/
private
function
preprocessReferenceFields
()
{
foreach
(
$this
->
entityReferenceFields
as
$name
=>
$props
)
{
$val
=
$this
->
getElementValue
(
$name
);
foreach
(
$this
->
entityReferenceFields
as
$name
)
{
$field
=
$this
->
getElement
(
$name
);
$val
=
$field
->
getValue
();
// Support array values
if
(
is_array
(
$val
))
{
$val
=
implode
(
','
,
$val
);
...
...
@@ -1262,16 +1268,18 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
}
if
(
$val
)
{
$data
=
$labels
=
array
();
$api
=
json_decode
(
$field
->
getAttribute
(
'data-api-params'
),
TRUE
);
$select
=
json_decode
(
$field
->
getAttribute
(
'data-select-params'
),
TRUE
);
// Support serialized values
if
(
strpos
(
$val
,
CRM_Core_DAO
::
VALUE_SEPARATOR
)
!==
FALSE
)
{
$val
=
str_replace
(
CRM_Core_DAO
::
VALUE_SEPARATOR
,
','
,
trim
(
$val
,
CRM_Core_DAO
::
VALUE_SEPARATOR
));
$field
->
setValue
(
$val
);
}
foreach
(
explode
(
','
,
$val
)
as
$v
)
{
$result
=
civicrm_api3
(
$
props
[
'
api
'
]
[
'entity'
],
$
props
[
'
api
'
]
[
'action'
],
array
(
'sequential'
=>
1
,
$
props
[
'
api
'
]
[
'key'
]
=>
$v
));
$result
=
civicrm_api3
(
$api
[
'entity'
],
$api
[
'action'
],
array
(
'sequential'
=>
1
,
$api
[
'key'
]
=>
$v
));
if
(
!
empty
(
$result
[
'values'
]))
{
$data
[]
=
array
(
'id'
=>
$v
,
'text'
=>
$result
[
'values'
][
0
][
$
props
[
'
api
'
]
[
'label'
]]);
$labels
[]
=
$result
[
'values'
][
0
][
$
props
[
'
api
'
]
[
'label'
]];
$data
[]
=
array
(
'id'
=>
$v
,
'text'
=>
$result
[
'values'
][
0
][
$api
[
'label'
]]);
$labels
[]
=
$result
[
'values'
][
0
][
$api
[
'label'
]];
}
}
if
(
$field
->
isFrozen
())
{
...
...
@@ -1279,7 +1287,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
$field
->
setValue
(
implode
(
', '
,
$labels
));
}
elseif
(
$data
)
{
if
(
empty
(
$
props
[
'
select
'
]
[
'multiple'
]))
{
if
(
empty
(
$select
[
'multiple'
]))
{
$data
=
$data
[
0
];
}
$field
->
setAttribute
(
'data-entity-value'
,
json_encode
(
$data
));
...
...
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