markocupic/gallery-creator-bundle

Contao CMS 的相册扩展

3.0.1 2024-08-18 11:28 UTC

README

Marko Cupic

Gallery Creator Bundle

Contao CMS 的前端和后端扩展 Contao CMS

此扩展可用于在您的 Contao 安装中创建、显示和管理照片专辑。Gallery Creator Bundle 提供了专辑列表和专辑详情视图。自 2.0.0 版本起,可以使用 markdown 创建专辑描述。

Gallery.Creator.mp4

安装

请使用 Contao 管理器或在您的 CLI 中运行 composer require markocupic/gallery-creator-bundle 来安装此扩展。

CHMOD

转到 Contao 后端设置 并选择默认的 专辑所有者默认专辑所有者组 并设置默认的 访问权限

重要:如果您保留“专辑所有者”字段为空,则在创建新专辑时,当前登录的后端用户将自动成为专辑所有者。

chmod

灯箱

我们强烈推荐使用 Glightbox 作为灯箱。只需在您的 CLI 中运行 composer require inspiredminds/contao-glightbox 命令。请确保您已激活主题的布局设置中的灯箱模板。

CSS

Gallery Creator 将向 body 标签添加 .gc-listing-view 和/或 .gc-detail-view。这有助于您在列表和详情视图模式中显示或隐藏不想显示的项目。

/** SASS
 * Do not display ce elements headline in detail mode
 *
 */
body.gc-detail-view {
  .ce_gallery_creator {
    h2:not([class^="gc-album-detail-name"]) {
      display: none;
    }
  }
}

配置

此相册扩展附带默认配置。如果您想覆盖这些设置,可以在位于 config/config.yml 的公共配置文件中完成此操作。

# config/config.yml
# 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']

# Contao configuration
contao:
 url_suffix: ''
 #....

"galleryCreatorGenerateFrontendTemplate" - 钩子

使用 "galleryCreatorGenerateFrontendTemplate" 钩子来自适应前端输出。

"galleryCreatorGenerateFrontendTemplate" 钩子在解析相册创建器前端模板之前触发。它传递内容元素对象、模板对象和活动专辑的专辑对象(如果有的话)。"galleryCreatorGenerateFrontendTemplate" 钩子不需要返回值。

<?php
// src/EventListener/GalleryCreatorFrontendTemplateListener.php
declare(strict_types=1);

namespace App\EventListener;

use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\CoreBundle\Twig\FragmentTemplate;
use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorAlbumsModel;

#[AsHook(GalleryCreatorFrontendTemplateListener::HOOK, priority: 100)]
class GalleryCreatorFrontendTemplateListener
{
    public const HOOK = 'galleryCreatorGenerateFrontendTemplate';

    public function __invoke(AbstractContentElementController $contentElement, Fragmenttemplate $template, GalleryCreatorAlbumsModel|null $activeAlbum = null)
    {
        $template->set('foo', 'bar');
    }
}

"galleryCreatorImagePostInsert" - 钩子

使用 "galleryCreatorImagePostInsert" 钩子来适应在向专辑上传新图像时的图片实体。

"galleryCreatorImagePostInsert" 在图像上传并写入数据库后立即执行。它传递图片模型并不需要返回值。

<?php
// src/EventListener/GalleryCreatorImagePostInsertListener.php
declare(strict_types=1);

namespace App\EventListener;

use Contao\BackendUser;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Markocupic\GalleryCreatorBundle\Model\GalleryCreatorPicturesModel;
use Symfony\Bundle\SecurityBundle\Security;

#[AsHook(GalleryCreatorImagePostInsertListener::HOOK, priority: 100)]
class GalleryCreatorImagePostInsertListener
{
    public const HOOK = 'galleryCreatorImagePostInsert';

    private Security $security;

    public function __construct(Security $security)
    {
        $this->security = $security;
    }

    public function __invoke(GalleryCreatorPicturesModel $picturesModel): void
    {
        $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();
        }
    }
}

祝您玩得开心!