<?php

/*
 * This file is part of newsmailer bundle for Contao.
 *
 * (c) Benjamin Roth
 *
 * @license LGPL-3.0-or-later
 */

use Contao\CoreBundle\DataContainer\PaletteManipulator;

/**
 * Palettes
 */

PaletteManipulator::create()
    ->addLegend('nc_legend','protected_legend',PaletteManipulator::POSITION_BEFORE)
    ->addField('nc_enable','nc_legend', PaletteManipulator::POSITION_APPEND)
    ->applyToPalette('default','tl_news_archive')
;
$GLOBALS['TL_DCA']['tl_news_archive']['palettes']['__selector__'][] = 'nc_enable';
$GLOBALS['TL_DCA']['tl_news_archive']['subpalettes']['nc_enable'] = 'nc_notification,nc_notification_groups';


/**
 * Fields
 */

$GLOBALS['TL_DCA']['tl_news_archive']['fields']['nc_enable'] = array
(
    'exclude'                 => true,
    'inputType'               => 'checkbox',
    'eval'                    => array('tl_class'=>'w50 m12','submitOnChange'=>true),
    'sql'                     => "char(1) NOT NULL default ''"
);

$GLOBALS['TL_DCA']['tl_news_archive']['fields']['nc_notification_groups'] = array
(
    'exclude'                 => true,
    'inputType'               => 'checkbox',
    'foreignKey'              => 'tl_member_group.name',
    'eval'                    => array('mandatory'=>true, 'multiple'=>true,'tl_class'=>'clr'),
    'sql'                     => "blob NULL",
    'relation'                => array('type'=>'hasMany', 'load'=>'lazy')
);

$GLOBALS['TL_DCA']['tl_news_archive']['fields']['nc_notification'] = array
(
    'exclude'                   => true,
    'inputType'                 => 'select',
    'eval'                      => array('mandatory'=>true,'includeBlankOption'=>true, 'chosen'=>true, 'tl_class'=>'w50'),
    'sql'                       => "int(10) unsigned NOT NULL default '0'"
);