PHPackages                             sensiolabs-de/storyblok-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. sensiolabs-de/storyblok-bundle

Abandoned → [storyblok/symfony-bundle](/?search=storyblok%2Fsymfony-bundle)Symfony-bundle

sensiolabs-de/storyblok-bundle
==============================

Symfony bundle for sensiolabs-de/storyblok-api

0.4.1(1y ago)26.8k[2 PRs](https://github.com/sensiolabs-de/storyblok-bundle/pulls)MITPHPPHP &gt;=8.3CI passing

Since Sep 28Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/sensiolabs-de/storyblok-bundle)[ Packagist](https://packagist.org/packages/sensiolabs-de/storyblok-bundle)[ RSS](/packages/sensiolabs-de-storyblok-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (22)Versions (16)Used By (0)

Storyblok Bundle
================

[](#storyblok-bundle)

BranchPHPCode Coverage`master`[![PHP](https://github.com/sensiolabs-de/storyblok-bundle/actions/workflows/ci.yaml/badge.svg)](https://github.com/sensiolabs-de/storyblok-bundle/actions/workflows/ci.yaml)[![codecov](https://camo.githubusercontent.com/4c10cbdf933e06ee40199990b631b8664856000e21c1bac681a4224919d8388a/68747470733a2f2f636f6465636f762e696f2f67682f73656e73696f6c6162732d64652f73746f7279626c6f6b2d62756e646c652f67726170682f62616467652e7376673f746f6b656e3d4d464d4e43424c4e5842)](https://codecov.io/gh/sensiolabs-de/storyblok-bundle)A Symfony bundle to integrate the [Storyblok headless CMS](https://www.storyblok.com/) with your Symfony application.

This bundle leverages the [sensiolabs-de/storyblok-api](https://github.com/sensiolabs-de/storyblok-api), a type-safe PHP SDK for Storyblok. It configures the Storyblok client and provides a Symfony Profiler extension for easier debugging and monitoring of Storyblok API interactions.

Installation
------------

[](#installation)

To install the bundle run:

```
composer require sensiolabs-de/storyblok-api sensiolabs-de/storyblok-bundle
```

Configuration
-------------

[](#configuration)

### Symfony Flex

[](#symfony-flex)

If you are using `symfony/flex`, the bundle will be automatically enabled and the configuration files will be added to your project.

### Manual Configuration

[](#manual-configuration)

If `symfony/flex` is not available, or you prefer manual setup, follow these steps:

1. **Add the Configuration**Add the following configuration to your `config/packages/storyblok.yaml`:

    ```
    storyblok:
      base_uri: '%env(STORYBLOK_API_BASE_URI)%'
      token: '%env(STORYBLOK_API_TOKEN)%'
    ```

    If you want to use the AssetsApi, you can also add the following configuration:

    ```
    storyblok:
      # ...
      assets_token: '%env(STORYBLOK_ASSETS_API_TOKEN)%'
    ```
2. **Set Environment Variables**Define the necessary environment variables in your `.env` file:

    ```
    STORYBLOK_API_BASE_URI=https://api.storyblok.com/v1
    STORYBLOK_API_TOKEN=your_storyblok_api_token
    ```

Usage
-----

[](#usage)

### API Usage

[](#api-usage)

After setting up the bundle, you can use the Storyblok client within your Symfony application to interact with the Storyblok CMS API.

For detailed usage and examples, please refer to the [Storyblok API SDK documentation](https://github.com/sensiolabs-de/storyblok-api).

### Versions (`draft` and `published`)

[](#versions-draft-and-published)

Storyblok allows you to work with two versions of your content: `draft` and `published`. By default, the bundle uses the `published` version. If you want to use the `draft` version, you can set the `version` parameter in the configuration:

```
storyblok:
    # ...
    version: draft
```

### Webhooks

[](#webhooks)

Storyblok Webhooks allow your Symfony application to react to events like content changes. This bundle provides easy setup for handling these Webhooks.

#### Configuration

[](#configuration-1)

To enable Webhooks, add the following route to your application:

```
# config/routes/storyblok.yaml
storyblok:
    resource: '@StoryblokBundle/config/routes.php'
```

This will make a route available at `/storyblok/webhook` to receive Webhook requests. For more details on how Webhooks work, check the [Storyblok Webhooks Documentation](https://www.storyblok.com/docs/guide/in-depth/webhooks).

#### Verifying Webhook Signatures (Security)

[](#verifying-webhook-signatures-security)

For security, you can enable the verification of Webhook signatures to ensure that the requests come from Storyblok. This is done by configuring a `webhook_secret`:

```
# config/packages/storyblok.yaml
storyblok:
    # ...
    webhook_secret: '%env(STORYBLOK_WEBHOOK_SECRET)%'
```

You'll need to set this secret in your `.env` file:

```
STORYBLOK_WEBHOOK_SECRET=your_webhook_secret
```

Once enabled, the bundle will automatically validate each Webhook request against this secret.

#### Handling Webhook Events

[](#handling-webhook-events)

To process Webhooks, implement the `WebhookHandlerInterface`. The bundle automatically registers any classes implementing this interface as Webhook handlers, no additional service configuration is required.

**Example Webhook Handler**

Here's an example of a Webhook handler that purges a Varnish cache whenever certain events occur (e.g., content published or deleted):

```
