Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
eca-3382070
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
eca-3382070
Commits
39428409
Commit
39428409
authored
2 years ago
by
Jürgen Haas
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3271039
: Check events against the triggered event name
parent
9c314d43
No related branches found
Branches containing commit
Tags
5.5.0
8.x-5.5
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Entity/EcaStorage.php
+14
-13
14 additions, 13 deletions
src/Entity/EcaStorage.php
src/EventSubscriber/EcaBase.php
+3
-2
3 additions, 2 deletions
src/EventSubscriber/EcaBase.php
src/Processor.php
+3
-2
3 additions, 2 deletions
src/Processor.php
with
20 additions
and
17 deletions
src/Entity/EcaStorage.php
+
14
−
13
View file @
39428409
...
...
@@ -107,11 +107,13 @@ class EcaStorage extends ConfigEntityStorage {
*
* @param \Drupal\Component\EventDispatcher\Event $event
* The event object.
* @param string $event_name
* The name of the event.
*
* @return \Drupal\eca\Entity\Eca[]
* The configurations, keyed by entity ID.
*/
public
function
loadByEvent
(
Event
$event
):
array
{
public
function
loadByEvent
(
Event
$event
,
string
$event_name
):
array
{
if
(
!
isset
(
$this
->
configByEvents
))
{
$cid
=
'eca:storage:events'
;
if
(
$cached
=
$this
->
cacheBackend
->
get
(
$cid
))
{
...
...
@@ -130,16 +132,16 @@ class EcaStorage extends ConfigEntityStorage {
foreach
(
$eca
->
getUsedEvents
()
as
$ecaEvent
)
{
$eca_id
=
$eca
->
id
();
$plugin
=
$ecaEvent
->
getPlugin
();
$
used_class
=
$plugin
->
drupal
EventClass
();
$
drupal_id
=
$plugin
->
drupal
Id
();
$wildcard
=
$plugin
->
lazyLoadingWildcard
(
$eca_id
,
$ecaEvent
);
if
(
!
isset
(
$this
->
configByEvents
[
$
used_class
]))
{
$this
->
configByEvents
[
$
used_class
]
=
[
$eca_id
=>
[
$wildcard
]];
if
(
!
isset
(
$this
->
configByEvents
[
$
drupal_id
]))
{
$this
->
configByEvents
[
$
drupal_id
]
=
[
$eca_id
=>
[
$wildcard
]];
}
elseif
(
!
isset
(
$this
->
configByEvents
[
$
used_class
][
$eca_id
]))
{
$this
->
configByEvents
[
$
used_class
][
$eca_id
]
=
[
$wildcard
];
elseif
(
!
isset
(
$this
->
configByEvents
[
$
drupal_id
][
$eca_id
]))
{
$this
->
configByEvents
[
$
drupal_id
][
$eca_id
]
=
[
$wildcard
];
}
elseif
(
!
in_array
(
$wildcard
,
$this
->
configByEvents
[
$
used_class
][
$eca_id
],
TRUE
))
{
$this
->
configByEvents
[
$
used_class
][
$eca_id
][]
=
$wildcard
;
elseif
(
!
in_array
(
$wildcard
,
$this
->
configByEvents
[
$
drupal_id
][
$eca_id
],
TRUE
))
{
$this
->
configByEvents
[
$
drupal_id
][
$eca_id
][]
=
$wildcard
;
}
}
}
...
...
@@ -147,14 +149,13 @@ class EcaStorage extends ConfigEntityStorage {
$this
->
logger
->
debug
(
'Rebuilt cache array for EcaStorage::loadByEvent().'
);
}
}
$class
=
get_class
(
$event
);
if
(
empty
(
$this
->
configByEvents
[
$class
]))
{
if
(
empty
(
$this
->
configByEvents
[
$event_name
]))
{
return
[];
}
$context
=
[
'%event'
=>
$
class
];
$context
=
[
'%event'
=>
$
event_name
];
if
(
$event
instanceof
ConditionalApplianceInterface
)
{
$eca_ids
=
[];
foreach
(
$this
->
configByEvents
[
$
class
]
as
$eca_id
=>
$wildcards
)
{
foreach
(
$this
->
configByEvents
[
$
event_name
]
as
$eca_id
=>
$wildcards
)
{
$wildcard_passed
=
FALSE
;
$context
[
'%ecaid'
]
=
$eca_id
;
foreach
(
$wildcards
as
$wildcard
)
{
...
...
@@ -170,7 +171,7 @@ class EcaStorage extends ConfigEntityStorage {
}
}
else
{
$eca_ids
=
array_keys
(
$this
->
configByEvents
[
$
class
]);
$eca_ids
=
array_keys
(
$this
->
configByEvents
[
$
event_name
]);
}
if
(
$eca_ids
)
{
$context
[
'%eca_ids'
]
=
implode
(
', '
,
$eca_ids
);
...
...
This diff is collapsed.
Click to expand it.
src/EventSubscriber/EcaBase.php
+
3
−
2
View file @
39428409
...
...
@@ -37,10 +37,11 @@ abstract class EcaBase implements EventSubscriberInterface {
/**
* @param \Drupal\Component\EventDispatcher\Event $event
* @param string $event_name
*/
public
function
onEvent
(
Event
$event
):
void
{
public
function
onEvent
(
Event
$event
,
string
$event_name
):
void
{
try
{
$this
->
processor
->
execute
(
$event
);
$this
->
processor
->
execute
(
$event
,
$event_name
);
}
catch
(
InvalidPluginDefinitionException
|
PluginNotFoundException
$e
)
{
// This is thrown during installation of eca and we can ignore this.
...
...
This diff is collapsed.
Click to expand it.
src/Processor.php
+
3
−
2
View file @
39428409
...
...
@@ -91,17 +91,18 @@ class Processor {
* Main method that executes ECA config regards applying events.
*
* @param \Drupal\Component\EventDispatcher\Event $event
* @param string $event_name
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public
function
execute
(
Event
$event
):
void
{
public
function
execute
(
Event
$event
,
string
$event_name
):
void
{
$context
=
[
'%event'
=>
get_class
(
$event
),
];
/** @var \Drupal\eca\Entity\EcaStorage $eca_storage */
$eca_storage
=
$this
->
entityTypeManager
->
getStorage
(
'eca'
);
foreach
(
$eca_storage
->
loadByEvent
(
$event
)
as
$eca
)
{
foreach
(
$eca_storage
->
loadByEvent
(
$event
,
$event_name
)
as
$eca
)
{
unset
(
$context
[
'%eventlabel'
],
$context
[
'%eventid'
]);
$context
[
'%ecalabel'
]
=
$eca
->
label
();
$context
[
'%ecaid'
]
=
$eca
->
id
();
...
...
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