[1597 Aufrufe]

3.8 Beispiele für Felddefinitionen

Nachdem wir uns in den letzten Kapiteln die Grundlagen der Feldkonfigurationen erarbeitet haben, möchte ich diese nun mit einigen Beipsielen vertiefen. Zuerst zeige ich für jeden Feldtyp eine grundlegenede Konfiguration. Im Anschluss liste ich noch einige Beispiele für spezielle Verwendungszwecke auf.

Die Liste erhebt keinen Anspruch auf Vollständigkeit. Die Felder müssen nicht genau so genutzt werden. Es ist sinnvoll, diese Anregungen an den jeweiligen Anwengungszweck anzupassen.

Hier noch einmal der Aufbau unseres DCAs aus den letzten Kapiteln in verkürzter Form:

<?php

$GLOBALS['TL_DCA']['tl_testtable'] = [
    // Config ...
    // List ...
    // Palettes ...
    // Subpalettes ...
    'fields' => [
        // Hier würden die gezeigen Definitionen eingefügt!
    ]
];

Übersicht der Standardfelder

Texfeld (text)

Konfiguration für ein Textfeld:

<?php

'mytext' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['maxlength'=>255, 'tl_class'=>'w50'],
    'sql'                   => "varchar(255) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_text


Passwortfeld (password)

Konfiguration für ein Passwordfeld:

<?php

'mypassword' => [
    'exclude'               => true,
    'inputType'             => 'password',
    'eval'                  => ['mandatory'=>true, 'preserveTags'=>true, 'minlength'=>\Contao\Config::get('minPasswordLength')],
    'sql'                   => "varchar(128) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_password


Textarea (textarea)

Konfiguration für eine einfache Textarea:

<?php

'mytextarea' => [
    'exclude'               => true,
    'search'                => true,
    'inputType'             => 'textarea',
    'eval'                  => ['tl_class'=>'clr'],
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_textarea_simple


Textarea mit TinyMCE (textarea)

Konfiguration für eine Textarea mit TinyMCE:

<?php

'mytextarea' => [
    'exclude'               => true,
    'search'                => true,
    'inputType'             => 'textarea',
    'eval'                  => ['rte'=>'tinyMCE', 'tl_class'=>'clr'],
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_textarea


Textarea mit ACE (textarea)

Konfiguration für eine Textarea mit Syntax Highlighting für HTML:

<?php

'mytextarea' => [
    'exclude'               => true,
    'search'                => true,
    'inputType'             => 'textarea',
    'eval'                  => ['rte'=>'ace|html', 'tl_class'=>'clr', 'allowHtml'=>true, 'class'=>'monospace', 'helpwizard'=>true],
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_textarea_ace


Auswahlfeld (select)

Konfiguration für ein Auswahlfeld:

<?php

'myselect' => [
    'exclude'               => true,
    'inputType'             => 'select',
    'options'               => ['opt01', 'opt02', 'opt03'],
    'reference'             => &$GLOBALS['TL_LANG'][$table]['myselect']['options'],
    //'foreignKey'          => 'tl_user.name',
    //'options_callback'    => ['CLASS', 'METHOD'],
    'eval'                  => ['includeBlankOption'=>true, 'tl_class'=>'w50', 'chosen'=>true],
    'sql'                   => "varchar(255) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_select


Clicklist (select)

Konfiguration für eine Clicklist:

<?php

'myclicklist' => [
    'exclude'               => true,
    'inputType'             => 'select',
    'options'               => ['opt01', 'opt02', 'opt03'],
    'reference'             => &$GLOBALS['TL_LANG'][$table]['myclicklist']['options'],
    //'foreignKey'          => 'tl_user.name',
    //'options_callback'    =>['CLASS', 'METHOD'],
    'eval'                  => ['maxlength'=>255, 'includeBlankOption'=>true, 'multiple'=>true, 'chosen'=>true],
    'sql'                   => "varchar(255) NOT NULL default ''"
]

Durch 'multiple'=>true in Kombination mit 'chosen'=>true wird aus dem Auswahlfeld eine Clickliste.

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_select_clicklist


Checkbox (checkbox)

Konfiguration für eine Checkbox:

<?php

'mycheckbox' => [
    'exclude'               => true,
    'inputType'             => 'checkbox',
    'default'               => 1,
    'eval'                  => ['tl_class'=>'w50'],
    'sql'                   => "char(1) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_checkbox


Radio-Button (radio)

Konfiguration für einen Radio-Button:

<?php

'myradio' => [
    'exclude'               => true,
    'inputType'             => 'radio',
    'options'               => ['opt01', 'opt02', 'opt03'],
    'reference'             => &$GLOBALS['TL_LANG'][$table]['myselect']['options'],
    'eval'                  => ['tl_class'=>'w50'],
    'sql'                   => "varchar(255) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_radio


Tabelle mit Radio-Buttons (radioTable)

Konfiguration für eine Tabelle mit Radio-Button:

<?php

'myradiotable' => [
    'exclude'               => true,
    'inputType'             => 'radioTable',
    'options'               => ['opt01', 'opt02', 'opt03'],
    'reference'             => &$GLOBALS['TL_LANG'][$table]['myradiotable']['options'],
    //'foreignKey'          => 'tl_user.name',
    //'options_callback'    => array('CLASS', 'METHOD'),
    'eval'                  => ['cols'=>4, 'tl_class'=>'w50'],
    'sql'                   => "varchar(255) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_radioTable


Bildgröße (imageSize)

Konfiguration für die Auswahl von Bildgröße:

<?php

'myimagesize' => array
(
    'exclude'               => true,
    'inputType'             => 'imageSize',
    'options'               => \Contao\System::getImageSizes(),
    'reference'             => &$GLOBALS['TL_LANG']['MSC'],
    'eval'                  => ['rgxp'=>'natural', 'includeBlankOption'=>true, 'nospace'=>true, 'helpwizard'=>true, 'tl_class'=>'w50'],
    'sql'                   => "varchar(64) NOT NULL default ''"
)

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_imageSize


Eingabefeld mit Einheit (inputUnit)

Konfiguration für ein Eingabefeld mit Einheit:

<?php

'myinputunit' => [
    'exclude'               => true,
    'inputType'             => 'inputUnit',
    'options'               => ['opt01', 'opt02', 'opt03'],
    'reference'             => &$GLOBALS['TL_LANG'][$table]['myinputunit']['options'],
    //'foreignKey'          => 'tl_user.name',
    //'options_callback'    => ['CLASS', 'METHOD'],
    'eval'                  => ['includeBlankOption'=>true, 'rgxp'=>'digit_auto_inherit', 'maxlength' => 20, 'tl_class'=>'w50'],
    'sql'                   => "varchar(64) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_inputUnit


Vier Eingabefelder mit Einheit (trbl)

Konfiguration für vier Eingabefelder mit einem Feld für die Einheit:

<?php

'mytrbl' => [
    'exclude'               => true,
    'inputType'             => 'trbl',
    'options'               => $GLOBALS['TL_CSS_UNITS'],
    'eval'                  => ['includeBlankOption'=>true, 'tl_class'=>'w50'],
    'sql'                   => "varchar(128) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_trbl


Tabelle für Dateirechte (chmod)

Konfiguration für die Auswahl von Zugriffsrchten:

<?php

'mychmod' => [
    'exclude'               => true,
    'inputType'             => 'chmod',
    'default'               => \Contao\Config::get('defaultChmod'),
    'eval'                  => ['tl_class'=>'clr'],
    'sql'                   => "varchar(255) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_chmod


Seitenbaum für eine Seite (pageTree)

Konfiguration für einen Seitenbaum zur Auswahl einer Seite:

<?php

'mypagetree' => [
    'exclude'               => true,
    'inputType'             => 'pageTree',
    'eval'                  => ['fieldType'=>'radio', 'tl_class'=>'clr'],
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_pageTree


Seitenbaum für mehrere Seiten (pageTree)

Konfiguration für einen Seitenbaum zur Auswahl mehrerer Seiten:

<?php

'mypagetree' => [
    'exclude'               => true,
    'inputType'             => 'pageTree',
    'eval'                  => ['fieldType'=>'checkbox', 'tl_class'=>'clr', 'multiple'=>true],
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_pagetree_multiple


Dateibaum für eine Datei (fileTree)

Konfiguration für einen Dateibaum zur Auswahl einer Datei:

<?php

'myfiletree' => [
    'exclude'               => true,
    'inputType'             => 'fileTree',
    'eval'                  => ['fieldType'=>'radio', 'files'=>true, 'filesOnly'=>true, 'tl_class'=>'clr', 'extensions'=>\Contao\Config::get('validImageTypes')],
    'sql'                   => 'binary(16) NULL'
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_fileTree


Dateibaum für mehrere Dateien (fileTree)

Konfiguration für einen Dateibaum zur Auswahl mehrerer Dateien:

<?php

'myfiletree' => [
    'exclude'               => true,
    'inputType'             => 'fileTree',
    'eval'                  => ['fieldType'=>'checkbox', 'files'=>true, 'filesOnly'=>true, 'multiple'=>true, 'tl_class'=>'clr', 'extensions'=>\Contao\Config::get('uploadTypes'), 'orderField'=>'ordermyfiletree', 'isGallery'=>true],
    'sql'                   => 'binary(16) NULL'
],
'ordermyfiletree' => [  // Nur nötig, wenn die Dateien sortiert werden sollen!
    'sql'                   => 'binary(16) NULL'
]

Für extensions wäre auch \Contao\Config::get('allowedDownload') möglich. isGallery ist nicht zwingend, wenn keine Galierie erstellt wird. Es ermöglicht zusammen mit orderField das Sortieren von Bildern für eine Galerie. Das zusätzliche Feld für die Sortierung (ordermyfiletree) muss nur angelegt werden, wenn es unter orderField angegeben wird.

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_filetree_multiple


Dateibaum für ein Verzeichnis (fileTree)

Konfiguration für einen Dateibaum zur Auswahl eines Verzeichnisses:

<?php

'myfiletree' => [
    'exclude'               => true,
    'inputType'             => 'fileTree',
    'eval'                  => ['fieldType'=>'radio', 'tl_class'=>'clr'],
    'sql'                   => 'binary(16) NULL'
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_filetree_folders


Dateibaum für mehrere Verzeichnisse (fileTree)

Konfiguration für einen Dateibaum zur Auswahl mehrerer Verzeichnisse:

<?php

'myfiletree' => [
    'exclude'               => true,
    'inputType'             => 'fileTree',
    'eval'                  => ['fieldType'=>'checkbox', 'tl_class'=>'clr', 'multiple'=>true],
    'sql'                   => 'binary(16) NULL'
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_filetree_folders_multiple


Tabelle (tableWizard)

Konfiguration für eine Tabelle:

<?php

'mytableeizard' => [
    'exclude'                 => true,
    'inputType'               => 'tableWizard',
    'eval'                    => ['allowHtml'=>true, 'doNotSaveEmpty'=>true, 'style'=>'width:142px;height:66px'],
    'sql'                     => 'mediumtext NULL'
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_tableWizard


Textfeld mit Auswahlfeld (timePeriod)

Konfiguration für ein Textfeld mit einem Auswahlfeld:

<?php

'mytimeperiod' => [
    'exclude'               => true,
    'inputType'             => 'timePeriod',
    'options'               => ['opt01', 'opt02', 'opt03'],
    'reference'             => &$GLOBALS['TL_LANG'][$table]['mytimeperiod']['options'],
    'eval'                  => ['tl_class'=>'w50'],
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_timePeriod


Liste (listWizard)

Konfiguration für eine Liste:

<?php

'mylistwizard' => [
    'exclude'               => true,
    'inputType'             => 'listWizard',
    'eval'                  => ['allowHtml'=>true, 'tl_class'=>'clr'],
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_listWizard


Verwaltung von Optionen (optionWizard)

Konfiguration für eine Liste von Optionen:

<?php

'myoptionwizard' => [
    'exclude'               => true,
    'inputType'             => 'optionWizard',
    'eval'                  => ['mandatory'=>true, 'allowHtml'=>true],
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_optionWizard


Verwaltung von Modulen (moduleWizard)

Konfiguration für eine Liste von Modulen:

<?php

'mymodulewizard' => [
    'default'               => [['mod'=>0, 'col'=>'main', 'enable'=>1]],
    'exclude'               => true,
    'inputType'             => 'moduleWizard',
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_moduleWizard


Sortierbare Checkbox-Liste (checkboxWizard)

Konfiguration für eine sortierbare Checkbox-Liste:

<?php

'mycheckboxwizard' => [
    'exclude'               => true,
    'inputType'             => 'checkboxWizard',
    'options'               => ['opt01', 'opt02', 'opt03'],
    'reference'             => &$GLOBALS['TL_LANG'][$table]['mycheckboxwizard']['options'],
    //'foreignKey'          => 'tl_user.name',
    //'options_callback'    => ['CLASS', 'METHOD'],
    'eval'                  => ['multiple'=>true],
    'sql'                   => 'text NULL'
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_checkboxWizard


Versteckte Eingabe (textStore)

Konfiguration für ein Feld zur verdeckten Eingabe von Werte:

<?php

'mytextstore' => [
    'exclude'               => true,
    'inputType'             => 'textStore',
    'eval'                  => ['tl_class'=>'w50', 'maxlength'=>255],
    'sql'                   => 'varchar(255) NOT NULL default '''
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_textStore


Zweckgebundene Felder

Hier finden sich Feldkonfigurationen für häufig benötigte Zwecke.

Id

Konfiguration für das Feld id:

<?php

'id' => [
    'sql'                   => 'int(10) unsigned NOT NULL auto_increment'
]

Dieses Feld wird im Backend nicht angezeigt, da es von Contao intern verwendet wird, um die Datensätze zu identifizieren. Das Feld id ist in fast jeder Tabelle vorhanden.


Pid

Konfiguration für das Feld pid:

<?php

'pid' => [
    'sql'                   => "int(10) unsigned NOT NULL default '0'"

]

Dieses Feld wird im Backend nicht angezeigt, da es von Contao intern verwendet wird, um die Beziehung zu einem Elterndatensatz herzustellen.


Zeitstempel

Konfiguration für das Feld tstamp:

<?php

'tstamp' => [
    'sql'                   => "int(10) unsigned NOT NULL default '0'"
]

Dieses Feld wird im Backend nicht angezeigt, da es von Contao intern verwendet wird, um die letzte Bearbeitung zu speichern. Das Feld tstamp ist in fast jeder Tabelle vorhanden.


Sorting

Konfiguration für das Feld sorting:

<?php

'sorting' => [
    'sql'                   => "int(10) unsigned NOT NULL default '0'"
]

Dieses Feld wird im Backend nicht angezeigt, da es von Contao für die Sortierung der Datensätze verwendet wird.


Natürliche Zahl

Konfiguration für ein Eingabefeld zur Eingabe einer natürlichen Zahl:

<?php

'mynatural' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['maxlength'=>10, 'rgxp'=>'natural'],
    'sql'                   => "int(10) unsigned NOT NULL default '0'"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_natural


Zahl

Konfiguration für ein Eingabefeld zur Eingabe einer Zahl:

<?php

'mydigit' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['maxlength'=>10, 'rgxp'=>'digit'],
    'sql'                   => "int(10) unsigned NOT NULL default '0'"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_digit


Datum

Konfiguration für ein Eingabefeld zur Eingabe eines Datums:

<?php

'mydate' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['rgxp'=>'date', 'datepicker'=>true, 'tl_class'=>'w50 wizard'],
    'sql'                   => "varchar(10) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_date


Datum und Zeit

Konfiguration für ein Eingabefeld zur Eingabe eines Datums, inkl. Uhrzeit:

<?php

'mydate' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['rgxp'=>'datim', 'datepicker'=>true, 'tl_class'=>'w50 wizard'],
    'sql'                   => "varchar(10) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_datim


Telefon

Konfiguration für ein Eingabefeld zur Eingabe einer Telefonnummer:

<?php

'myphone' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['maxlength'=>64, 'rgxp'=>'phone', 'decodeEntities'=>true, 'tl_class'=>'w50'],
    'sql'                   => "varchar(64) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_phone


E-Mail

Konfiguration für ein Eingabefeld zur Eingabe einer E-Mail-Adresse:

<?php

'myemail' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['mandatory'=>true, 'rgxp'=>'email', 'maxlength'=>255, 'decodeEntities'=>true, 'tl_class'=>'w50'],
    'sql'                   => "varchar(255) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_email


Postleitzahl

Konfiguration für ein Eingabefeld zur Eingabe einer Postleitzahl:

<?php

'mypostal' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['maxlength'=>32, 'tl_class'=>'w50'],
    'sql'                   => "varchar(32) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_postal


Farbwähler

Konfiguration für ein Auswahlfeld zur Auswahl einer Farbe:

<?php

'mycolor' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['maxlength'=>6, 'multiple'=>true, 'size'=>2, 'colorpicker'=>true, 'isHexColor'=>true, 'decodeEntities'=>true, 'tl_class'=>'w50 wizard'],
    'sql'                   => "varchar(64) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_color


Vier Textfelder

Konfiguration für 4 Eingabefeld:

<?php

'mymultitext' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['multiple'=>true, 'size'=>4, 'decodeEntities'=>true, 'tl_class'=>'w50'],
    'sql'                   => "varchar(128) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_four_txt


Land

Konfiguration für ein Auswahlfeld zur Auswahl eines Landes:

<?php

'mycountry' => [
    'exclude'               => true,
    'inputType'             => 'select',
    'options'               => \Contao\System::getCountries(),
    'eval'                  => ['includeBlankOption'=>true, 'chosen'=>true, 'tl_class'=>'w50'],
    'sql'                   => "varchar(2) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_country


URL

Konfiguration für ein Eingabefeld zur Eingabe einer Url:

<?php

'myurl' => [
    'exclude'               => true,
    'inputType'             => 'text',
    'eval'                  => ['mandatory'=>true, 'rgxp'=>'url', 'decodeEntities'=>true, 'maxlength'=>255, 'tl_class'=>'w50 wizard'],
    'wizard'                => [['tl_content', 'pagePicker']],
    'sql'                   => "varchar(255) NOT NULL default ''"
)

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_url


Mitgliederauswahl

Konfiguration für ein Auswahlfeld zur Auswahl eines Frontend-Mitglieds:

<?php

'mymemberfield' => [
    'exclude'               => true,
    'inputType'             => 'select',
    'foreignKey'            => "tl_member.CONCAT(lastname, ', ', firstname)",
    'eval'                  => ['tl_class'=>'w50', 'chosen'=>true, 'includeBlenkOption'=>true],
    'sql'                   => "int(10) NOT NULL default '0'"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_member


Benutzerauswahl

Konfiguration für ein Auswahlfeld zur Auswahl eines Bachend-Nutzers:

<?php

'myuserfield' => [
    'exclude'               => true,
    'inputType'             => 'select',
    'foreignKey'            => 'tl_user.name',
    'eval'                  => ['tl_class'=>'w50', 'includeBlankOption'=>true, 'chosen'=>true],
    'sql'                   => "int(10) NOT NULL default '0'"
]

Beispiel für eine Ausgabe:

06_DCA_Fieldsdefinition_user


Templateauswahl

Konfiguration für ein Auswahlfeld zur Auswahl eines Templates:

<?php

'mytemplate' => [
    'exclude'               => true,
    'inputType'             => 'select',
    'options'               => \Conto\Controller::getTemplateGroup('ce_text'),
    'eval'                  => ['includeBlankOption'=>true, 'chosen'=>true, 'tl_class'=>'w50'],
    'sql'                   => "varchar(64) NOT NULL default ''"
]

Beispiel für eine Ausgabe:

05_DCA_Fields_inputType_select