Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI

on:
pull_request: null

jobs:
Silverstripe:
name: 'Silverstripe (bundle)'
uses: nswdpc/ci-files/.github/workflows/silverstripe_53_83.yml@v-4
PHPStan:
name: 'PHPStan (analyse)'
uses: nswdpc/ci-files/.github/workflows/phpstan.silverstripe_83.yml@v-4
needs: Silverstripe
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
/vendor/
.DS_Store
/.php-cs-fixer.cache
/.phpactor.json
/app/
/public/
/composer.lock
21 changes: 0 additions & 21 deletions .php-cs-fixer.dist.php

This file was deleted.

31 changes: 12 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Datawrapper support for Silverstripe

This module provides an iframe element to embed [Datawrapper](https://datawrapper.de) charts and maps on a page, along with the script to enable responsiveness.
This module provides an iframe element to embed [Datawrapper](https://datawrapper.de) charts and maps on a page, as an Elemental content block, along with the script to enable responsiveness.

### Features

Expand All @@ -15,7 +15,7 @@ See [composer.json](./composer.json)

## Installation

```
```sh
composer require nswdpc/silverstripe-datawrapper
```

Expand All @@ -25,34 +25,27 @@ composer require nswdpc/silverstripe-datawrapper

## Documentation


Further [documentation for content authors](./docs/en/001_index.md) is available.

## Configuration

### Webhooks
### Enable the element

```yaml
Name: 'app-datawrapper'
After:
- '#nswdpc-datawrapper'
NSWDPC\Datawrapper\WebhookController:
webhooks_enabled: true|false
webhooks_random_code: 'a random unguessable code'
```
Add the following to a project configuration,e.g. 'app/_config/datawrapper.yml` to enable the content block on Page records:

If you are using Datwrapper custom webhooks, add a `webhooks_random_code` value.

As there is no shared webhook signing key, anyone with the webhook URL and the Datawrapper Id of an element on your website will be able to publish elements.
You can change this random code at any time but you must ensure the custom webhook URL value at Datawrapper is updated to match.
```yml
Page:
allowed_elements:
- 'NSWDPC\Elemental\Models\Datawrapper\ElementDatawrapper'
```

You can set elements to ignore webhook publishing requests by unchecking the "Auto publish" value on an element.
### Webhooks

Datawrapper custom webhook URLs are Team-based. Only charts in that team will receive a webhook request when they are published.
[See webhooks documentation](./docs/en/002_webhooks.md) for further information.

## Maintainers

+ [dpcdigital@NSWDPC:~$](https://dpc.nsw.gov.au)
+ PD Web Team

## Bugtracker

Expand Down
23 changes: 21 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"authors": [
{
"name": "James Ellis",
"homepage": "https://dpc.nsw.gov.au",
"role": "Developer"
}
],
Expand All @@ -26,7 +25,13 @@
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"friendsofphp/php-cs-fixer": "^3"
"friendsofphp/php-cs-fixer": "^3",
"cambis/silverstripe-rector": "^2",
"cambis/silverstan": "^2",
"nswdpc/ci-files": "dev-v-4",
"phpstan/phpstan": "^2",
"phpstan/phpstan-phpunit": "^2",
"rector/rector": "^2"
},
"autoload": {
"psr-4": {
Expand All @@ -44,9 +49,23 @@
]
}
},
"scripts": {
"phpstan-analyse": "./vendor/bin/phpstan analyse --ansi --no-progress --no-interaction --configuration vendor/nswdpc/ci-files/phpstan/.phpstan.silverstripe.neon src/ tests/",
"rector-dryrun": "./vendor/bin/rector process --dry-run --ansi --config vendor/nswdpc/ci-files/rector/.rector.silverstripe_53_83.php src/ tests/",
"rector-process": "./vendor/bin/rector process --no-diffs --ansi --config vendor/nswdpc/ci-files/rector/.rector.silverstripe_53_83.php src/ tests/",
"phpcsfixer-fix": "./vendor/bin/php-cs-fixer fix --ansi --no-interaction --config vendor/nswdpc/ci-files/php-cs-fixer/.php-cs-fixer.php src/ tests/"
},
"extra": {
"expose": [
"client/static"
]
},
"config": {
"allow-plugins": {
"composer/installers": true,
"silverstripe/vendor-plugin": true,
"silverstripe/recipe-plugin": true,
"phpstan/extension-installer": true
}
}
}
7 changes: 7 additions & 0 deletions docs/en/001_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Documentation

> This requires the Datawrapper content block to be enabled by a developer.

## How to create a element

> Audience: content editors, authors and creators
Expand All @@ -19,7 +21,10 @@ In the "Share & Embed" section on your chart/map:
* You will see a URL like "https://datawrapper.dwcdn.net/abcd1/5/"

<img src="../img/url.png" alt="image showing URL to be copied per instructions" style="border:1px solid #000;">

## Page editing

Add a "Datawrapper visualisation" content block to the Page.

In the "Datawrapper" CMS element you have created, add the URL value provided. You can right click and copy the URL then paste it in the field.

Expand All @@ -43,4 +48,6 @@ To update the version on your website, simply set the "Datawrapper version" fiel

Then save the element to review changes or, optionally, publish.

## Automatic updates on publish

See [webhook setup for options to automatically publish](.002_webhooks.md).
15 changes: 11 additions & 4 deletions docs/en/002_webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ POST /webhook HTTP/1.1
content-type: application/json
content-length: 32

{"id":"abcd1","publicVersion":6}
{"id":"abcd1","publicVersion":6, "user":{"id":123,"email":"user@your-org.com"}}
```

You can use a system such as Pipedream to inspect and debug webhook requests.
Expand All @@ -33,12 +33,19 @@ You can use a system such as Pipedream to inspect and debug webhook requests.

Turn off|on via project configuration, the default is `true`

```yaml
NSWDPC\Datawrapper\Webhook:
webhooks_enabled: true|false
```yml
---
Name: app-datawrapper
After:
- '#nswdpc-datawrapper'
---
NSWDPC\Datawrapper\WebHookController:
webhooks_enabled: true
webhooks_random_code: 'some_random_code_string'
```

Use `webhooks_random_code` to randomise the URL. Using this example, the submission URL will look something like `https://mysite.example.com/_datawrapperwebhook/submit/some_random_code_string/`

This is empty by default. It's a good idea to have this value set as anyone who knows the URL and a Datawrapper chart ID you are using will be able to submit webhook requests.

To invalidate webhook requests, change the `webhooks_random_code` value and flush the configuration. Any webhooks configured at DataWrapper will need to be updated in this event.
25 changes: 13 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="nswdpc/silverstripe-datawrapper">
<directory>tests/</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</coverage>
<testsuite name="nswdpc/silverstripe-datawrapper">
<directory>tests/</directory>
</testsuite>
</phpunit>
Loading
Loading