Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
push_framework
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
push_framework
Commits
2d7afe8f
Commit
2d7afe8f
authored
1 year ago
by
Jürgen Haas
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3378397
by jurgenhaas: Fix notify action to specify the recipient
parent
980a6164
Branches
2.2.x
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/Action/Notify.php
+19
-34
19 additions, 34 deletions
src/Plugin/Action/Notify.php
with
19 additions
and
34 deletions
src/Plugin/Action/Notify.php
+
19
−
34
View file @
2d7afe8f
...
...
@@ -8,10 +8,9 @@ use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\Core\Session\AccountProxyInterface
;
use
Drupal\node\Entity\Node
;
use
Drupal\push_framework
\ChannelPluginManager
;
use
Drupal\
Core\Plugin\ContextAwarePluginManag
erInterface
;
use
Drupal\
user\Us
erInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
...
...
@@ -19,7 +18,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* @Action(
* id = "push_framework_notify",
* label = @Translation("Push a notification to a channel.")
* label = @Translation("Push a notification to a channel."),
* type = "user"
* )
*/
class
Notify
extends
ConfigurableActionBase
implements
ContainerFactoryPluginInterface
{
...
...
@@ -38,16 +38,6 @@ class Notify extends ConfigurableActionBase implements ContainerFactoryPluginInt
*/
protected
EntityTypeBundleInfoInterface
$entityTypeBundleInfo
;
/**
* The current user account.
*
* @var \Drupal\Core\Session\AccountProxyInterface
* Represents the currently authenticated user session within Drupal.
* Provides methods to retrieve information about the user,
* such as their ID, username, roles, and permissions.
*/
protected
AccountProxyInterface
$currentUser
;
/**
* Constructs a new instance of the class.
*
...
...
@@ -57,21 +47,15 @@ class Notify extends ConfigurableActionBase implements ContainerFactoryPluginInt
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\
Core\Plugin\ContextAware
PluginManager
Interface
$channelPluginManager
* @param \Drupal\
push_framework\Channel
PluginManager $channelPluginManager
* The channel plugin manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo
* The entity type bundle info service.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user account.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* The entity type and bundle info service.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
C
ontextAware
PluginManager
Interface
$channelPluginManager
,
EntityTypeBundleInfoInterface
$entityTypeBundleInfo
,
AccountProxyInterface
$currentUser
,
EntityTypeManagerInterface
$entity_type_manager
)
{
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
C
hannel
PluginManager
$channelPluginManager
,
EntityTypeBundleInfoInterface
$entityTypeBundleInfo
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
channelPluginManager
=
$channelPluginManager
;
$this
->
entityTypeBundleInfo
=
$entityTypeBundleInfo
;
$this
->
currentUser
=
$currentUser
;
$this
->
userStorage
=
$entity_type_manager
->
getStorage
(
'user'
);
}
/**
...
...
@@ -86,7 +70,7 @@ class Notify extends ConfigurableActionBase implements ContainerFactoryPluginInt
* @param mixed $plugin_definition
* The plugin definition.
*
* @return \Drupal\
your_module
\Notify
* @return \Drupal\
push_framework\Plugin\Action
\Notify
* The new instance of the Notify class.
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
):
Notify
{
...
...
@@ -95,9 +79,7 @@ class Notify extends ConfigurableActionBase implements ContainerFactoryPluginInt
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'push_framework.channel.plugin.manager'
),
$container
->
get
(
'entity_type.bundle.info'
),
$container
->
get
(
'current_user'
),
$container
->
get
(
'entity_type.manager'
)
$container
->
get
(
'entity_type.bundle.info'
)
);
}
...
...
@@ -105,15 +87,17 @@ class Notify extends ConfigurableActionBase implements ContainerFactoryPluginInt
* {@inheritdoc}
*/
public
function
access
(
$object
,
AccountInterface
$account
=
NULL
,
$return_as_object
=
FALSE
)
{
$result
=
AccessResult
::
allowed
(
);
$result
=
AccessResult
::
allowed
If
(
$object
instanceof
UserInterface
);
try
{
$channelPlugin
=
$this
->
channelPluginManager
->
createInstance
(
$this
->
configuration
[
'channel'
]);
if
(
$channelPlugin
===
NULL
)
{
throw
new
\RuntimeExceptio
n
(
'The given channel does not exist.'
);
$result
=
AccessResult
::
forbidde
n
(
'The given channel does not exist.'
);
}
$bundles
=
$this
->
entityTypeBundleInfo
->
getBundleInfo
(
'node'
);
if
(
!
isset
(
$bundles
[
$this
->
configuration
[
'node_type'
]]))
{
throw
new
\RuntimeException
(
'The given node type does not exist.'
);
else
{
$bundles
=
$this
->
entityTypeBundleInfo
->
getBundleInfo
(
'node'
);
if
(
!
isset
(
$bundles
[
$this
->
configuration
[
'node_type'
]]))
{
$result
=
AccessResult
::
forbidden
(
'The given node type does not exist.'
);
}
}
}
catch
(
\Exception
$e
)
{
...
...
@@ -125,10 +109,11 @@ class Notify extends ConfigurableActionBase implements ContainerFactoryPluginInt
/**
* {@inheritdoc}
*/
public
function
execute
():
void
{
public
function
execute
(
$object
=
NULL
):
void
{
/** @var \Drupal\push_framework\ChannelPluginInterface $channelPlugin */
$channelPlugin
=
$this
->
channelPluginManager
->
createInstance
(
$this
->
configuration
[
'channel'
]);
$user
=
$this
->
userStorage
->
load
(
$this
->
currentUser
->
id
());
/** @var \Drupal\user\UserInterface $user */
$user
=
$object
;
/** @var \Drupal\node\Entity\Node $node */
$node
=
Node
::
create
([
'type'
=>
$this
->
configuration
[
'node_type'
],
...
...
@@ -150,7 +135,7 @@ class Notify extends ConfigurableActionBase implements ContainerFactoryPluginInt
'body_field'
=>
'body'
,
'subject'
=>
''
,
'body'
=>
''
,
];
]
+
parent
::
defaultConfiguration
()
;
}
/**
...
...
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