oveleon/contao-config-driver-bundle

Contao开源CMS的配置驱动

安装数: 2,868

依赖: 1

建议: 0

安全: 0

星星: 1

关注者: 3

分支: 0

开放问题: 0

类型:contao-bundle

1.4.0 2024-08-02 11:29 UTC

This package is auto-updated.

Last update: 2024-09-02 11:37:56 UTC


README

此扩展为Contao开源CMS添加了另一个驱动程序。

使用Config-Driver可以从配置文件中加载字段,并在后台输出它们。保留Contao使用的DCA结构。可以决定数据是存储在本地config中还是在现有的数据库列中。

位于ROOT下的/templates/目录中的配置文件被使用。如果没有找到模板,随后将搜索已安装的扩展包。这使您有机会覆盖配置文件而不丢弃默认设置。

为什么?

在我们的情况下,我们需要一个DCA,在其中我们可以将字段存储在另一个数据库列中,以节省数据库查询和提高性能。

此外,我们还想提供一种可能,即提供标准配置,该配置可以通过后台进行扩展。该驱动程序是为了提供基本主题及其SCSS变量而开发的,并允许它由另一个扩展使用或扩展。有关更多信息,您可以查看我们的扩展 "Contao ThemeManager",其中使用了该驱动程序。

保存到本地config的示例

对于存储在localconfig中,只需要两个字段。

字段

  • dataContainer: 要使用的驱动程序
  • configFile: 要使用的配置文件(DCA调色板和字段)
$GLOBALS['TL_DCA']['tl_newdca'] = array
(
    'config' => array
    (
        'dataContainer'               => 'Config',
        'configFile'                  => 'dcaConfigFile.html5' // Use the extension html5 to make the configuration extensible in the backend. If the configuration must not be changed, choose the extension PHP.
    )
);

保存到现有数据库表/列的示例

对于存储在现有数据库列中,配置文件的全部字段都存储为序列化格式。

字段

  • dataContainer: 要使用的驱动程序
  • ptable: 存储数据的表
  • configField: 存储序列化数据的列
  • configFile: 要使用的配置文件(DCA调色板和字段)
  • multipleConfigFiles: 合并所有同名configFiles
$GLOBALS['TL_DCA']['tl_newdca'] = array
(
    'config' => array
    (
        'dataContainer'               => 'Config',
        'ptable'                      => 'tl_theme', 
        'configField'                 => 'configData',
        'configFile'                  => 'dcaConfigFile.html5',
        'multipleConfigFiles'         => true
    )
);

配置文件的示例

return array(
    'palettes' => array(                                    //
        'default'  => '{font_legend},fontsize,fontcolor'    // Optional
    ),                                                      // 
    'fields'   => array(
        'fontsize' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_newdca']['fontsize'],
            'inputType'               => 'inputUnit',
            'options'                 => $GLOBALS['TL_CSS_UNITS'],
            'eval'                    => array('includeBlankOption'=>true, 'rgxp'=>'digit_inherit', 'maxlength' => 20, 'tl_class'=>'w50'),
        ),
        'fontcolor' => array
        (
            'label'                   => &$GLOBALS['TL_LANG']['tl_newdca']['fontcolor'],
            'inputType'               => 'text',
            'eval'                    => array('maxlength'=>6, 'colorpicker'=>true, 'isHexColor'=>true, 'decodeEntities'=>true, 'tl_class'=>'w50 wizard'),
        )
    )
);

更多示例

为了继续上面的示例,并能够在例如主题中通过后端访问配置,我们可以为每个主题添加另一个图标。

config/config.php
$GLOBALS['BE_MOD']['design']['themes']['tables'][] = 'tl_newdca';
dca/tl_theme.php
// Add operation
$GLOBALS['TL_DCA']['tl_theme']['list']['operations']['newdca'] = array
(
    'label'               => &$GLOBALS['TL_LANG']['tl_theme']['newdca'],
    'href'                => 'table=tl_newdca',
    'icon'                => 'css.svg',
);

// Add fields
$GLOBALS['TL_DCA']['tl_theme']['fields']['configData'] = array
(
    'inputType'      => 'text',
    'sql'            => "text NULL"
);

现在,我们有了在每种主题中填充所有配置字段并将其保存到其新的数据库列中的可能性。

后台视图

Admin View: List