### Frontend Integration Setup for SuluVideoBundle
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
Sets up the SuluVideoBundle for frontend integration by adding it to the admin's package.json, installing dependencies, and building the assets.
```json
// assets/admin/package.json
{
"dependencies": {
"sulu-video-bundle": "file:../../vendor/robole/sulu-video-bundle/src/Resources/js"
}
}
```
```javascript
// assets/admin/app.js
import "sulu-video-bundle";
```
```bash
cd assets/admin
npm install
npm run build
```
--------------------------------
### Install SuluVideoBundle using Composer
Source: https://github.com/robole-dev/sulu-video-bundle/blob/main/README.md
This snippet shows the Composer command to install the SuluVideoBundle into a Symfony project. It is a prerequisite for integrating the bundle's functionalities.
```bash
composer require robole/sulu-video-bundle
```
--------------------------------
### Test Video Twig Extension Functionality (PHPUnit)
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
Provides example PHPUnit tests for the VideoTwigExtension class, verifying its ability to correctly transform YouTube and Vimeo URLs into embeddable formats and detect video providers. These tests ensure the core logic of the extension is sound.
```php
extension = new VideoTwigExtension();
}
public function testYouTubeEmbedUrlTransformation(): void
{
$youtubeUrl = 'https://www.youtube.com/watch?v=aqz-KE-bpKQ';
$expectedUrl = 'https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ';
$this->assertEquals(
$expectedUrl,
$this->extension->getVideoEmbedUrl($youtubeUrl)
);
}
public function testVimeoWithDoNotTrackParameter(): void
{
$vimeoUrl = 'https://vimeo.com/76979871';
$expectedUrl = 'https://player.vimeo.com/video/76979871?dnt=1';
$this->assertEquals(
$expectedUrl,
$this->extension->getVideoEmbedUrl($vimeoUrl)
);
}
public function testProviderDetection(): void
{
$this->assertEquals(
'youtube',
$this->extension->getVideoProvider('https://youtu.be/aqz-KE-bpKQ')
);
$this->assertEquals(
'vimeo',
$this->extension->getVideoProvider('https://vimeo.com/76979871')
);
$this->assertNull(
$this->extension->getVideoProvider('https://example.com/video.mp4')
);
}
}
```
--------------------------------
### Run PHPUnit Tests for SuluVideoBundle
Source: https://github.com/robole-dev/sulu-video-bundle/blob/main/README.md
This command executes the PHPUnit tests for the SuluVideoBundle. It's used to ensure the backend PHP code functions correctly and meets the expected quality standards.
```bash
composer phpunit
```
--------------------------------
### Manage Project Dependencies and Code Style (Bash)
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
Provides essential bash commands for managing the project's dependencies and ensuring code quality. This includes running PHPUnit tests, checking code style with PHP-CS, and automatically fixing style issues.
```bash
# Run tests
composer phpunit
# Check code style
composer php-cs
# Fix code style issues
composer php-cs-fix
```
--------------------------------
### Integrate Custom Video Service Logic (PHP & YAML)
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
Demonstrates how to create and configure a custom VideoService in PHP that utilizes the Sulu Video Bundle's Twig extension for processing video URLs and retrieving metadata. The service is configured using Symfony's YAML service definitions.
```php
videoExtension = $videoExtension;
}
public function processVideoUrl(string $url): array
{
return [
'original_url' => $url,
'embed_url' => $this->videoExtension->getVideoEmbedUrl($url),
'provider' => $this->videoExtension->getVideoProvider($url),
'is_external' => $this->videoExtension->getVideoProvider($url) !== null,
];
}
public function getVideoMetadata(string $url): array
{
$provider = $this->videoExtension->getVideoProvider($url);
return match($provider) {
'youtube' => [
'platform' => 'YouTube',
'privacy_enhanced' => true,
'iframe_allowed' => true,
],
'vimeo' => [
'platform' => 'Vimeo',
'privacy_enhanced' => true,
'iframe_allowed' => true,
],
'dailymotion' => [
'platform' => 'Dailymotion',
'privacy_enhanced' => false,
'iframe_allowed' => true,
],
default => [
'platform' => 'HTML5',
'privacy_enhanced' => false,
'iframe_allowed' => false,
],
};
}
}
```
```yaml
# config/services.yaml
services:
App\Service\VideoService:
arguments:
$videoExtension: '@sulu_video_bundle.twig_extension'
```
--------------------------------
### Register SuluVideoBundle in bundles.php
Source: https://github.com/robole-dev/sulu-video-bundle/blob/main/README.md
For projects not using Symfony Flex, this PHP snippet demonstrates how to manually register the SuluVideoBundle in the `config/bundles.php` file. This ensures the bundle is recognized by the Symfony application.
```php
return [
//...
Robole\SuluVideoBundle\SuluVideoBundle::class => ['all' => true],
];
```
--------------------------------
### Complete Twig Template for Video Display with Error Handling
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
This Twig template demonstrates how to display video content, supporting external platforms like YouTube and Vimeo, as well as HTML5 videos. It includes conditional logic to handle different video sources and provides fallback messages for unsupported browsers or missing videos. The template relies on the `video_provider` and `video_embed_url` Twig functions.
```twig
{# templates/pages/video-page.html.twig #}
{% extends "base.html.twig" %}
{% block content %}
{{ content.title }}
{% if content.main_video %}
{% if video_provider(content.main_video) %}
{# External video platform (YouTube, Vimeo, Dailymotion) #}
{% else %}
{# HTML5 video for .mp4, .webm, .ogv files #}
{% endif %}
{% else %}
No video available for this content.
{% endif %}
{{ content.description|raw }}
{% endblock %}
```
--------------------------------
### PHP API for Video Provider Detection using VideoTwigExtension
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
This PHP code illustrates the use of the `getVideoProvider` method from the `VideoTwigExtension` class. This method identifies the video platform (YouTube, Vimeo, Dailymotion) based on the provided URL. For HTML5 videos or unrecognized URLs, it returns null. This functionality is essential for conditionally rendering different video player components.
```php
getVideoProvider('https://www.youtube.com/watch?v=aqz-KE-bpKQ');
// Returns: 'youtube'
$youtubeShortProvider = $extension->getVideoProvider('https://youtu.be/aqz-KE-bpKQ');
// Returns: 'youtube'
// Detect Vimeo
$vimeoProvider = $extension->getVideoProvider('https://vimeo.com/76979871');
// Returns: 'vimeo'
// Detect Dailymotion
$dailymotionProvider = $extension->getVideoProvider('https://www.dailymotion.com/video/x92td94');
// Returns: 'dailymotion'
// HTML5 or unknown video returns null
$html5Provider = $extension->getVideoProvider('https://example.com/video.mp4');
// Returns: null
$unknownProvider = $extension->getVideoProvider('https://example.com/unknown-video');
// Returns: null
```
--------------------------------
### Add SuluVideoBundle to admin package.json
Source: https://github.com/robole-dev/sulu-video-bundle/blob/main/README.md
This JSON snippet illustrates how to add the SuluVideoBundle as a dependency in the `assets/admin/package.json` file. This step is necessary for linking the frontend code of the bundle.
```json
"dependencies": {
"sulu-video-bundle": "file:../../vendor/robole/sulu-video-bundle/src/Resources/js"
}
```
--------------------------------
### Import SuluVideoBundle in app.js
Source: https://github.com/robole-dev/sulu-video-bundle/blob/main/README.md
This JavaScript snippet shows how to import the SuluVideoBundle's frontend code into the main admin application file (`assets/admin/app.js`). This makes the bundle's JavaScript functionalities available in the Sulu administration interface.
```javascript
import "sulu-video-bundle";
```
--------------------------------
### Check PHP Coding Standards
Source: https://github.com/robole-dev/sulu-video-bundle/blob/main/README.md
This command runs a check on the PHP code within the SuluVideoBundle to ensure it adheres to defined coding standards. This helps maintain code consistency and quality.
```bash
composer php-cs
```
--------------------------------
### Detect Video Platform using Twig
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
Employs the `video_provider()` Twig function to determine the platform of a given video URL (e.g., 'youtube', 'vimeo', 'dailymotion'). This allows for conditional rendering of video embeds tailored to each platform, or a fallback for HTML5 video.
```twig
{# Conditional rendering based on video provider #}
{% if content.promotional_video %}
{% set provider = video_provider(content.promotional_video) %}
{% if provider == 'youtube' %}
Hosted on YouTube
{% elseif provider == 'vimeo' %}
Hosted on Vimeo
{% elseif provider == 'dailymotion' %}
Hosted on Dailymotion
{% else %}
{# HTML5 video for direct video files #}
{% endif %}
{% endif %}
{# Returns: 'youtube', 'vimeo', 'dailymotion', or null for HTML5 videos #}
```
--------------------------------
### Apply PHP Coding Standards
Source: https://github.com/robole-dev/sulu-video-bundle/blob/main/README.md
This command automatically applies coding standards fixes to the PHP code in the SuluVideoBundle. It's used to reformat code and correct style issues.
```bash
composer php-cs-fix
```
--------------------------------
### PHP API for Video URL Conversion using VideoTwigExtension
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
This PHP code demonstrates the usage of the `getVideoEmbedUrl` method from the `VideoTwigExtension` class. This method converts various video URLs (YouTube, Vimeo, Dailymotion) into their respective embeddable formats. It also handles HTML5 video URLs by returning them unchanged. This is crucial for integrating external video content seamlessly into applications.
```php
getVideoEmbedUrl($youtubeUrl);
// Returns: 'https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ'
// YouTube short URL (youtu.be)
$youtubeShort = 'https://youtu.be/aqz-KE-bpKQ';
$embedUrl = $extension->getVideoEmbedUrl($youtubeShort);
// Returns: 'https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ'
// Vimeo URL with privacy parameter
$vimeoUrl = 'https://vimeo.com/76979871';
$embedUrl = $extension->getVideoEmbedUrl($vimeoUrl);
// Returns: 'https://player.vimeo.com/video/76979871?dnt=1'
// Dailymotion URL
$dailymotionUrl = 'https://www.dailymotion.com/video/x92td94';
$embedUrl = $extension->getVideoEmbedUrl($dailymotionUrl);
// Returns: 'https://www.dailymotion.com/embed/video/x92td94'
// HTML5 video (unchanged)
$html5Video = 'https://example.com/videos/demo.mp4';
$embedUrl = $extension->getVideoEmbedUrl($html5Video);
// Returns: 'https://example.com/videos/demo.mp4'
```
--------------------------------
### Define Sulu Video Bundle Services (XML)
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
Defines the Video Content Type and Twig Extension services for the Sulu Video Bundle using Symfony's service configuration in XML format. These services are essential for handling video content within Sulu.
```xml
```
--------------------------------
### Render Video Embeds in Twig Templates
Source: https://github.com/robole-dev/sulu-video-bundle/blob/main/README.md
This Twig snippet illustrates how to render embedded videos in Twig templates using the `video_provider` and `video_embed_url` functions. It handles both external video platforms (YouTube, Vimeo, Dailymotion) and HTML5 video elements.
```twig
{% if content['my_video'] %}
{% if video_provider(content['my_video']) %}
{% else %}
{% endif %}
{% endif %}
```
--------------------------------
### VideoPreview Component Features (JavaScript)
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
The VideoPreview component in the SuluVideoBundle handles video URL validation using regex, detects providers (YouTube, Vimeo, Dailymotion, generic), and enables real-time previews using iframes or HTML5 video elements. It automatically transforms embed URLs and supports common video file formats.
```javascript
// The VideoPreview component provides:
// 1. URL validation with regex pattern matching
// 2. Provider detection (YouTube, Vimeo, Dailymotion, or generic URL)
// 3. Real-time preview with iframe or HTML5 video element
// 4. Automatic embed URL transformation
// 5. Support for .mp4, .webm, .ogv video formats
// URL validation regex
const urlPattern = new RegExp("^(https?|ftp)://[^s/$.?#].*$", "i");
// Supported video formats
const iframeProviders = ['youtube', 'youtu.be', 'vimeo', 'dailymotion'];
const html5Formats = ['.mp4', '.webm', '.ogv'];
// The component automatically:
// - Displays provider badge (YouTube, Vimeo, Dailymotion, or URL)
// - Validates URLs in real-time
// - Converts URLs to embed format
// - Renders live preview in admin panel
// - Shows iframe for external providers
// - Shows HTML5 video player for direct video files
```
--------------------------------
### Configure Video Field in Sulu Page Template
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
Defines a 'video' type custom field within a Sulu page template. This allows content editors to manage video URLs, with options for mandatory fields and additional parameters like a headline.
```xml
Header VideoKopfzeilen-VideoTutorial VideoTutorial-Video
```
--------------------------------
### Register Video Field Type in Sulu Admin (JavaScript)
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
Shows how to register the 'video' field type with Sulu's admin bundle using JavaScript. This integration makes the custom video field available within the Sulu content management interface by importing the VideoPreview component and adding it to the field registry.
```javascript
// assets/admin/app.js
import { fieldRegistry } from "sulu-admin-bundle/containers";
import VideoPreview from "./containers/VideoPreview";
const FIELD_TYPE_VIDEO = "video";
// Register the video field type with Sulu's field registry
fieldRegistry.add(FIELD_TYPE_VIDEO, VideoPreview);
```
--------------------------------
### Define Video Content Type in Sulu Template
Source: https://github.com/robole-dev/sulu-video-bundle/blob/main/README.md
This XML snippet demonstrates how to define a 'video' content type within a Sulu page template. This allows editors to add video fields to their content pages.
```xml
VideoVideo
```
--------------------------------
### Transform Video URL to Embed Format using Twig
Source: https://context7.com/robole-dev/sulu-video-bundle/llms.txt
Uses the `video_embed_url()` Twig function to convert a video URL into an embed-ready format suitable for iframe sources. It handles transformations for YouTube, Vimeo, and Dailymotion, including privacy-enhanced YouTube embeds.
```twig
{# Basic usage - Convert any video URL to embed-ready format #}
{% set video_url = content.my_video %}
{% if video_url %}
{% endif %}
{# Examples of URL transformations:
Input: https://www.youtube.com/watch?v=aqz-KE-bpKQ
Output: https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ
Input: https://vimeo.com/76979871
Output: https://player.vimeo.com/video/76979871?dnt=1
Input: https://www.dailymotion.com/video/x92td94
Output: https://www.dailymotion.com/embed/video/x92td94
#}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.