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
704d3260
Commit
704d3260
authored
11 years ago
by
colemanw
Browse files
Options
Downloads
Patches
Plain Diff
CRM-13966 - entityRef - Render frozen text as link when appropriate
parent
fd36866a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Form.php
+17
-13
17 additions, 13 deletions
CRM/Core/Form.php
CRM/Core/Form/Renderer.php
+35
-3
35 additions, 3 deletions
CRM/Core/Form/Renderer.php
with
52 additions
and
16 deletions
CRM/Core/Form.php
+
17
−
13
View file @
704d3260
...
...
@@ -1220,7 +1220,20 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
* @return HTML_QuickForm_Element
*/
function
addEntityRef
(
$name
,
$label
,
$props
=
array
(),
$required
=
FALSE
)
{
$props
[
'class'
]
=
isset
(
$props
[
'class'
])
?
$props
[
'class'
]
.
' crm-select2'
:
'crm-select2'
;
$props
[
'api'
]
=
CRM_Utils_Array
::
value
(
'api'
,
$props
,
array
());
// Merge in defaults for api params
$props
[
'api'
]
+=
array
(
'entity'
=>
'contact'
,
'key'
=>
'id'
,
);
$props
[
'api'
]
+=
array
(
'action'
=>
$props
[
'api'
][
'entity'
]
==
'contact'
?
'getquick'
:
'get'
,
'search'
=>
'name'
,
'label'
=>
'data'
,
);
$props
[
'class'
]
=
isset
(
$props
[
'class'
])
?
$props
[
'class'
]
.
' '
:
''
;
$props
[
'class'
]
.
=
"crm-select2 crm-
{
$props
[
'api'
][
'entity'
]
}
-ref-field"
;
$props
[
'select'
]
=
CRM_Utils_Array
::
value
(
'select'
,
$props
,
array
())
+
array
(
'minimumInputLength'
=>
1
,
...
...
@@ -1232,14 +1245,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
//'formatNoMatches' => ts('No contacts found.'),
);
$props
[
'api'
]
=
CRM_Utils_Array
::
value
(
'api'
,
$props
,
array
())
+
array
(
'entity'
=>
'contact'
,
'action'
=>
'getquick'
,
'search'
=>
'name'
,
'label'
=>
'data'
,
'key'
=>
'id'
,
);
$this
->
entityReferenceFields
[]
=
$name
;
$this
->
formatReferenceFieldAttributes
(
$props
);
return
$this
->
add
(
'text'
,
$name
,
$label
,
$props
,
$required
);
...
...
@@ -1267,7 +1272,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
$field
->
setValue
(
$val
);
}
if
(
$val
)
{
$data
=
$labels
=
array
();
$data
=
array
();
$api
=
json_decode
(
$field
->
getAttribute
(
'data-api-params'
),
TRUE
);
$select
=
json_decode
(
$field
->
getAttribute
(
'data-select-params'
),
TRUE
);
// Support serialized values
...
...
@@ -1279,14 +1284,13 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
$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
][
$api
[
'label'
]]);
$labels
[]
=
$result
[
'values'
][
0
][
$api
[
'label'
]];
}
}
if
(
$field
->
isFrozen
())
{
$field
->
removeAttribute
(
'class'
);
$field
->
setValue
(
implode
(
', '
,
$labels
));
}
elseif
(
$data
)
{
if
(
$data
)
{
// Simplify array for single selects - makes client-side code simpler (but feels somehow wrong)
if
(
empty
(
$select
[
'multiple'
]))
{
$data
=
$data
[
0
];
}
...
...
This diff is collapsed.
Click to expand it.
CRM/Core/Form/Renderer.php
+
35
−
3
View file @
704d3260
...
...
@@ -95,9 +95,9 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty {
*
* @access private
*
* @param
object An
HTML_QuickForm_element
object
* @param bool
Whether an element is required
* @param string
Error associated with the element
* @param
$element
HTML_QuickForm_element
* @param
$required
bool
-
Whether an element is required
* @param
$error
string
-
Error associated with the element
*
* @return array
*/
...
...
@@ -117,6 +117,13 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty {
}
}
if
(
!
empty
(
$el
[
'frozen'
]))
{
if
(
$element
->
getAttribute
(
'data-api-params'
)
&&
$element
->
getAttribute
(
'data-entity-value'
))
{
$this
->
renderFrozenEntityRef
(
$el
,
$element
);
}
$el
[
'html'
]
=
'<div class="crm-frozen-field">'
.
$el
[
'html'
]
.
'</div>'
;
}
return
$el
;
}
...
...
@@ -173,6 +180,31 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty {
$attributes
[
'class'
]
=
$class
;
$element
->
updateAttributes
(
$attributes
);
}
/**
* Render entity references as text.
* If user has permission, format as link (or now limited to contacts).
* @param $el array
* @param $field HTML_QuickForm_element
*/
function
renderFrozenEntityRef
(
&
$el
,
$field
)
{
$api
=
json_decode
(
$field
->
getAttribute
(
'data-api-params'
),
TRUE
);
$vals
=
json_decode
(
$field
->
getAttribute
(
'data-entity-value'
),
TRUE
);
if
(
isset
(
$vals
[
'id'
]))
{
$vals
=
array
(
$vals
);
}
$display
=
array
();
foreach
(
$vals
as
$val
)
{
// Format contact as link
if
(
$api
[
'entity'
]
==
'contact'
&&
CRM_Contact_BAO_Contact_Permission
::
allow
(
$val
[
'id'
],
CRM_Core_Permission
::
VIEW
))
{
$url
=
CRM_Utils_System
::
url
(
"civicrm/contact/view"
,
array
(
'reset'
=>
1
,
'cid'
=>
$val
[
'id'
]));
$val
[
'text'
]
=
'<a href="'
.
$url
.
'" title="'
.
ts
(
'View Contact'
)
.
'">'
.
$val
[
'text'
]
.
'</a>'
;
}
$display
[]
=
$val
[
'text'
];
}
$el
[
'html'
]
=
implode
(
'; '
,
$display
)
.
'<input type="hidden" value="'
.
$field
->
getValue
()
.
'" name="'
.
$field
->
getAttribute
(
'name'
)
.
'">'
;
}
}
// end CRM_Core_Form_Renderer
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