


Wie man in die Listen von Contao eigene Aktionen einträgt, habe ich ja bereits im Artikel "Eine eigene Aktion in eine Contao-Übersicht einfügen" beschrieben. Bei diesem Vorgehen wird für alle Einträge der Liste das gleiche Icon angezeigt. Es handelt sich also um ein globales Icon. Es ist nicht möglich verschiedene Icons pro Listeneintrag anzuzeigen (um z.B. einen Status abzubilden). Wie man individuelle Icons für eine Aktion anzeigt, ist Thema dieses Artikels.
Zu nächst legen wir eine Aktion mit Standard-Icon an. Dies geschieht wie in dem Beitrag „Eine eigene Aktion in eine Contao-Übersicht einfügen“.
Nun geben wir den button_callback bekannt. Dieser erstellt den Link für den Aufruf unserer Aktion mit dem individuellen Icon. Wir tragen dazu in die Datei mit dem Namen unserer Tabelle im dca-Verzeichnis unserer Erweiterung eine Klasse und einen Methodennamen ein (z.B. demoErweiterung/dca/tl_beispiel.php).
$GLOBALS['TL_DCA']['tl_beispiel']['list']['operations']['testaktion'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_beispiel']['testaktion'],
'href' => 'key=reset',
'icon' => 'system/modules/demoErweiterung/html/standardIcon.png',
'button_callback' => array('demoErweiterungsKlasse', 'makeIconMethode')
);Wichtig ist hier die Zeile 'button_callback' => array('demoErweiterungsKlasse', 'makeIconMethode'). Durch die Methode makeIconMethode der Klasse demoErweiterungsKlasse wird also das Icon erstellt.
| $arrRow | the current row |
| $href | the url of the embedded link of the button |
| $label | label text for the button |
| $title | title value for the button |
| $icon | url of the image for the button |
| $attributes | additional attributes for the button (fetched from the array key "attributes" in the DCA) |
| $strTable | the name of the current table |
| $arrRootIds | array of the ids of the selected "page mounts" (only in tree view) |
| $arrChildRecordIds | ids of the childs of the current record (only in tree view) |
| $blnCircularReference | determines if this record has a circular reference (used to prevent pasting of an cutted item from an tree into any of it's childs). |
| $strPrevious | id of the previous entry on the same parent/child level. Used for move up/down buttons. Not for root entries in tree view. |
| $strNext | id of the next entry on the same parent/child level. Used for move up/down buttons. Not for root entries in tree view. |
(Danke an Xtra aus dem Contao-Forum, der diese Liste hier gepostet hat.)
Contao erwartet von der Methode die Rückgabe eines Links, der wie folgt aufgebaut werden kann.
return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';
Vorher legt man für $icon den Pfad zum gewünschten Icon fest.
Möchte man für jede gerade Id ein anderes Icon darstellen schreibt man in die Callback-Methode vor dem return:
if($arrRow %2 == 0){
$icon = 'system/modules/demoErweiterung/html/anderesIcon.png';
}
return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';Für die ungeraden Id's wird das Standardicon verwendet. Natürlich lassen sich beliebige Eigenschaften der Tabellenzeile analysieren und nicht nur das Icon, sondern auch das Linkziel lässt sich anpassen. Hier sind der Phantasie keine Grenzen gesetzt.
Das war's schon. Wie immer gilt: Es ist ganz einfach, wenn man weiß wie es geht! Wenn Sie Fragen oder Anregungen haben, hinterlassen Sie mir bitte einen Kommentar.
Kommentare