mirror of
https://github.com/directus/directus.git
synced 2026-01-31 22:28:07 -05:00
Merge pull request #3688 from directus/remove-bundles
Remove bundles from docs
This commit is contained in:
@@ -4,9 +4,8 @@
|
||||
|
||||
## 1. Create a Hook File
|
||||
|
||||
Custom hooks are dynamically loaded from within your extensions folder. By default this directory is
|
||||
located at `/extensions`, but it can be configured within your project's env file to be located
|
||||
anywhere. Hooks can be added [standalone](#) or via an [extension bundle](#).
|
||||
Custom hooks are dynamically loaded from within your extensions folder. By default this directory is located at
|
||||
`/extensions`, but it can be configured within your project's env file to be located anywhere.
|
||||
|
||||
### Default Standalone Hook Location
|
||||
|
||||
@@ -14,16 +13,10 @@ anywhere. Hooks can be added [standalone](#) or via an [extension bundle](#).
|
||||
/extensions/hooks/<hook-id>/index.js
|
||||
```
|
||||
|
||||
### Default Bundled Hook Location
|
||||
|
||||
```
|
||||
/extensions/bundles/<bundle-id>/hooks/<hook-id>/index.js
|
||||
```
|
||||
|
||||
## 2. Define the Event
|
||||
|
||||
Next, you will want to define your event. You can trigger your custom hook with any of the
|
||||
platform's many API events. System events are referenced with the format:
|
||||
Next, you will want to define your event. You can trigger your custom hook with any of the platform's many API events.
|
||||
System events are referenced with the format:
|
||||
|
||||
```
|
||||
<scope>.<action>(.<before>)
|
||||
@@ -35,28 +28,26 @@ platform's many API events. System events are referenced with the format:
|
||||
|
||||
### Scope
|
||||
|
||||
The scope determines the API endpoint that is triggered. The `*` wildcard can also be used to
|
||||
include all scopes.
|
||||
The scope determines the API endpoint that is triggered. The `*` wildcard can also be used to include all scopes.
|
||||
|
||||
::: System Scope Currently all system tables are available as event scopes except for
|
||||
`directus_migrations` and `directus_sessions`, which don't have relevant endpoints or services. :::
|
||||
::: System Scope Currently all system tables are available as event scopes except for `directus_migrations` and
|
||||
`directus_sessions`, which don't have relevant endpoints or services. :::
|
||||
|
||||
### Action
|
||||
|
||||
Defines the triggering operation within the specified context (see chart below). The `*` wildcard
|
||||
can also be used to include all actions available to the scope.
|
||||
Defines the triggering operation within the specified context (see chart below). The `*` wildcard can also be used to
|
||||
include all actions available to the scope.
|
||||
|
||||
### Before
|
||||
|
||||
Many scopes (see chart below) support an optional `.before` suffix for running a _blocking_ hook
|
||||
prior to the event being fired. This allows you to check and/or modify the event's payload before it
|
||||
is processed.
|
||||
Many scopes (see chart below) support an optional `.before` suffix for running a _blocking_ hook prior to the event
|
||||
being fired. This allows you to check and/or modify the event's payload before it is processed.
|
||||
|
||||
- `items.create` (Non Blocking)
|
||||
- `items.create.before` (Blocking)
|
||||
- `items.create` (Non Blocking)
|
||||
- `items.create.before` (Blocking)
|
||||
|
||||
This also allows you to cancel an event based on the logic within the hook. Below is an example of
|
||||
how you can cancel a create event by throwing a standard Directus exception.
|
||||
This also allows you to cancel an event based on the logic within the hook. Below is an example of how you can cancel a
|
||||
create event by throwing a standard Directus exception.
|
||||
|
||||
```js
|
||||
module.exports = function registerHook({ exceptions }) {
|
||||
@@ -117,27 +108,27 @@ module.exports = function registerHook() {
|
||||
|
||||
### Register Function
|
||||
|
||||
The register function (eg: `module.exports = function registerHook()`) must return an object where
|
||||
the key is the event, and the value is the handler function itself.
|
||||
The register function (eg: `module.exports = function registerHook()`) must return an object where the key is the event,
|
||||
and the value is the handler function itself.
|
||||
|
||||
The `registerHook` function receives a context parameter with the following properties:
|
||||
|
||||
- `services` — All API interal services
|
||||
- `exceptions` — API exception objects that can be used for throwing "proper" errors
|
||||
- `database` — Knex instance that is connected to the current database
|
||||
- `env` — Parsed environment variables
|
||||
- `services` — All API interal services
|
||||
- `exceptions` — API exception objects that can be used for throwing "proper" errors
|
||||
- `database` — Knex instance that is connected to the current database
|
||||
- `env` — Parsed environment variables
|
||||
|
||||
### Event Handler Function
|
||||
|
||||
The event handler function (eg: `'items.create': function()`) recieves a context parameter with the
|
||||
following properties:
|
||||
The event handler function (eg: `'items.create': function()`) recieves a context parameter with the following
|
||||
properties:
|
||||
|
||||
- `event` — Full event string
|
||||
- `accountability` — Information about the current user
|
||||
- `collection` — Collection that is being modified
|
||||
- `item` — Primary key(s) of the item(s) being modified
|
||||
- `action` — Action that is performed
|
||||
- `payload` — Payload of the request
|
||||
- `event` — Full event string
|
||||
- `accountability` — Information about the current user
|
||||
- `collection` — Collection that is being modified
|
||||
- `item` — Primary key(s) of the item(s) being modified
|
||||
- `action` — Action that is performed
|
||||
- `payload` — Payload of the request
|
||||
|
||||
## 5. Restart the API
|
||||
|
||||
|
||||
Reference in New Issue
Block a user