Drupal is a registered trademark of Dries Buytaert
Release: Drupal 10.3.6 Update released for Drupal core (10.3.6)! Release: Drupal 11.0.5 Update released for Drupal core (11.0.5)! Release: Drupal 10.2.9 Update released for Drupal core (10.2.9)! Release: Drupal 10.2.10 Update released for Drupal core (10.2.10)! Release: Drupal 10.3.7 Update released for Drupal core (10.3.7)! Release: Drupal 11.0.6 Update released for Drupal core (11.0.6)! Release: Drupal 10.3.8 Update released for Drupal core (10.3.8)! Release: Drupal 11.0.7 Update released for Drupal core (11.0.7)! Module Revived: Translation Management Tool 8.x-1.19 Module tmgmt updated after 7 months of inactivity (8.x-1.19). Usage Milestone: Account field split Module account_field_split crossed 10,000 active installs.

Registers Symfony Webhook component's webhook receiver features in Drupal.

Before you start

Read Symfony's official Webhook component documentation and
read the additions to that in this pull request if it is still open to understand the fundamental concepts.

Define your own webhook type

To define a custom webhook type, register the required services in your [MY_MODULE].services.yml file:

services:
  _defaults:
    autowire: true
    public: false

  my_module.webhook.request_parser.my_type:
    parent: symfony_webhook_receiver.request_parser # Or use your own \Symfony\Component\Webhook\Client\RequestParserInterface implementation.
    tags:
      - { name: webhook.request_parser, type: my_type }

  my_module.webhook.remote_event.consumer.my_type:
    class: Drupal\my_module\MyTypeConsumer
    # Remote Event Consumers have to be public otherwise service locator
    # does not find them.
    public: true
    tags:
      - { name: remote_event.consumer, type: my_type }

In this example:

  • my_type represents your custom webhook type.
  • Replace my_module with your module name.
  • The MyTypeConsumer class must implement the \Symfony\Component\RemoteEvent\Consumer\ConsumerInterface.

Remote Event Consumer auto-discovery

A Remote Event Consumer class residing in the src/RemoteEventConsumer
directory of a module is auto-discoverable. It has to have a
#[AsRemoteEventConsumer] attribute on the class and it must implement the
\Symfony\Component\RemoteEvent\Consumer\ConsumerInterface interface.

See ExampleAutoDiscoverConsumer as example.

The rest of the necessary configuration with defining a parser and secret for
the webhook type remains the same.

Configure secret for webhook type

Secrets are essential for securing webhook communications. To configure the secret for your custom webhook type, follow these steps:

  1. Ensure your service configuration is included:

    In web/sites/default/settings.local.php, make sure to include services.local.yml (or a dedicated service file) in the container YAML files:

    $settings['container_yamls'][] = __DIR__ . '/services.local.yml';
    
  2. Define the secret for your webhook type:

    In the services.local.yml file, define the secret for your webhook type as a parameter:

    parameters:
      symfony_webhook_receiver.request_parser.my_type.secret: 'my_super_secret'
    

    Make sure to replace 'my_super_secret' with your actual secret.

Extending functionality

You can enhance and extend the behavior of your webhook receivers in the following ways:

  • Fetch secrets from environment variables:

    If you'd prefer to retrieve secrets from environment variables, you will need to create a custom ServiceProvider and implement a CompilerPass. This will allow you to capture the value from an environment variable and set it as the corresponding container parameter.

    Since Drupal currently lacks native support for environment variables as container parameters, this approach can be particularly useful.

  • Create a custom WebhookController:

    Another option is to build a custom WebhookController that fetches secrets from an alternative location, such as a secure storage service. Even with a custom controller, you can still leverage the reusable components provided by the Symfony Webhook package.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Oct 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.0 Stable Oct 7, 2024
1.x-dev Dev Oct 7, 2024