PHP code example of markocupic / gallery-creator-bundle
1. Go to this page and download the library: Download markocupic/gallery-creator-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
markocupic / gallery-creator-bundle example snippets
// 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');
}
}
// 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();
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.