Commit 3a49776d authored by swentel's avatar swentel

Example hook

parent 2e48e9af
......@@ -138,11 +138,51 @@ follow users and then use your favorite client to read content and interact via
Micropub.
If you are using a Micropub client (or in-built in a Reader), using one or
more syndication targets can help you to create an outbox request. This
requires implementing a hook, for example:
more syndication targets can help you to create an outbox request. Create a
syndication target which is not a URL. These won't be added then to the
webmention queue. Once done, you need to implement a hook with custom code:
```
/**
* Implements hook_indieweb_micropub_node_saved().
*/
function hook_indieweb_micropub_node_saved(NodeInterface $node, $values, $payload, $payload_original) {
if (!empty($payload_original['mp-syndicate-to'])) {
foreach ($payload_original['mp-syndicate-to'] as $target) {
switch ($target) {
// Value of syndication target.
case 'activitypub_reply':
if ($node->bundle() == 'reply') {
$values = [
'status' => TRUE,
'collection' => 'outbox',
// id of reply config entity
'config_id' => 'reply',
'uid' => $node->getOwnerId(),
// Replace {actor_name} with the activitypub name.
'actor' => 'https://yourdomain.com/user/1/activitypub/{actor_name}',
'entity_type_id' => 'node',
'entity_id' => $node->id(),
'processed' => FALSE,
];
// This is a reply, so we have the in-reply-to microformat value.
// Other values of this can be 'followers' or the canonical link
// of a user.
$values['object'] = $payload_original['in-reply-to'][0];
/** @var \Drupal\activitypub\Entity\ActivityPubActivityInterface $activity */
$activity = \Drupal::entityTypeManager()->getStorage('activitypub_activity')->create($values);
$activity->save();
\Drupal::service('activitypub.outbox.client')->createQueueItem($activity);
Cache::invalidateTags(['user:' . $node->getOwnerId()]);
}
break;
}
}
}
}
```
### Can I send DM's
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment