Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
recurring_events
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
recurring_events
Commits
b4a55e85
Commit
b4a55e85
authored
4 years ago
by
Owen Bush
Committed by
Owen Bush
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3178669
by owenbush: Publishing Series Workflow Should Be Reflected in Instances
parent
f42c6001
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
recurring_events.module
+16
-1
16 additions, 1 deletion
recurring_events.module
src/EventCreationService.php
+61
-1
61 additions, 1 deletion
src/EventCreationService.php
with
77 additions
and
2 deletions
recurring_events.module
+
16
−
1
View file @
b4a55e85
...
@@ -173,9 +173,11 @@ function recurring_events_eventseries_insert(EntityInterface $entity) {
...
@@ -173,9 +173,11 @@ function recurring_events_eventseries_insert(EntityInterface $entity) {
if
(
empty
(
$instance
->
eventseries_id
->
target_id
))
{
if
(
empty
(
$instance
->
eventseries_id
->
target_id
))
{
$instance
->
set
(
'eventseries_id'
,
$entity
->
id
());
$instance
->
set
(
'eventseries_id'
,
$entity
->
id
());
$instance
->
setNewRevision
(
FALSE
);
$instance
->
setNewRevision
(
FALSE
);
$instance
->
save
();
$creation_service
->
configureDefaultInheritances
(
$instance
,
$entity
->
id
());
$creation_service
->
configureDefaultInheritances
(
$instance
,
$entity
->
id
());
$creation_service
->
updateInstanceStatus
(
$instance
,
$entity
);
$instance
->
save
();
}
}
}
}
}
}
...
@@ -221,10 +223,23 @@ function recurring_events_field_inheritance_update(EntityInterface $entity) {
...
@@ -221,10 +223,23 @@ function recurring_events_field_inheritance_update(EntityInterface $entity) {
function
recurring_events_eventseries_update
(
EntityInterface
$entity
)
{
function
recurring_events_eventseries_update
(
EntityInterface
$entity
)
{
$creation_service
=
\Drupal
::
service
(
'recurring_events.event_creation_service'
);
$creation_service
=
\Drupal
::
service
(
'recurring_events.event_creation_service'
);
$instances
=
$entity
->
event_instances
->
referencedEntities
();
$instances
=
$entity
->
event_instances
->
referencedEntities
();
$updated_statuses
=
$skipped_statuses
=
0
;
if
(
!
empty
(
$instances
))
{
if
(
!
empty
(
$instances
))
{
foreach
(
$instances
as
$instance
)
{
foreach
(
$instances
as
$instance
)
{
$creation_service
->
configureDefaultInheritances
(
$instance
,
$entity
->
id
());
$creation_service
->
configureDefaultInheritances
(
$instance
,
$entity
->
id
());
$status_updated
=
$creation_service
->
updateInstanceStatus
(
$instance
,
$entity
);
if
(
$status_updated
)
{
$updated_statuses
++
;
$instance
->
save
();
}
else
{
$skipped_statuses
++
;
}
}
}
\Drupal
::
messenger
()
->
addMessage
(
t
(
'Successfully updated @success instance statuses. Skipped @skipped instances due to status or workflow mismatch with series.'
,
[
'@success'
=>
$updated_statuses
,
'@skipped'
=>
$skipped_statuses
,
]));
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/EventCreationService.php
+
61
−
1
View file @
b4a55e85
...
@@ -135,7 +135,8 @@ class EventCreationService {
...
@@ -135,7 +135,8 @@ class EventCreationService {
$container
->
get
(
'plugin.manager.field.field_type'
),
$container
->
get
(
'plugin.manager.field.field_type'
),
$container
->
get
(
'entity_field.manager'
),
$container
->
get
(
'entity_field.manager'
),
$container
->
get
(
'module_handler'
),
$container
->
get
(
'module_handler'
),
$container
->
get
(
'entity_type.manager'
)
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'keyvalue'
)
);
);
}
}
...
@@ -660,4 +661,63 @@ class EventCreationService {
...
@@ -660,4 +661,63 @@ class EventCreationService {
return
$recur_fields
;
return
$recur_fields
;
}
}
/**
* Update instance status.
*
* @param Drupal\recurring_events\Entity\EventInstance $instance
* The event instance for which to update the status.
* @param Drupal\recurring_events\Entity\EventSeries $event
* The event series entity.
*/
public
function
updateInstanceStatus
(
EventInstance
$instance
,
EventSeries
$event
)
{
$original_event
=
$event
->
original
;
$field_name
=
'status'
;
if
(
$this
->
moduleHandler
->
moduleExists
(
'workflows'
))
{
if
(
$event
->
hasField
(
'moderation_state'
)
&&
$instance
->
hasField
(
'moderation_state'
))
{
$series_query
=
$this
->
entityTypeManager
->
getStorage
(
'workflow'
)
->
getQuery
();
$series_query
->
condition
(
'type_settings.entity_types.eventseries.*'
,
$event
->
bundle
());
$series_workflows
=
$series_query
->
execute
();
$series_workflows
=
array_keys
(
$series_workflows
);
$series_workflow
=
reset
(
$series_workflows
);
$instance_query
=
$this
->
entityTypeManager
->
getStorage
(
'workflow'
)
->
getQuery
();
$instance_query
->
condition
(
'type_settings.entity_types.eventinstance.*'
,
$instance
->
bundle
());
$instance_workflows
=
$instance_query
->
execute
();
$instance_workflows
=
array_keys
(
$instance_workflows
);
$instance_workflow
=
reset
(
$instance_workflows
);
// We only want to mimic moderation state if the series and instance use
// the same workflows, otherwise we cannot guarantee the states match.
if
(
$instance_workflow
===
$series_workflow
)
{
$field_name
=
'moderation_state'
;
}
else
{
return
FALSE
;
}
}
}
$new_state
=
$event
->
get
(
$field_name
)
->
getValue
();
$instance_state
=
$instance
->
get
(
$field_name
)
->
getValue
();
if
(
!
empty
(
$original_event
))
{
$original_state
=
$original_event
->
get
(
$field_name
)
->
getValue
();
}
else
{
$instance
->
set
(
$field_name
,
$new_state
);
return
TRUE
;
}
// If the instance state matches the original state of the series we want
// to also update the instance state.
if
(
$instance_state
===
$original_state
)
{
$instance
->
set
(
$field_name
,
$new_state
);
return
TRUE
;
}
return
FALSE
;
}
}
}
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