PHP code example of heimrichhannot / contao-fieldpalette
1. Go to this page and download the library: Download heimrichhannot/contao-fieldpalette library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
heimrichhannot / contao-fieldpalette example snippets
#/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('
/* /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);
/* /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',
],
],
];
$GLOBALS['TL_DCA']['tl_*'] = array
(
'config' => array
(
// ...
'oncopy_callback' => array(
array('HeimrichHannot\FieldPalette\FieldPalette', 'copyFieldPaletteRecords')
),
)
)
'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;
}
}