heimrichhannot / contao-advanced-dashboard-bundle
用于自定义 contao 后端仪表板的插件。
0.1.3
2023-09-12 10:12 UTC
Requires
- php: ^7.2|^8.0
- contao/core-bundle: ^4.9
- heimrichhannot/contao-twig-support-bundle: ^1.0
- symfony/config: ^4.4|^5.0
- symfony/dependency-injection: ^4.4|^5.0
- symfony/event-dispatcher: ^4.4|^5.0
- symfony/http-kernel: ^4.4|^5.0
README
用于增加更多灵活性的 contao 后端仪表板插件。
功能
- 替换 contao 仪表板,使用更可定制的版本
- 根据需要自定义仪表板版本列表,例如更改用户和表的可见性或添加自定义列
使用方法
安装
-
使用 composer 或 contao 管理器安装
composer require heimrichhannot/contao-advanced-dashboard-bundle
-
更新数据库
自定义仪表板版本列表。
此插件的主要功能是自定义 contao 仪表板中的版本日志。安装此插件后,您会发现与原始 contao 仪表板没有区别,因为默认配置相同。但现在您可以创建配置,指定哪些日志对用户或表进行过滤后显示。您还可以指定哪些列要显示。
-
在项目配置中设置 versions_right 配置,通常在
config/config.yml
huh_advanced_dashboard: versions_rights: # All user changes visible for table tl_news. editor_news: user_access_level: all columns: - date - user - table - id - description - version - actions tables: - tl_news
-
如果不是开发模式,请清除缓存
-
将创建的权限应用于用户或用户组设置中的用户或用户组。
附加说明
- 如果没有定义配置,或者用户没有添加配置,则使用默认配置。您可以通过创建一个名为 default 的配置来自定义默认配置。
- 限制不应用于管理员用户。
将自定义内容/部分添加到后端模板
此插件包含的仪表板模板提供了一些自定义选项。您可以添加自定义部分或内容,并禁用现有部分。
以下位置可用(作为模板变量)
- positionTop
- positionBeforeShortcuts
- positionBeforeVersions
- positonBottom
通过将这些变量设置为 false 跳过现有部分(作为模板变量可用)
- showMessages
- showShortcuts
- showVersions
要设置这些模板变量,您可以使用 contao parseTemplate 钩子或 Twig 支持插件 的 BeforeParseTwigTemplateEvent
和 BeforeRenderTwigTemplateEvent
事件。对于 twig 支持插件事件,模板名称为 be_advanced_dashboard
。
如果您使用 parseTemplate 钩子添加自定义内容,请记住它应具有比 -10
更高的优先级!
/** * @Hook("parseTemplate") */ class ParseTemplateListener { public function __invoke(Template $template): void { if ('be_welcome' === $template->getName()) { $template->positionTop = '<div id="tl_custom_welcome"> <h2 style="margin-top: 18px;">Welcome</h2> <p style="margin-top: 6px;">This could be your message!</p> </div>'; $template->showShortcuts = false; } } }
开发者
添加新列或更改现有列的显示方式
有两个事件可以用于向版本日志添加自定义列或更改现有列。
也许您有一个扩展了版本表并向版本数据库日志条目添加更多信息的扩展,并希望在仪表板版本日志中输出这些信息。我们建议创建 VersionListDatabaseColumnsEvent
和 VersionListTableColumnsEvent
的订阅者。
use HeimrichHannot\AdvancedDashboardBundle\Event\VersionListDatabaseColumnsEvent; use HeimrichHannot\AdvancedDashboardBundle\Event\VersionListTableColumnsEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class AdvancedDashboardEventSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents(){ return [ VersionListDatabaseColumnsEvent::class => 'onVersionListDatabaseColumnsEvent', VersionListTableColumnsEvent::class => 'onVersionListTableColumnsEvent', ]; } // Add additional database columns that should be fetched (or modify existing values) public function onVersionListDatabaseColumnsEvent(VersionListDatabaseColumnsEvent $event) { $event->addColumn('custom_information'); } // Add additional columns to the version list. // `label` is the table column headline // `renderCallback` is the method that renders the content of the current column. // Gets the database values for the current row as parameter. public function onVersionListTableColumnsEvent(VersionListTableColumnsEvent $event) { $event->setColumn('custom_colum', [ 'label' => 'Custom information', 'renderCallback' => function(array $version) { return $version['custom_information'] ?: 'No custom information'; } ]); } }
配置参考
# Default configuration for extension with alias: "huh_advanced_dashboard" huh_advanced_dashboard: # Configure user rights for version list. Can be selected in the user and user group settings. versions_rights: # Prototype: The title of the configuration. Should be a unique alias/name containing just 'a-z0-9-_' like 'all_users','editor_news'. name: # Allowed version table columns. Empty means all columns are allowed. columns: # Defaults: - date - user - table - id - description - version - actions # Allowed database tables. Empty means all tables are allowed. tables: [] # Access rights for other users version logs. user_access_level: [self] # One of "all"; "self"