Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
twig_tweak-3313874
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
twig_tweak-3313874
Commits
fa6b362a
Commit
fa6b362a
authored
5 years ago
by
Ivan
Browse files
Options
Downloads
Patches
Plain Diff
Deprecate loading entitiies from route
parent
5372b821
No related branches found
Branches containing commit
Tags
8.x-2.4
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/TwigExtension.php
+14
-10
14 additions, 10 deletions
src/TwigExtension.php
with
14 additions
and
10 deletions
src/TwigExtension.php
+
14
−
10
View file @
fa6b362a
...
...
@@ -242,9 +242,6 @@ class TwigExtension extends \Twig_Extension {
* # Print a content block which ID is 1.
* {{ drupal_entity('block_content', 1) }}
*
* # Print a user which ID is fetched from URL (i.e. /user/1).
* {{ drupal_entity('user') }}
*
* # Print a node's teaser.
* {{ drupal_entity('node', 123, 'teaser') }}
*
...
...
@@ -270,9 +267,13 @@ class TwigExtension extends \Twig_Extension {
*/
public
function
drupalEntity
(
$entity_type
,
$id
=
NULL
,
$view_mode
=
NULL
,
$langcode
=
NULL
,
$check_access
=
TRUE
)
{
$entity_type_manager
=
\Drupal
::
entityTypeManager
();
$entity
=
$id
?
$entity_type_manager
->
getStorage
(
$entity_type
)
->
load
(
$id
)
:
\Drupal
::
routeMatch
()
->
getParameter
(
$entity_type
);
if
(
$id
)
{
$entity
=
$entity_type_manager
->
getStorage
(
$entity_type
)
->
load
(
$id
);
}
else
{
@
trigger_error
(
'Loading entities from route is deprecated in Twig Tweak 2.4 and will not be supported in Twig Tweak 3.0'
,
E_USER_DEPRECATED
);
$entity
=
\Drupal
::
routeMatch
()
->
getParameter
(
$entity_type
);
}
if
(
$entity
&&
(
!
$check_access
||
$entity
->
access
(
'view'
)))
{
$render_controller
=
$entity_type_manager
->
getViewBuilder
(
$entity_type
);
return
$render_controller
->
view
(
$entity
,
$view_mode
,
$langcode
);
...
...
@@ -351,10 +352,13 @@ class TwigExtension extends \Twig_Extension {
* A render array for the field or NULL if the value does not exist.
*/
public
function
drupalField
(
$field_name
,
$entity_type
,
$id
=
NULL
,
$view_mode
=
'default'
,
$langcode
=
NULL
,
$check_access
=
TRUE
)
{
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity
=
$id
?
\Drupal
::
entityTypeManager
()
->
getStorage
(
$entity_type
)
->
load
(
$id
)
:
\Drupal
::
routeMatch
()
->
getParameter
(
$entity_type
);
if
(
$id
)
{
$entity
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
$entity_type
)
->
load
(
$id
);
}
else
{
@
trigger_error
(
'Loading entities from route is deprecated in Twig Tweak 2.4 and will not be supported in Twig Tweak 3.0'
,
E_USER_DEPRECATED
);
$entity
=
\Drupal
::
routeMatch
()
->
getParameter
(
$entity_type
);
}
if
(
$entity
&&
(
!
$check_access
||
$entity
->
access
(
'view'
)))
{
$entity
=
\Drupal
::
service
(
'entity.repository'
)
->
getTranslationFromContext
(
$entity
,
$langcode
);
...
...
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