Installation:
composer.json under "repositories":
"repositories": {
"bibsdb/cafe-smag-bundle": {
"type": "vcs",
"url": "https://github.com/bibsdb/cafe-smag-bundle"
}
}
composer require bibsdb/cafe-smag-bundle
config/bundles.php (Laravel 5.4+) or AppKernel.php (older versions):
Bibsdb\CafeSmagBundle\BibsdbCafeSmagBundle::class => ['all' => true],
php artisan bibsdb:core:templates:load
First Use Case:
{{ bibsdb_cafe_smag(videoId) }}).Video Embedding:
bibsdb_cafe_smag to render the player:
{{ bibsdb_cafe_smag('YOUR_VIDEO_ID', {
'width': 800,
'height': 450,
'autoplay': false
}) }}
width, height, autoplay, or controls (if allowed by the video source).Admin Integration:
CafeSmagVideo field:
$builder
->add('videoId', CafeSmagVideoType::class, [
'label' => 'Cafe Smag Video',
'required' => false,
]);
CafeSmagVideoType form type for easy integration.Dynamic Loading:
// Example: Fetch and render a video after page load
fetch('/api/video/embed?videoId=123')
.then(response => response.text())
.then(html => {
document.getElementById('video-container').innerHTML = html;
});
API Integration:
$videoService = $this->container->get('bibsdb_cafe_smag.video_service');
$metadata = $videoService->getMetadata('VIDEO_ID');
Asset Management:
The bundle auto-registers the player.js from CafeSmag. Ensure your Laravel mix/webpack config doesn’t conflict with its asset paths.
Example (if overriding):
// webpack.mix.js
mix.js('resources/js/cafe-smag-player.js', 'public/js')
.alias({
'cafe-smag-player': path.resolve(__dirname, 'node_modules/cafe-smag/player.js')
});
Caching: Preload the template in your cache layer (e.g., Symfony’s HTTP cache) if serving static video pages:
# config/cache.php
'default' => [
'pool' => 'file_cache',
'prefix' => 'cafe_smag_',
],
Localization:
Override the bundle’s translations in config/packages/bibsdb_cafe_smag.yaml:
twig:
globals:
cafe_smag:
player_title: "Custom Player Title"
Ads/Controls Persistence:
cafe-smag.com/ads/ calls).Template Loading:
bibsdb:core:templates:load command must run post-installation. Skipping this will break Twig rendering.php artisan cache:clear
php artisan config:clear
JavaScript Conflicts:
player.js fails to load, ensure:
window.CafeSmagPlayer.{{ encore_entry_script_tags('cafe-smag-player') }}
Video ID Validation:
videoId is a string. Pass invalid IDs (e.g., null, 0) to trigger errors.$builder->add('videoId', CafeSmagVideoType::class, [
'constraints' => [new NotBlank(), new Length(min: 3)],
]);
Log Player Events: Extend the player’s event system by overriding the Twig template:
{% extends 'BibsdbCafeSmagBundle:default:player.html.twig' %}
{% block cafe_smag_events %}
{{ parent() }}
<script>
document.addEventListener('CafeSmagPlayerReady', (e) => {
console.log('Player loaded:', e.detail.player);
});
</script>
{% endblock %}
Check Console Errors: Common issues:
Uncaught ReferenceError: CafeSmagPlayer is not defined: Missing JS asset.Failed to load resource: net::ERR_BLOCKED_BY_CLIENT: Ad-blocker interfering (disable temporarily for testing).Custom Player Config: Override the default player options in your Twig template:
{{ bibsdb_cafe_smag(videoId, {
'playerOptions': {
'theme': 'dark',
'quality': 'hd'
}
}) }}
Hook into Video Events: Use the bundle’s event system (if available) or attach listeners via JavaScript:
document.querySelector('.cafe-smag-player').addEventListener('play', (e) => {
console.log('Video started');
});
Add Metadata Fields:
Extend the CafeSmagVideoType to include custom fields (e.g., title, description):
// src/Form/Extension/CafeSmagVideoExtension.php
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('title', TextType::class);
}
Server-Side Video Processing: Use the bundle’s service to pre-process video URLs (e.g., add tracking parameters):
$processedUrl = $this->container->get('bibsdb_cafe_smag.video_processor')
->process('VIDEO_ID', ['utm_source' => 'laravel']);
How can I help you explore Laravel packages today?