Installation
Add the repository to composer.json under "repositories":
"repositories": {
"bibsdb/book-bundle": {
"type": "vcs",
"url": "https://github.com/bibsdb/book-bundle"
}
}
Require the bundle:
composer require bibsdb/book-bundle
Enable the Bundle
Register Bibsdb\BookBundle\BibsdbBookBundle in config/bundles.php (Laravel) or AppKernel.php (Symfony):
// Laravel (config/bundles.php)
return [
Bibsdb\BookBundle\BibsdbBookBundle::class => true,
];
Load Templates Run the command to load the slide template:
php artisan bibsdb:core:templates:load
Enable in Admin Activate the template via the administration panel (UI-specific; check the bundle’s docs for exact steps).
Create a Slide Entity Use the bundle’s form or API to upload a book’s frontpage (image) and add a short description. Example (if using a form):
// Example controller logic (adjust based on bundle's actual API)
$slide = new \Bibsdb\BookBundle\Entity\Slide();
$slide->setImage($request->file('frontpage')->getRealPath());
$slide->setDescription($request->input('description'));
$slide->setTemplate('book_slide'); // Default template name
$slideManager = $this->get('bibsdb.book.slide_manager');
$slideManager->save($slide);
Display the Slide Render the slide in a Twig template:
{% include 'BibsdbBookBundle:Slide:display.html.twig' with {
'slide': slide,
'showControls': false
} %}
Upload & Process
SlideManager service to handle uploads, validation, and storage.$manager = $this->container->get('bibsdb.book.slide_manager');
$slide = $manager->createFromRequest($request);
$manager->persist($slide);
Template Customization
templates/Slide/ from the bundle to your theme’s directory.display.html.twig) to add/modify fields.API Integration
// Example route (routes/web.php)
Route::get('/slides/{id}', 'SlideController@show')->name('slides.show');
// Controller
public function show($id) {
$slide = $this->get('bibsdb.book.slide_repository')->find($id);
return response()->json($slide);
}
Admin Panel Integration
# config/packages/bibsdb_book.yaml
bibsdb_book:
admin:
enabled: true
route: admin.slides
slide_storage service:
$this->app->bind('bibsdb.book.slide_storage', function () {
return new \Bibsdb\BookBundle\Storage\S3Storage();
});
Slide entity’s validation rules by overriding the validate() method or using Symfony’s validator constraints.SlideCreatedEvent) to trigger actions like notifications:
$dispatcher->addListener(
'bibsdb.book.slide.created',
function ($event) {
// Send email, log, etc.
}
);
Template Loading
bibsdb:core:templates:load will result in missing templates. Run this command after every bundle update.Book.com API Dependencies
book.com for shared video content. Without a PLUS account, ads/video controls cannot be disabled.File Size Limits
max_file_size in php.ini or use a CDN.Slide entity:
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\File(maxSize="2048k")
*/
private $image;
Admin Panel Conflicts
bibsdb_book.admin.route may conflict.bibsdb_book:
admin:
enabled: false
Template Not Loading
vendor/bibsdb/book-bundle/Resources/views/Slide/.php artisan cache:clear
php artisan config:clear
Slide Not Saving
SlideManager is autowired correctly. Debug with:
dump($this->container->has('bibsdb.book.slide_manager')); // Should return true
$errors = $validator->validate($slide);
dump($errors);
Book.com API Errors
$this->partialMock(\Bibsdb\BookBundle\Service\BookApiClient::class, ['fetchVideoConfig'])
->shouldReceive('fetchVideoConfig')
->andReturn(['ad_free' => true]);
Custom Slide Types
Slide entity to support additional fields (e.g., isbn, author):
class CustomSlide extends Slide {
private $isbn;
public function getIsbn() { return $this->isbn; }
public function setIsbn($isbn) { $this->isbn = $isbn; }
}
Storage Backends
AbstractStorage:
class LocalStorage extends AbstractStorage {
public function save($filePath, $content) {
// Custom logic (e.g., save to local directory)
}
}
$this->app->bind('bibsdb.book.slide_storage', LocalStorage::class);
Event Listeners
SlideDownloaded):
$dispatcher->dispatch(new SlideDownloadedEvent($slide));
EventSubscriber:
class SlideSubscriber implements EventSubscriber {
public static function getSubscribedEvents() {
return [
'bibsdb.book.slide.downloaded' => 'onSlideDownloaded',
];
}
}
Default Template Name
'book_slide' as the default template. Override it globally:
bibsdb_book:
default_template: 'custom_book_template'
File Naming
SlideManager:
$manager->setRenameFiles(false);
CORS for API
.env:
APP_URL=http://yourdomain.com
CORS_ALLOWED_METHODS=GET,POST,PUT,DELETE
How can I help you explore Laravel packages today?