lumturo-net / contao-globals-wrapper
Contao 中 GLOBALS 数组的面向对象包装器
1.0.8
2023-01-03 10:51 UTC
Requires
- php: ^7.4|^8.0
- contao/core-bundle: ^4.9
This package is auto-updated.
Last update: 2024-09-30 01:43:29 UTC
README
一个简化 Contao 中 DCAs(数据内容数组)操作的 Contao 扩展。
使用 PHP7.3 和 Contao 4.9 开发。
安装
通过 composer 安装
composer require lumturo-net/contao-globals-wrapper
TL_DCA
use LumturoNet\Globals\Dca; $dca = Dca::new(string $namespace);
配置
$dca->config() ->dataContainer('Table') ->cTable(['tl_tabelle']) ->enableVersioning() ->custom([ // Eigene Konfigurationsfelder ]) ->sql([ 'keys' => ['id' => 'primary'] ]);
扩展现有配置
$dca->config([bool $extend])
异常
DcaConfigNotSetException
当 $extend = true 且要扩展的配置不存在时返回。
列表
$dca->list() ->sorting() ->fields(['title']) ->mode(1) ->flag(11) ->panelLayout('search;filter') ->compile() ->label() ->fields(['title']) ->compile() ->globalOperations('all') ->label($label) ->href() ->class() ->attributes() ->compile() ->operations('edit') ->href() ->icon() ->compile()
扩展现有列表
$dca->list([bool $extend])
异常
DcaListNotSetException
当 $extend = true 且要扩展的列表不存在时返回。
字段
$dca->fields('mein_feld') ->text() ->label(string|array $label) ->exclude() ->eval() ->mandatory() ->maxlength(255) ->compile() ->relation([ 'hasOne' => 'lazy' ]) ->sql()
扩展现有字段
$dca->field('singleSRC', [bool $extend])
异常
DcaFieldExistsException
当 $extend = false 且要在相同命名空间中创建具有相同名称的字段时返回。
DcaFieldNotSetException
当 $extend = true 且要扩展的字段不存在时返回。
面板 & 子面板
$dca->palettes(string $palette) ->group('title_legend' [string $translations, boolean $hidden]) ->fields([ 'mein_feld', 'anderes_feld', 'nochein_feld' ]) ->compile() $dca->subpalette('mein_feld') ->fields([ 'unterfeld_1', 'unterfeld_2' ]) ->compile();
TL_CTE
使用 Cte::new($namespace)->push(Array [])
可以定义内容元素到它们相应类别的映射。
use LumturoNet\Globals\Cte; use Namespace\Elements\MyCustomElement1; use Namespace\Elements\MyCustomElement2; use Namespace\Elements\MyCustomElement3; Cte::new(string $namespace)->push([ 'MyCustomElement1' => MyCustomElement1::class, 'MyCustomElement2' => MyCustomElement2::class, 'MyCustomElement3' => MyCustomElement3::class, ]);
TL_LANG
使用语言包装器可以创建新的翻译,也可以从现有的翻译中读取相应的值。
创建翻译
use LumturoNet\Globals\Lang; $lang = Lang::set($namespace); $lang->trans('MyCustomElement1', 'Ein cooles Inhaltselement') ->trans('MyCustomElement2', 'Und noch eins') ->trans('MyCustomElement3', 'Elemente gründen Gewerkschaft'); ->trans('sharkday', ['Haitag', 'Es ist Haitag']);
获取翻译
use LumturoNet\Globals\Lang; Lang::set($namespace); $dca->field('text') ->label(__('sharkday'));
从其他命名空间获取翻译
use LumturoNet\Globals\Lang; $dca->field('text') ->label(__('deleteConfirm', 'MSC'));
TL_MODELS
!! 从 Contao 4.9.x 开始 !!
通过模型绑定,可以使模型的类名与数据库中的表名不同。
use LumturoNet\Globals\Models; use Namespace\Models\MyModel; use Namespace\Models\MySecondModel; Models::bind([ 'tl_tabelle' => MyModel:class, 'tl_tabelle_2' => MySecondModel::class, ... ]);
异常
BindingExistsException
当提供的绑定之一已存在时返回。
BE_MOD
use LumturoNet\Globals\Backend; Backend::new(string $namespace, string $module, [int $position = 1])->tables([ 'tl_tabelle_1', 'tl_tabelle_2', ... ]);
TL_HOOKS
use LumturoNet\Globals\Hooks; use Namespace\Hooks\AddCommentHook; $hooks = Hooks::get() $hooks->activateAccount(array $myCallback) ->addComment([AddCommentHook::class, 'addCommentHook']);
TL_CSS
use LumturoNet\Globals\Css; Css::push([ 'path/to/file1.css', 'path/to/file2.css', ... ]);
异常
CssExistsException
当要添加的 CSS 已存在于 TL_CSS 中时返回。