heimrichhannot/contao-fieldpalette-bundle

FieldPalette is a contao widget like MultiColumnWizard with its own database table.


README

Build Status Coverage Status

If you're in search of an multi column input field and the storage of values in another table isn't an explicit requirement, we recommend to use Multi Column Editor Bundle instead, as it has less possible side effects and is more often updated due it's higher usage.

FieldPalette is a contao widget similar to MultiColumnWizard. Unlike MultiColumnWizard, fields are stored flatly into tl_fieldpalette table and synced with its parent field.

The fieldpalette configuration is based on Contao's Data Container Arrays.

alt fieldpalette wizard FieldPalette Wizard - ListView

alt fieldpalette edit FieldPalette Wizard - Edit item

Technical instructions

Install

composer require heimrichhannot/contao-fieldpalette-bundle

You need to updated the contao database updated.

Getting started

FieldPalette comes with an custom input type fieldpalette. The configuration for this input type is done in the fieldpalette index of the field configuration array. You can customize your fieldpalette nearly as an "normal" dca configuration. When you finished setting up your fieldpalette input, you need to call the contao database tool to add the new fields to the table. See following example for a real world use case:

Default Setup (tl_fieldpalette table)

This example shows the setup of an fieldpalette field within tl_news by using it within an subpalette. That (shortend) example is available within the module Contao News Leisure Bundle.

// src/Resource/contao/dca/tl_news.php (Bundle)
// app/Resource/contao/dca/tl_news.php (Contao 4.4 Projekt)
// contao/dca/tl_news.php (Contao 4.9 Projekt)

$dc = &$GLOBALS['TL_DCA']['tl_news'];

$fields = array
(
	'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',
			),
			'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 ''",
				),
			),
		),
	),
);

$dc['fields'] = array_merge($dc['fields'], $fields);

Developers

Guides

DCA reference
Custom table set up
Working with fieldpalette records (copying (parent) records)

Working with fieldpalette model

The FieldPaletteModel is not intended to be called directly and all custom methods are non static. We recommend to use the huh.fieldpalette.manager service.

Example:

/** 
 * @var ContainerInterface $container 
 */

// Return a model instance (with default table) for usage with model method (like find methods)
$container->get('huh.fieldpalette.manager')->getInstance()->findByPidAndTableAndField($item->id, 'tl_item', 'parentItem');

// Return a new model instance
$container->get('huh.fieldpalette.manager')->createModel()->findByPidAndTableAndField($item->id, 'tl_item', 'parentItem');

// Return a new model instance with custom table
$container->get('huh.fieldpalette.manager')->createModelByTable('tl_my_custom_table')->findByPidAndTableAndField($item->id, 'tl_item', 'parentItem');

Default model methods are still callable static. Custom method can also be called by creating a new model instance.

Widgets

Fields

tl_fieldpalette:

Form Callbacks

tl_fieldpalette:

Hooks

Restrictions

  • only supports DC_Table DataContainers