PHP code example of heimrichhannot / contao-fieldpalette-bundle

1. Go to this page and download the library: Download heimrichhannot/contao-fieldpalette-bundle 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-bundle example snippets


# contao/dca/tl_news.php

$GLOBALS['TL_DCA']['tl_news']['fields']['venues'] = [
    'inputType' => 'fieldpalette',
    'foreignKey' => 'tl_fieldpalette.id',
    'relation' => ['type' => 'hasMany', 'load' => 'eager'],
    'sql' => "blob NULL",
    'fieldpalette' => [
        'config' => [
            'hidePublished' => false
        ],
        'list' => [
            'label' => [
                'fields' => ['venueName', 'venueStreet', 'venuePostal', 'venueCity'],
                'format' => '%s <span style="color:#b3b3b3;padding-left:3px">[%s, %s %s]</span>',
            ],
        ],
        'palettes' => [
            'default' => 'venueName,venueStreet,venuePostal,venueCity',
        ],
        'fields' => [
            'venueName' => [
                'label' => &$GLOBALS['TL_LANG']['tl_news']['venueName'],
                'exclude' => true,
                'search' => true,
                'inputType' => 'text',
                'eval' => ['maxlength' => 255, 'tl_class' => 'long'],
                'sql' => "varchar(255) NOT NULL default ''",
            ],
            'venueStreet' => [
                'label' => &$GLOBALS['TL_LANG']['tl_news']['venueStreet'],
                'exclude' => true,
                'search' => true,
                'inputType' => 'text',
                'eval' => ['maxlength' => 255, 'tl_class' => 'w50'],
                'sql' => "varchar(255) NOT NULL default ''",
            ],
            'venuePostal' => [
                'label' => &$GLOBALS['TL_LANG']['tl_news']['venuePostal'],
                'exclude' => true,
                'search' => true,
                'inputType' => 'text',
                'eval' => ['maxlength' => 32, 'tl_class' => 'w50'],
                'sql' => "varchar(32) NOT NULL default ''",
            ],
            'venueCity' => [
                'label' => &$GLOBALS['TL_LANG']['tl_news']['venueCity'],
                'exclude' => true,
                'filter' => true,
                'search' => true,
                'sorting' => true,
                'inputType' => 'text',
                'eval' => ['maxlength' => 255, 'tl_class' => 'w50'],
                'sql' => "varchar(255) NOT NULL default ''",
            ],
        ],
    ],
];

/** 
 * @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');