Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Merge requests
!8317
3336994 StringFormatter access
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
3336994 StringFormatter access
issue/drupal-3336994:3336994-stringformatter-access-r2
into
11.x
Overview
10
Commits
16
Pipelines
11
Changes
8
3 unresolved threads
Hide all comments
Open
Dezső Biczó
requested to merge
issue/drupal-3336994:3336994-stringformatter-access-r2
into
11.x
10 months ago
Overview
10
Commits
16
Pipelines
11
Changes
8
3 unresolved threads
Hide all comments
Expand
Co-authored-by: Dezső BICZÓ
mxr576@gmail.com
Closes
#3336994
0
0
Merge request reports
Compare
11.x
version 10
652bf50a
9 months ago
version 9
eb60879e
9 months ago
version 8
f9036d11
9 months ago
version 7
3cb22a7e
9 months ago
version 6
31602914
9 months ago
version 5
364e4989
9 months ago
version 4
4b382b30
9 months ago
version 3
f39d1de1
10 months ago
version 2
d0714b0f
10 months ago
version 1
3ce751e2
10 months ago
11.x (base)
and
latest version
latest version
b62d8a8d
16 commits,
9 months ago
version 10
652bf50a
16 commits,
9 months ago
version 9
eb60879e
16 commits,
9 months ago
version 8
f9036d11
15 commits,
9 months ago
version 7
3cb22a7e
14 commits,
9 months ago
version 6
31602914
13 commits,
9 months ago
version 5
364e4989
10 commits,
9 months ago
version 4
4b382b30
9 commits,
9 months ago
version 3
f39d1de1
8 commits,
10 months ago
version 2
d0714b0f
8 commits,
10 months ago
version 1
3ce751e2
8 commits,
10 months ago
8 files
+
157
−
11
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php
+
12
−
5
Options
@@ -2,6 +2,7 @@
namespace
Drupal\Core\Field\Plugin\Field\FieldFormatter
;
use
Drupal\Core\Cache\CacheableMetadata
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Field\Attribute\FieldFormatter
;
@@ -122,27 +123,33 @@ public function settingsSummary() {
*/
public
function
viewElements
(
FieldItemListInterface
$items
,
$langcode
)
{
$elements
=
[];
$url
=
NULL
;
$entity
=
$items
->
getEntity
();
$entity_type
=
$entity
->
getEntityType
();
$render_as_link
=
FALSE
;
if
(
$this
->
getSetting
(
'link_to_entity'
)
&&
!
$entity
->
isNew
()
&&
$entity_type
->
hasLinkTemplate
(
'canonical'
))
{
$url
=
$this
->
getEntityUrl
(
$entity
);
$access
=
$url
->
access
(
return_as_object
:
TRUE
);
(
new
CacheableMetadata
())
->
addCacheableDependency
(
$access
)
->
applyTo
(
$elements
);
$render_as_link
=
$access
->
isAllowed
();
}
foreach
(
$items
as
$delta
=>
$item
)
{
$view_value
=
$this
->
viewValue
(
$item
);
if
(
$url
)
{
if
(
$render_as_link
)
{
assert
(
isset
(
$url
)
);
$elements
[
$delta
]
=
[
'#type'
=>
'link'
,
'#title'
=>
$view
_v
alue
,
'#title'
=>
$
this
->
view
V
alue
(
$item
)
,
'#url'
=>
$url
,
];
}
else
{
$elements
[
$delta
]
=
$view
_v
alue
;
$elements
[
$delta
]
=
$
this
->
view
V
alue
(
$item
)
;
}
}
return
$elements
;
}
Loading