Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the message stack for content subscriptions #192

Open
jurgenhaas opened this issue May 30, 2017 · 2 comments
Open

How to use the message stack for content subscriptions #192

jurgenhaas opened this issue May 30, 2017 · 2 comments

Comments

@jurgenhaas
Copy link

For a customer of mine who runs a forum on their D8 site I'm looking for a solution to allow users to subscribe to entities and get notified when new comments are submitted.

Looks like the message stack is what I need and message_subscribe is the right approach. That requires the flag module which seems to be working, at least I get the subscribe records in the database when users do subscribe to entities.

But no messages are created when a new comment gets submitted.

Now I'm wondering if there is something special on how to configure all that or if it's simply that either flag or message stack is not quite ready yet.

@jhedstrom
Copy link
Collaborator

jhedstrom commented Sep 22, 2017

The message stack provides everything but the logic to actually create the messages. This is typically done in a site-specific way using hook_ENTITY_TYPE_insert/update(). I think the message subscribe module should provide an example module that demonstrates this.

Here's an example:

function mymodule_node_update(EntityInterface $node) {
  /** @var \Drupal\message\MessageInterface $message */
  $message = \Drupal::entityTypeManager()->getStorage('message')->create([
     'uid' => $node->getOwnerId(),
     // This is the message template ID that should be used.
     'template' => 'my_message_template',
  ]);

  $subscribers = \Drupal::service('message_subscribe.subscribers');
  $subscribers->sendMessage($node, $message);
}

@OnkelTem
Copy link

@jhedstrom Could you please provide some help in a follow-up here: #245
Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants