Frontend and backend extension for Contao CMS.
This extension lets you create, display and manage photo albums in your Contao installation. It ships with an album listing and an album detail view, supports nested (child) albums, per-album access rights, and Markdown album descriptions.
Gallery.Creator.mp4
- Requirements
- Installation
- Upgrading
- Configuration
- Access rights (CHMOD)
- Lightbox
- Styling (CSS)
- Frontend templates
- Extending the bundle
- Running the tests
- Contao
^5.3 - PHP
^8.3
Use the Contao Manager or run the following command in your CLI:
composer require markocupic/gallery-creator-bundle
⚠️ Upgrading to 3.3.0? This release contains breaking changes to the frontend Twig templates and removes the legacygalleryCreatorGenerateFrontendTemplateandgalleryCreatorImagePostInserthooks (replaced by Symfony events). Please read the UPGRADE.md before updating, especially if you have customized any templates or used one of these hooks.
The bundle ships with a default configuration. To override it, add your settings to your
project configuration (e.g. config/config.yaml):
# config/config.yaml
# Gallery Creator (default settings)
markocupic_gallery_creator:
upload_path: 'files/gallery_creator_albums'
copy_images_on_import: true
read_exif_meta_data: false
valid_extensions: ['jpg', 'jpeg', 'gif', 'png', 'webp', 'svg', 'svgz']
Go to the Contao backend settings and select a default album owner, a default album owner group and the default access rights.
Important: If you leave the "album owner" field empty, the currently logged-in backend user automatically becomes the album owner when creating a new album.
As a lightbox we strongly recommend Glightbox:
composer require inspiredminds/contao-glightboxMake sure you have activated the lightbox template in the layout settings of your theme in the Contao backend.
Gallery Creator adds the .gc-listing-view and/or the .gc-detail-view class to the
<body> tag. This helps you show or hide items depending on the current mode (listing vs.
detail view).
// SASS: do not display the content element headline in detail mode
body.gc-detail-view {
.ce_gallery_creator {
h2:not([class^="gc-album-detail-name"]) {
display: none;
}
}
}The frontend output is rendered with Contao Twig components. You can override any of the
shipped templates in your project's contao/templates/ directory:
content_element/gallery_creator.html.twigcontent_element/gallery_creator_news.html.twigcomponent/_album.html.twigcomponent/_album_detail_view.html.twigcomponent/_album_list_view.html.twig
If you override these templates, be aware that the template variables changed in 3.3.0. See UPGRADE.md for the details.
Use the GenerateFrontendTemplateEvent to adapt the frontend output. It is dispatched
right before the gallery frontend template is rendered and carries the content element
controller, the template, the current request and the active album (if there is one).
Listeners mutate the template in place; no return value is expected.
This replaces the in version 3.0.0 removed
galleryCreatorGenerateFrontendTemplatehook (see UPGRADE.md).
<?php
// src/EventListener/GalleryCreatorFrontendTemplateListener.php
declare(strict_types=1);
namespace App\EventListener;
use Markocupic\GalleryCreatorBundle\Event\GenerateFrontendTemplateEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener(priority: 100)]
class GalleryCreatorFrontendTemplateListener
{
public function __invoke(GenerateFrontendTemplateEvent $event): void
{
$template = $event->getTemplate();
$activeAlbum = $event->getAlbumsModel();
$contentElement = $event->getContentElement();
$request = $event->getRequest();
$template->set('foo', 'bar');
}
}Use the ImagePostInsertEvent to adapt the picture entity when uploading new images to an
album. It is dispatched right after an image has been uploaded and written to the database
and carries the pictures model. Listeners mutate the model in place; no return value is
expected.
This replaces the in version 3.0.0 removed
galleryCreatorImagePostInserthook (see UPGRADE.md).
<?php
// src/EventListener/GalleryCreatorImagePostInsertListener.php
declare(strict_types=1);
namespace App\EventListener;
use Contao\BackendUser;
use Markocupic\GalleryCreatorBundle\Event\ImagePostInsertEvent;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener(priority: 100)]
class GalleryCreatorImagePostInsertListener
{
public function __construct(private readonly Security $security)
{
}
public function __invoke(ImagePostInsertEvent $event): void
{
$picturesModel = $event->getPicturesModel();
$user = $this->security->getUser();
// Automatically add a caption to the uploaded image
if ($user instanceof BackendUser && $user->name) {
$picturesModel->caption = 'Holidays '.date('Y').', Photo: '.$user->name;
$picturesModel->save();
}
}
}Have fun!
