{"id":1589,"date":"2023-06-22T17:45:41","date_gmt":"2023-06-22T08:45:41","guid":{"rendered":"https:\/\/www.weschkalnies.de\/blog\/?p=1589"},"modified":"2024-04-11T19:08:03","modified_gmt":"2024-04-11T10:08:03","slug":"contao-4-13-table-toggle","status":"publish","type":"post","link":"https:\/\/www.weschkalnies.de\/blog\/contao-4-13-table-toggle\/","title":{"rendered":"Contao 4.13 &#8211; Table &#8211; Toggle"},"content":{"rendered":"<p>Ab Contao 4.13 lassen sich in DC Table eine Toogle-Funktion f\u00fcr die Listenelemente integrieren, so dass man also Listenelemente aktivieren bzw. deaktivieren kann.<br \/>\nLeider ist nicht besonders gut dokumentiert und ich habe selbst ein paar Stunden damit verbracht die L\u00f6sung dann f\u00fcr ein eigenes Contao-Modul zu integrieren.<br \/>\n<!--more--><\/p>\n<p>Hier die L\u00f6sung:<\/p>\n<p>1. Man integriert in den DCA ein neues Feld &#8218;published&#8216;:<br \/>\n<code><br \/>\n'published' =&gt; [<br \/>\n'label' =&gt; ['Ver\u00f6ffentlicht', 'Ver\u00f6ffentlicht'],<br \/>\n'inputType' =&gt; 'checkbox',<br \/>\n'toggle' =&gt; true,<br \/>\n'eval'      =&gt; array('tl_class' =&gt; 'clr'),<br \/>\n'sql' =&gt; [<br \/>\n'type' =&gt; 'boolean',<br \/>\n'default' =&gt; true,<br \/>\n],<br \/>\n],<br \/>\n<\/code><\/p>\n<p>Wichtig ist hier das man die Eigenschaft &#8218;toggle&#8216; auf &#8218;true&#8216; setzt.<\/p>\n<p>2. Man definiert im DCA eine neue Operation, wie folgt:<br \/>\n<code><br \/>\n'operations'        =&gt; array(<br \/>\n...<br \/>\n'toggle' =&gt; array<br \/>\n(<br \/>\n'href'                =&gt; 'act=toggle&amp;field=published',<br \/>\n'icon'                =&gt; 'visible.svg',<br \/>\n'button_callback'     =&gt; array('tl_jobs', 'toggleIcon')<br \/>\n),<br \/>\n)<br \/>\n<\/code><\/p>\n<p>3. Man definiert im DCA eine neue Methode toggleIcon, wie folgt:<br \/>\n<code><br \/>\npublic function toggleIcon($row, $href, $label, $title, $icon, $attributes) {<\/p>\n<p>$href .= '&amp;id=' . $row['id'];<\/p>\n<p>if (!$row['published']) {<br \/>\n$icon = 'invisible.svg';<br \/>\n}<\/p>\n<p>return '<a title=\"' . StringUtil::specialchars($title) . '\" href=\"' . $this-&gt;addToUrl($href) . '\">' . Image::getHtml($icon, $label, 'data-icon=\"' . Image::getPath('visible.svg') . '\" data-icon-disabled=\"' . Image::getPath('invisible.svg') . '\" data-state=\"' . ($row['published'] ? 1 : 0) . '\"') . '<\/a> ';<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Dann nat\u00fcrlich die Datenbank aktualisieren und System-Cache erneuern. Das wars.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ab Contao 4.13 lassen sich in DC Table eine Toogle-Funktion f\u00fcr die Listenelemente integrieren, so dass man also Listenelemente aktivieren bzw. deaktivieren kann. Leider ist nicht besonders gut&#8230;<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[35,120],"class_list":["post-1589","post","type-post","status-publish","format-standard","hentry","category-contao","tag-contao-2","tag-toggle"],"_links":{"self":[{"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/posts\/1589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/comments?post=1589"}],"version-history":[{"count":3,"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/posts\/1589\/revisions"}],"predecessor-version":[{"id":1640,"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/posts\/1589\/revisions\/1640"}],"wp:attachment":[{"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/media?parent=1589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/categories?post=1589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weschkalnies.de\/blog\/wp-json\/wp\/v2\/tags?post=1589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}