Initial release
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Contao\Database;
|
||||
use Contao\StringUtil;
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_module']['palettes']['news_submission'] = '{title_legend},name,headline,type;{news_submission_legend},author,newsArchive,uploadFolder,thankYouPage,allowedTags;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
|
||||
$GLOBALS['TL_DCA']['tl_module']['palettes']['event_submission_confirmation'] = '{title_legend},name,headline,type;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_module']['fields']['author'] = [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_module']['author'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'select',
|
||||
'foreignKey' => 'tl_user.name',
|
||||
'eval' => ['mandatory' => true, 'chosen' => true, 'includeBlankOption' => true, 'tl_class' => 'w50'],
|
||||
'sql' => ['type' => 'integer', 'unsigned' => true, 'default' => 0],
|
||||
'relation' => ['type' => 'hasOne', 'load' => 'lazy'],
|
||||
];
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_module']['fields']['newsArchive'] = [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_module']['newsArchive'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'select',
|
||||
'foreignKey' => 'tl_news_archive.title',
|
||||
'eval' => ['mandatory' => true, 'chosen' => true, 'includeBlankOption' => true, 'tl_class' => 'w50'],
|
||||
'sql' => ['type' => 'integer', 'unsigned' => true, 'default' => 0],
|
||||
'relation' => ['type' => 'hasOne', 'load' => 'lazy'],
|
||||
];
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_module']['fields']['uploadFolder'] = [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_module']['uploadFolder'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'fileTree',
|
||||
'eval' => ['fieldType' => 'radio', 'files' => false, 'mandatory' => true, 'tl_class' => 'w50'],
|
||||
'sql' => ['type' => 'binary', 'length' => 16, 'notnull' => false],
|
||||
];
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_module']['fields']['thankYouPage'] = [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_module']['thankYouPage'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'pageTree',
|
||||
'eval' => ['fieldType' => 'radio', 'mandatory' => true, 'tl_class' => 'w50'],
|
||||
'sql' => ['type' => 'integer', 'unsigned' => true, 'default' => 0],
|
||||
];
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_module']['fields']['allowedTags'] = [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_module']['allowedTags'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'checkbox',
|
||||
'options_callback' => static function (): array {
|
||||
$rows = Database::getInstance()
|
||||
->prepare("SELECT id, tag FROM tl_tags WHERE invisible='' ORDER BY tag ASC")
|
||||
->execute()
|
||||
->fetchAllAssoc();
|
||||
|
||||
$options = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$options[(int) $row['id']] = (string) $row['tag'];
|
||||
}
|
||||
|
||||
return $options;
|
||||
},
|
||||
'eval' => ['multiple' => true, 'tl_class' => 'clr'],
|
||||
'sql' => ['type' => 'blob', 'notnull' => false],
|
||||
'save_callback' => [
|
||||
static function ($value): array {
|
||||
return array_values(array_unique(array_map('intval', StringUtil::deserialize($value, true))));
|
||||
},
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Contao\CoreBundle\DataContainer\PaletteManipulator;
|
||||
use Contao\DataContainer;
|
||||
use Contao\Database;
|
||||
|
||||
PaletteManipulator::create()
|
||||
->addLegend('submission_legend', 'publish_legend', 'before')
|
||||
->addField('submittedByMember', 'submission_legend', 'append')
|
||||
->addField('submittedByName', 'submission_legend', 'append')
|
||||
->addField('submittedByEmail', 'submission_legend', 'append')
|
||||
->applyToPalette('default', 'tl_news')
|
||||
->applyToPalette('internal', 'tl_news')
|
||||
->applyToPalette('article', 'tl_news')
|
||||
->applyToPalette('external', 'tl_news');
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_news']['config']['onsubmit_callback'][] = static function (DataContainer $dc): void {
|
||||
$newsId = (int) ($dc->id ?? 0);
|
||||
|
||||
if ($newsId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$database = Database::getInstance();
|
||||
|
||||
$memberId = (int) $database
|
||||
->prepare('SELECT submittedByMember FROM tl_news WHERE id=?')
|
||||
->limit(1)
|
||||
->execute($newsId)
|
||||
->submittedByMember;
|
||||
|
||||
if ($memberId <= 0) {
|
||||
$database
|
||||
->prepare('UPDATE tl_news SET submittedByName=?, submittedByEmail=? WHERE id=?')
|
||||
->execute('', '', $newsId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$member = $database
|
||||
->prepare('SELECT firstname, lastname, email FROM tl_member WHERE id=?')
|
||||
->limit(1)
|
||||
->execute($memberId)
|
||||
->fetchAssoc();
|
||||
|
||||
if (false === $member || null === $member) {
|
||||
$database
|
||||
->prepare('UPDATE tl_news SET submittedByName=?, submittedByEmail=? WHERE id=?')
|
||||
->execute('', '', $newsId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$name = trim((string) (($member['firstname'] ?? '').' '.($member['lastname'] ?? '')));
|
||||
$email = trim((string) ($member['email'] ?? ''));
|
||||
|
||||
$database
|
||||
->prepare('UPDATE tl_news SET submittedByName=?, submittedByEmail=? WHERE id=?')
|
||||
->execute($name, $email, $newsId);
|
||||
};
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_news']['fields']['submittedByMember'] = [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_news']['submittedByMember'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'select',
|
||||
'options_callback' => static function (): array {
|
||||
$rows = Database::getInstance()
|
||||
->prepare('SELECT id, firstname, lastname FROM tl_member ORDER BY lastname ASC, firstname ASC')
|
||||
->execute()
|
||||
->fetchAllAssoc();
|
||||
|
||||
$options = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
|
||||
if ($id <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lastName = trim((string) ($row['lastname'] ?? ''));
|
||||
$firstName = trim((string) ($row['firstname'] ?? ''));
|
||||
$label = trim($lastName.', '.$firstName, ' ,');
|
||||
|
||||
$options[$id] = '' !== $label ? $label : 'Mitglied #'.$id;
|
||||
}
|
||||
|
||||
return $options;
|
||||
},
|
||||
'save_callback' => [
|
||||
static function ($value): int {
|
||||
return max(0, (int) $value);
|
||||
},
|
||||
],
|
||||
'eval' => ['chosen' => true, 'includeBlankOption' => true, 'tl_class' => 'clr w50'],
|
||||
'sql' => ['type' => 'integer', 'unsigned' => true, 'notnull' => false],
|
||||
];
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_news']['fields']['submittedByName'] = [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_news']['submittedByName'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'eval' => ['readonly' => true, 'disabled' => true, 'tl_class' => 'w50'],
|
||||
'sql' => "varchar(255) NOT NULL default ''",
|
||||
];
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_news']['fields']['submittedByEmail'] = [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_news']['submittedByEmail'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'eval' => ['readonly' => true, 'disabled' => true, 'rgxp' => 'email', 'tl_class' => 'w50'],
|
||||
'sql' => "varchar(255) NOT NULL default ''",
|
||||
];
|
||||
Reference in New Issue
Block a user