Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
entity_workflow
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
entity_workflow
Commits
9eb4492b
Commit
9eb4492b
authored
11 months ago
by
Andrei Mateescu
Browse files
Options
Downloads
Patches
Plain Diff
Ensure that all related path aliases and menu links are transitioned automatically if needed.
parent
104b104f
Branches
Branches containing commit
Tags
2.0.0-alpha9
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/entity_workflow_content/src/Plugin/WorkflowType/EntityWorkflowContent.php
+42
-11
42 additions, 11 deletions
...content/src/Plugin/WorkflowType/EntityWorkflowContent.php
with
42 additions
and
11 deletions
modules/entity_workflow_content/src/Plugin/WorkflowType/EntityWorkflowContent.php
+
42
−
11
View file @
9eb4492b
...
...
@@ -4,12 +4,15 @@ namespace Drupal\entity_workflow_content\Plugin\WorkflowType;
use
Drupal\Core\Cache\Cache
;
use
Drupal\Core\Entity\ContentEntityInterface
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\entity_workflow
\WorkflowType\EntityWorkflowTypeBase
;
use
Drupal\menu_link_content
\Entity\MenuLinkContent
;
use
Drupal\path_alias
\Entity\PathAlias
;
use
Drupal\workflows\TransitionInterface
;
use
Drupal\workflows\WorkflowInterface
;
use
Drupal\workspaces\WorkspaceAssociationInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* @WorkflowType(
...
...
@@ -28,6 +31,20 @@ use Drupal\workflows\WorkflowInterface;
*/
class
EntityWorkflowContent
extends
EntityWorkflowTypeBase
{
/**
* The workspace association.
*/
protected
WorkspaceAssociationInterface
$workspaceAssociation
;
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
$instance
=
parent
::
create
(
$container
,
$configuration
,
$plugin_id
,
$plugin_definition
);
$instance
->
workspaceAssociation
=
$container
->
get
(
'workspaces.association'
);
return
$instance
;
}
/**
* {@inheritdoc}
*/
...
...
@@ -152,19 +169,33 @@ class EntityWorkflowContent extends EntityWorkflowTypeBase {
// for nodes, etc.
$related_entities
=
[];
// Add the entity's path alias.
foreach
(
$entity
->
getFieldDefinitions
()
as
$field
=>
$field_definition
)
{
if
(
$field_definition
->
getType
()
===
'path'
&&
(
$path_alias_id
=
$entity
->
get
(
$field
)
->
get
(
0
)
->
pid
))
{
$related_entities
[]
=
PathAlias
::
load
(
$path_alias_id
);
}
// Add the entity's path aliases.
if
(
$entity
->
hasLinkTemplate
(
'canonical'
)
&&
$this
->
entityTypeManager
->
hasDefinition
(
'path_alias'
))
{
$path
=
$entity
->
toUrl
(
'canonical'
,
[
'path_processing'
=>
FALSE
])
->
toString
();
$aliases
=
$this
->
entityTypeManager
->
getStorage
(
'path_alias'
)
->
loadByProperties
([
'path'
=>
$path
]);
$related_entities
=
array_merge
(
$related_entities
,
$aliases
);
}
// Add the menu links for nodes.
if
(
$entity
->
getEntityTypeId
()
===
'node'
&&
$this
->
entityTypeManager
->
hasDefinition
(
'menu_link_content'
))
{
$menu_links
=
$this
->
entityTypeManager
->
getStorage
(
'menu_link_content'
)
->
loadByProperties
([
'link.uri'
=>
'entity:node/'
.
$entity
->
id
()]);
$related_entities
=
array_merge
(
$related_entities
,
$menu_links
);
}
// Add the menu link for nodes.
if
(
$entity
->
getEntityTypeId
()
===
'node'
)
{
$menu_defaults
=
menu_ui_get_menu_link_defaults
(
$entity
);
if
(
$menu_link_id
=
$menu_defaults
[
'entity_id'
])
{
$related_entities
[]
=
MenuLinkContent
::
load
(
$menu_link_id
);
}
// Ensure that we only auto-transition related entities that are already
// tracked by the current workspace.
if
(
$workspace
=
$this
->
workspaceManager
->
getActiveWorkspace
())
{
$tracked_entities
=
$this
->
workspaceAssociation
->
getTrackedEntities
(
$workspace
->
id
());
$related_entities
=
array_filter
(
$related_entities
,
function
(
EntityInterface
$entity
)
use
(
$tracked_entities
)
{
return
isset
(
$tracked_entities
[
$entity
->
getEntityTypeId
()])
&&
in_array
(
$entity
->
id
(),
$tracked_entities
[
$entity
->
getEntityTypeId
()]);
});
}
foreach
(
$related_entities
as
$entity
)
{
...
...
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