heimrichhannot / contao-fieldpalette
FieldPalette 是一个与 [MultiColumnWizard] (https://github.com/menatwork/MultiColumnWizard) 类似的 contao 小部件,拥有自己的数据库表。
Requires
- php: ~5.4 || ~7.0
- contao-community-alliance/composer-plugin: ~2.4 || ~3.0
- contao/core-bundle: ^3.5.1 || ~4.1
- heimrichhannot/contao-haste_plus: ^1.6.84
- heimrichhannot/datatables: ^1.10
- heimrichhannot/datatables-additional: ^1.0
- dev-master
- 1.4.10
- 1.4.9
- 1.4.8
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.19
- 1.3.18
- 1.3.17
- 1.3.16
- 1.3.15
- 1.3.14
- 1.3.13
- 1.3.12
- 1.3.11
- 1.3.10
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.11
- 1.2.10
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is not auto-updated.
Last update: 2022-02-01 12:55:19 UTC
README
FieldPalette 是一个类似于 [MultiColumnWizard] (https://github.com/menatwork/MultiColumnWizard) 的 contao 小部件。与 MultiColumnWizard 不同,字段被平坦地存储在 'tl_fieldpalette' 表中,并与父字段同步。
FieldPalette 配置基于 Contao 的 数据容器数组。
技术说明
默认设置(tl_fieldpalette
表)
此示例展示了在 tl_news 中使用子调色板来设置字段palette的配置。该示例可在模块 [heimrichhannot/contao-plus] (https://packagist.org.cn/packages/heimrichhannot/contao-news_plus) 中找到。
#/system/modules/[MyModule]/dca/tl_news.php
$dc = &$GLOBALS['TL_DCA']['tl_news'];
/**
* Selectors
*/
$dc['palettes']['__selector__'][] = 'addVenues';
/**
* Subpalettes
*/
$dc['subpalettes']['addVenues'] = 'venues';
/**
* Fields
*/
$arrFields = array
(
// venue
'addVenues' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_news']['addVenues'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('submitOnChange' => true),
'sql' => "char(1) NOT NULL default ''",
),
'venues' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_news']['venues'],
'inputType' => 'fieldpalette',
'foreignKey' => 'tl_fieldpalette.id',
'relation' => array('type' => 'hasMany', 'load' => 'eager'),
'sql' => "blob NULL",
'fieldpalette' => array
(
'config' => array(
'hidePublished' => false
),
'list' => array
(
'label' => array
(
'fields' => array('venueName', 'venueStreet', 'venuePostal', 'venueCity'),
'format' => '%s <span style="color:#b3b3b3;padding-left:3px">[%s, %s %s]</span>',
),
),
'palettes' => array
(
'default' => 'venueName,venueStreet,venuePostal,venueCity,venueCountry,venueSingleCoords,venuePhone,venueFax,venueEmail,venueWebsite,venueText',
),
'fields' => array
(
'venueName' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_news']['venueName'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('maxlength' => 255, 'tl_class' => 'long'),
'sql' => "varchar(255) NOT NULL default ''",
),
'venueStreet' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_news']['venueStreet'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''",
),
'venuePostal' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_news']['venuePostal'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('maxlength' => 32, 'tl_class' => 'w50'),
'sql' => "varchar(32) NOT NULL default ''",
),
'venueCity' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_news']['venueCity'],
'exclude' => true,
'filter' => true,
'search' => true,
'sorting' => true,
'inputType' => 'text',
'eval' => array('maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''",
),
'venueCountry' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_news']['venueCountry'],
'exclude' => true,
'filter' => true,
'sorting' => true,
'inputType' => 'select',
'options' => System::getCountries(),
'eval' => array('includeBlankOption' => true, 'chosen' => true, 'tl_class' => 'w50'),
'sql' => "varchar(2) NOT NULL default ''",
),
'venueSingleCoords' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_news']['venueSingleCoords'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('maxlength' => 64),
'sql' => "varchar(64) NOT NULL default ''",
'save_callback' => array
(
array('tl_news_plus', 'generateVenueCoords'),
),
),
'venueText' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_news']['venueText'],
'exclude' => true,
'search' => true,
'inputType' => 'textarea',
'eval' => array('rte' => 'tinyMCE', 'tl_class' => 'clr'),
'sql' => "text NULL",
),
),
),
),
);
$dc['fields'] = array_merge($dc['fields'], $arrFields);
自定义表设置(例如 tl_member_address
)
为了与您自己的表一起使用 Fieldpalette,创建一个从 $GLOBALS['TL_DCA']['tl_fieldpalette']
扩展的数据容器数组,如下例所述。
<?php
/* /dca/tl_member_address.php */
\Controller::loadLanguageFile('tl_fieldpalette');
\Controller::loadDataContainer('tl_fieldpalette');
\Controller::loadDataContainer('tl_member');
$GLOBALS['TL_DCA']['tl_member_address'] = $GLOBALS['TL_DCA']['tl_fieldpalette'];
$dca = &$GLOBALS['TL_DCA']['tl_member_address'];
$fields = [
'company' => $GLOBALS['TL_DCA']['tl_member']['fields']['company'],
'phone' => $GLOBALS['TL_DCA']['tl_member']['fields']['phone'],
'fax' => $GLOBALS['TL_DCA']['tl_member']['fields']['fax'],
'street' => $GLOBALS['TL_DCA']['tl_member']['fields']['street'],
'street2' => $GLOBALS['TL_DCA']['tl_member']['fields']['street2'],
'postal' => $GLOBALS['TL_DCA']['tl_member']['fields']['postal'],
'city' => $GLOBALS['TL_DCA']['tl_member']['fields']['city'],
'state' => $GLOBALS['TL_DCA']['tl_member']['fields']['state'],
'country' => $GLOBALS['TL_DCA']['tl_member']['fields']['country'],
'addressText' => $GLOBALS['TL_DCA']['tl_member']['fields']['addressText'],
];
$dca['fields'] = array_merge($dca['fields'], $fields);
然后将以下字段palette输入添加到父表(例如 tl_member
)中。
/* /dca/tl_member.php */
$dca = &$GLOBALS['TL_DCA']['tl_member'];
/**
* Adjust palettes
*/
$dca['palettes']['default'] = str_replace('country', 'country,additionalAddresses', $dca['palettes']['default']);
/**
* Adjust fields
*/
$dca['fields']['additionalAddresses'] = [
'label' => &$GLOBALS['TL_LANG']['tl_member']['additionalAddresses'],
'inputType' => 'fieldpalette',
'foreignKey' => 'tl_member_address.id',
'relation' => ['type' => 'hasMany', 'load' => 'eager'],
'sql' => "blob NULL",
'fieldpalette' => [
'config' => [
'hidePublished' => false,
'table' => 'tl_member_address',
],
'list' => [
'label' => [
'fields' => ['city'],
'format' => '%s',
],
],
'palettes' => [
'default' => '{contact_legend},phone,fax;{address_legend},company,street,street2,postal,city,state,country,addressText',
],
],
];
额外的 dca 参考
如果已实现,则支持 https://docs.contao.org/books/api/dca/reference.html 中的所有属性。其他属性将在此列出
记录列表
排序
键 | 值 | 描述 |
---|---|---|
viewMode | 视图模式(整数) | 0 表(默认) 1 列表 |
通过复制其父记录来支持递归复制字段palette记录
简单地向包含“fieldpalette”类型字段的 dca 添加 oncopy_callback
$GLOBALS['TL_DCA']['tl_*'] = array
(
'config' => array
(
// ...
'oncopy_callback' => array(
array('HeimrichHannot\FieldPalette\FieldPalette', 'copyFieldPaletteRecords')
),
)
)
动态操作即将被复制的字段palette记录
有时您的字段调色板记录包含对其他字段调色板记录的引用。当复制它们时,引用ID不再匹配新的(复制的)ID。您可以通过在字段的dca(类型为“字段调色板”的字段)中定义的copy_callback进行调整。
'inputType' => 'fieldpalette',
'eval' => array(
'fieldpalette' => array(
'copy_callback' => array(
array('tl_selection_model', 'updateOptionValuesOnCopy')
)
),
// ...
)
此类回调的示例
public static function updateOptionValuesOnCopy($objFieldpalette, $intPid, $intNewId, $strTable, $arrData)
{
$objFilter = \HeimrichHannot\FieldPalette\FieldPaletteModel::findByPk($objFieldpalette->selectionModel_questionData_options_filter);
if ($objFilter === null)
return;
$objFilterNew = \HeimrichHannot\FieldPalette\FieldPaletteModel::findBy(
array('selectionModel_questionData_filters_title=?', 'pid=?'),
array($objFilter->selectionModel_questionData_filters_title, $intNewId)
);
if ($objFilterNew !== null)
{
$objFieldpalette->selectionModel_questionData_options_filter = $objFilterNew->id;
}
}
功能
小部件
名称 | 描述 |
---|---|
fieldpalette | FieldPaletteWizard渲染tl_fieldpalette项目,并在其父记录(例如tl_news)内提供CRUD功能。 |
字段
tl_fieldpalette
名称 | 描述 |
---|---|
id | 自动递增的唯一标识符 |
pid | 父条目ID |
ptable | 父表名称(例如tl_news) |
pfield | 父字段名称(例如tl_news.venues) |
sorting | 排序值 |
published | 发布状态(1 = 发布) |
start | 元素发布的时间戳 |
stop | 元素停止发布的时间戳 |
表单回调
tl_fieldpalette
类型 | 描述 |
---|---|
oncreate_callback | 从请求中获取字段调色板密钥,检查父表是否在字段调色板注册表中处于活动状态,并将pfield设置为tl_fieldpalette项。 |
onsubmit_callback | 当tl_fieldpalette条目更新时,更新/同步父字段调色板项值(例如tl_news.venues)。 |
oncut_callback | 当tl_fieldpalette条目排序时,更新/同步父字段调色板项值(例如tl_news.venues)。 |
ondelete_callback | 当tl_fieldpalette条目被删除时,更新/同步父字段调色板项值(例如tl_news.venues)。 |
钩子
名称 | 参数 | 描述 |
---|---|---|
loadDataContainer | $strTable | 将父数据容器(如tl_news)中的字段注册到tl_fieldpalette,并在不存在字段调色板字段的后端模块中禁用字段调色板支持(参见:initializeSystem钩子)。 |
initializeSystem | - | 在所有后端模块中启用tl_fieldpalette表。 |
executePostActions | $strAction, \DataContainer $dc | 添加refreshFieldPaletteField AJAX操作,该操作返回更新的FieldPaletteWizard内容。 |
限制
- 仅支持DC_Table数据容器