Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
typed_entity
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
typed_entity
Commits
11386544
Commit
11386544
authored
May 12, 2020
by
Mateu Aguiló Bosch
Committed by
Mateu Aguiló Bosch
May 12, 2020
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3135987
by e0ipso: Revert constructor changes on base class
parent
48964c5d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/WrappedEntities/WrappedEntityBase.php
+57
-14
57 additions, 14 deletions
src/WrappedEntities/WrappedEntityBase.php
with
57 additions
and
14 deletions
src/WrappedEntities/WrappedEntityBase.php
+
57
−
14
View file @
11386544
...
@@ -79,25 +79,16 @@ abstract class WrappedEntityBase implements WrappedEntityInterface, RenderableIn
...
@@ -79,25 +79,16 @@ abstract class WrappedEntityBase implements WrappedEntityInterface, RenderableIn
*
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to wrap.
* The entity to wrap.
* @param \Drupal\typed_entity\RepositoryManager $repository_manager
* The repository manager.
* @param \Drupal\Core\Entity\EntityViewBuilderInterface $entity_view_builder
* The view builder.
*/
*/
public
function
__construct
(
EntityInterface
$entity
,
RepositoryManager
$repository_manager
,
EntityViewBuilderInterface
$entity_view_builder
)
{
public
function
__construct
(
EntityInterface
$entity
)
{
$this
->
entity
=
$entity
;
$this
->
entity
=
$entity
;
$this
->
repositoryManager
=
$repository_manager
;
$this
->
viewBuilder
=
$entity_view_builder
;
}
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
static
function
create
(
ContainerInterface
$container
,
EntityInterface
$entity
)
{
public
static
function
create
(
ContainerInterface
$container
,
EntityInterface
$entity
)
{
$entity_view_builder
=
$container
->
get
(
'entity_type.manager'
)
return
new
static
(
$entity
);
->
getViewBuilder
(
$entity
->
getEntityTypeId
());
$repository_manager
=
$container
->
get
(
RepositoryManager
::
class
);
return
new
static
(
$entity
,
$repository_manager
,
$entity_view_builder
);
}
}
/**
/**
...
@@ -140,7 +131,7 @@ abstract class WrappedEntityBase implements WrappedEntityInterface, RenderableIn
...
@@ -140,7 +131,7 @@ abstract class WrappedEntityBase implements WrappedEntityInterface, RenderableIn
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
toRenderable
():
array
{
public
function
toRenderable
():
array
{
return
$this
->
viewBuilder
->
view
(
$this
->
getEntity
(),
$this
->
viewMode
);
return
$this
->
viewBuilder
()
->
view
(
$this
->
getEntity
(),
$this
->
viewMode
);
}
}
/**
/**
...
@@ -161,7 +152,7 @@ abstract class WrappedEntityBase implements WrappedEntityInterface, RenderableIn
...
@@ -161,7 +152,7 @@ abstract class WrappedEntityBase implements WrappedEntityInterface, RenderableIn
if
(
!
$target_entity
instanceof
EntityInterface
)
{
if
(
!
$target_entity
instanceof
EntityInterface
)
{
continue
;
continue
;
}
}
$references
[]
=
$this
->
repositoryManager
->
wrap
(
$target_entity
);
$references
[]
=
$this
->
repositoryManager
()
->
wrap
(
$target_entity
);
}
}
return
$references
;
return
$references
;
...
@@ -183,7 +174,59 @@ abstract class WrappedEntityBase implements WrappedEntityInterface, RenderableIn
...
@@ -183,7 +174,59 @@ abstract class WrappedEntityBase implements WrappedEntityInterface, RenderableIn
if
(
!
$target_entity
instanceof
EntityInterface
)
{
if
(
!
$target_entity
instanceof
EntityInterface
)
{
return
NULL
;
return
NULL
;
}
}
return
$this
->
repositoryManager
->
wrap
(
$target_entity
);
return
$this
->
repositoryManager
()
->
wrap
(
$target_entity
);
}
/**
* Lazy initialized of the repository manager.
*
* @return \Drupal\typed_entity\RepositoryManager
* The repository manager.
*/
protected
function
repositoryManager
():
RepositoryManager
{
if
(
!
$this
->
repositoryManager
)
{
$this
->
repositoryManager
=
\Drupal
::
service
(
RepositoryManager
::
class
);
}
return
$this
->
repositoryManager
;
}
/**
* Lazy initialized of the view builder.
*
* @return \Drupal\Core\Entity\EntityViewBuilderInterface
* The repository manager.
*/
protected
function
viewBuilder
():
EntityViewBuilderInterface
{
if
(
!
$this
->
viewBuilder
)
{
$entity
=
$this
->
getEntity
()
->
getEntityTypeId
();
$entity_type_manager
=
\Drupal
::
entityTypeManager
();
$this
->
viewBuilder
=
$entity_type_manager
->
getViewBuilder
(
$entity
);
}
return
$this
->
viewBuilder
;
}
/**
* Sets the view builder.
*
* This is mostly here for testing ergonomics.
*
* @param \Drupal\Core\Entity\EntityViewBuilderInterface $view_builder
* The view builder.
*/
public
function
setViewBuilder
(
EntityViewBuilderInterface
$view_builder
):
void
{
$this
->
viewBuilder
=
$view_builder
;
}
/**
* Sets the repository manager.
*
* This is mostly here for testing ergonomics.
*
* @param \Drupal\typed_entity\RepositoryManager $repository_manager
* The manager.
*/
public
function
setRepositoryManager
(
RepositoryManager
$repository_manager
):
void
{
$this
->
repositoryManager
=
$repository_manager
;
}
}
}
}
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