Ich bin auch grad auf der Suche nach so einer Möglichkeit.... hat jemand evtl. einen anderen Ansatz gefunden?
Edit: habe selber einen gefunden ;-)
Das Kommentar-Modul muss eigentlich nur erweitert werden. Ich habe ein neues Modul geschrieben mit einer Klasse, die \Contao\Comments erweitert und in der die Funktion renderCommentForm überschrieben wird. Die neue Funktion ist im Grunde nur eine Kopie der Original-Funktion, wobei bei der Definition von $arrFields das Feld ergänzt wird, was man im FE noch haben möchte.
Bei der Definition von $arrSet muss man noch den Wert für ein neues DCA-Feld im BE zuweisen.
Auf die Weise kann das Kommentar-Formular um beliebige zulässige FE-Felder (siehe $GLOBALS['TL_FFL']) ergänzt werden.
Hier mal ein Auszug für ein Textfeld "headline". In ähnlicher Weise kann das auch für den Feldtyp upload umgesetzt werden.
classes/CommentsExtended.php
PHP-Code:
class CommentsExtended extends \Comments {
protected function renderCommentForm(\FrontendTemplate $objTemplate, \stdClass $objConfig, $strSource, $intParent, $varNotifies)
{
....
$arrFields = array
(
'name' => array
(
'name' => 'name',
'label' => $GLOBALS['TL_LANG']['MSC']['com_name'],
'value' => trim($this->User->firstname . ' ' . $this->User->lastname),
'inputType' => 'text',
'eval' => array('mandatory'=>false, 'maxlength'=>64)
),
'email' => array
(
'name' => 'email',
'label' => $GLOBALS['TL_LANG']['MSC']['com_email'],
'value' => $this->User->email,
'inputType' => 'text',
'eval' => array('rgxp'=>'email', 'mandatory'=>true, 'maxlength'=>128, 'decodeEntities'=>true)
),
'headline' => array
(
'name' => 'headline',
'label' => $GLOBALS['TL_LANG']['MSC']['com_headline'],
'inputType' => 'text',
'eval' => array('maxlength'=>128)
)
)
....
$arrSet = array
(
'tstamp' => $time,
'source' => $strSource,
'parent' => $intParent,
'name' => $arrWidgets['name']->value,
'email' => $arrWidgets['email']->value,
'headline' => $arrWidgets['headline']->value,
'comment' => $this->convertLineFeeds($strComment),
'ip' => $this->anonymizeIp(\Environment::get('ip')),
'date' => $time,
'published' => ($objConfig->moderate ? '' : 1)
);
....
}
}
dca/tl_comments.php
PHP-Code:
$GLOBALS['TL_DCA']['tl_comments']['palettes']['default'] = str_replace(
'{comment_legend},',
'{comment_legend},headline,',
$GLOBALS['TL_DCA']['tl_comments']['palettes']['default']);
$GLOBALS['TL_DCA']['tl_comments']['fields']['headline'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_comments']['headline'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('maxlength'=>200),
'sql' => "varchar(255) NOT NULL default ''"
);
Für meine Lösung des Bilder-Uploads nutze ich noch den Contao Fineuploader. Wenn ich Zeit finde, beschreibe ich dafür auch noch die Vorgehensweise.
Lesezeichen