|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | +# SuluVideoBundle |
| 5 | + |
| 6 | +> Sulu CMS bundle to preview and extract embed URLs from Youtube, Vimeo, Dailymotion and HTML5 videos. |
| 7 | +
|
| 8 | +This bundle adds a new content type `video` and provides the Twig functions `video_provider` and `video_embed_url` to embed external videos in an `iframe` or `video` element. |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +This bundle requires PHP 8.2 or later and [Node 18](https://nodejs.org/en/) (or Node 14 for Sulu versions <2.6.0) for building the Sulu administration UI. |
| 15 | + |
| 16 | +1. Open a command console, enter your project directory and run: |
| 17 | + |
| 18 | +```console |
| 19 | +composer require robole/sulu-video-bundle |
| 20 | +``` |
| 21 | + |
| 22 | +If you're **not** using Symfony Flex, you'll also need to add the bundle in your `config/bundles.php` file: |
| 23 | + |
| 24 | +```php |
| 25 | +return [ |
| 26 | + //... |
| 27 | + Robole\SuluVideoBundle\SuluVideoBundle::class => ['all' => true], |
| 28 | +]; |
| 29 | +``` |
| 30 | + |
| 31 | +2. Link the frontend code by adding the following to your `assets/admin/package.json`: |
| 32 | + |
| 33 | +```json |
| 34 | +"dependencies": { |
| 35 | + "sulu-video-bundle": "file:../../vendor/robole/sulu-video-bundle/src/Resources/js" |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +3. Import the frontend code by adding the following to your `assets/admin/app.js`: |
| 40 | + |
| 41 | +```javascript |
| 42 | +import "sulu-video-bundle"; |
| 43 | +``` |
| 44 | + |
| 45 | +4. Install all npm dependencies and build the admin UI ([see all options](https://docs.sulu.io/en/2.5/cookbook/build-admin-frontend.html): |
| 46 | + |
| 47 | +```bash |
| 48 | +cd assets/admin |
| 49 | +npm install |
| 50 | +npm run build |
| 51 | +``` |
| 52 | + |
| 53 | +## Usage |
| 54 | + |
| 55 | +1. Add the `video` content type to any of your page templates: |
| 56 | + |
| 57 | +```xml |
| 58 | +<property name="my_video" type="video" mandatory="true"> |
| 59 | + <meta> |
| 60 | + <title lang="de">Video</title> |
| 61 | + <title lang="en">Video</title> |
| 62 | + </meta> |
| 63 | +</property> |
| 64 | +``` |
| 65 | + |
| 66 | +2. Render the embeddable link in your twig templates: |
| 67 | + |
| 68 | +```twig |
| 69 | +{% if content['my_video'] %} |
| 70 | + {% if video_provider(content['my_video']) %} |
| 71 | + <!-- YouTube, Vimeo or Dailymotion --> |
| 72 | + <iframe |
| 73 | + src="{{ video_embed_url(content['my_video']) }}" |
| 74 | + frameborder="0" |
| 75 | + allow="fullscreen" |
| 76 | + ></iframe> |
| 77 | + {% else %} |
| 78 | + <!-- HTML5 video --> |
| 79 | + <video |
| 80 | + controls |
| 81 | + src="{{ video_embed_url(content['my_video']) }}" |
| 82 | + ></video> |
| 83 | + {% endif %} |
| 84 | +{% endif %} |
| 85 | +``` |
| 86 | + |
| 87 | +### Background |
| 88 | + |
| 89 | +This small bundle serves as a reference for our blog series ["Sulu Bundle Development"](https://robole.de/blog/sulu-bundle-development-part-1) showcasing major steps to build a Sulu bundle from scratch. The underlying idea was inspired by the [Statamic Video Fieldtype](https://statamic.dev/fieldtypes/video). |
| 90 | + |
| 91 | +### Scripts |
| 92 | + |
| 93 | +- To test the PHP code, run: |
| 94 | + |
| 95 | + > composer phpunit |
| 96 | +
|
| 97 | +- To check the coding standards, run: |
| 98 | + |
| 99 | + > composer php-cs |
| 100 | +
|
| 101 | +- To apply coding standards, run: |
| 102 | + > composer php-cs-fix |
0 commit comments