Contao fügt "_1" in Dateinamen ein, wieso?
Hallo,
ich hab mein Problem hier schon mal erwähnt, da ich mir aber nicht mehr sicher bin, ob es überhaupt etwas mit dem Problem des Threaderstellers zu tun hat, mach ich mal ein neues Thema auf.
Kurz noch mal die Situation: Ich habe "Angebote" und "Angebotskategorien". Diese sollen im Backend verwaltet werden. Zur Verwaltung der Angebote selbst verwende ich den Sorting Mode 6, d.h. die Angebote werden als Childs in einer Baumstruktur zusammen mit den Kategorien als Parents angezeigt, so wie bei der Artikelansicht. Zur Verwaltung der Kategorien verwende ich Sorting Mode 5, d.h. die Kategorien werden hier allein in einer Baumstruktur angezeigt, so wie bei der Seitenstruktur. (Ich verwende diese Sorting Modes eigentlich nur, weil ich die Cut/Paste-Funktion von Contao zum Verschieben der Items verwenden will, was wohl mit anderen Sorting Modes nicht geht...)
In beiden Ansichten habe ich ToggleVisibility-Buttons sowie ein label_callback, das dafür sorgen soll, dass je nach Sichtbarkeit eines Angebots bzw. einer Kategorie ein anderes Icon angezeigt wird ("dummyicon.gif" oder "dummyicon_.gif").
Das ganze funktioniert mit dem Sorting Mode 6 problemlos. Beim Sorting Mode 5 dagegen wird zwar beim Seitenaufruf das richtige Icon angezeigt, jedoch nicht mehr, wenn ich den Toggle-Button benutze, um die Sichtbarkeit zu ändern. Der Code unterscheidet sich nicht, d.h. der DCA beim Sorting Mode 6 sieht nicht viel anders aus als der für Sorting Mode 5, den ich unten einfach mal komplett einfüge.
Mir ist bei der Fehlersuche grade etwas sehr komisches aufgefallen, was wohl der Grund für das Problem ist. Und zwar habe ich im Quelltext nach Benutzen des Toggle-Buttons nicht "dummyicon.gif" bzw. "dummyicon_.gif" stehen, sondern "dummyicon_1.gif" bzw. "dummyicon__1.gif". An irgendeiner Stelle wird also ein "_1" in den Dateinamen eingebaut.
In der addIcon()-Methode wird im Grunde nur "Image::getHtml()" aufgerufen. Ich hab das debugged, innerhalb der Methode ist mein Dateinamen immer richtig. Es sieht so aus, dass Contao irgendwann später das "_1" in den Dateinamen einbaut. Ich steh völlig auf dem Schlauch. Kommt dieses Verhalten irgendwem bekannt vor, kann mir jemand einen Hinweis geben, woher das kommt oder gar, wie ich das abstellen kann?
Da alles funktioniert, wenn die Seite neu aufgebaut wird, und das Problem nur bei Verwenden des Toggle-Buttons auftritt, hat es eventuell etwas mit Ajax (wovon ich keine Ahnung habe) zu tun?
edit: ich verwende Contao 3.1
Tschö,
fluppi
PHP-Code:
<?php
$GLOBALS['TL_DCA']['tl_dk_company_offer_category'] = array
(
// Config
'config' => array
(
'dataContainer' => 'Table',
'label' => &$GLOBALS['TL_LANG']['MOD']['dk_company_offers'][0],
'ctable' => array('tl_dk_company_offer'),
'enableVersioning' => true,
'sql' => array
(
'keys' => array
(
'id' => 'primary'
)
),
),
// List
'list' => array
(
'sorting' => array
(
'mode' => 5,
'fields' => array('sorting'),
'flag' => 1,
'panelLayout' => 'search',
'paste_button_callback' => array('tl_dk_company_offer_category', 'pasteTag'),
),
'label' => array
(
'fields' => array('title'),
'format' => '%s',
'label_callback' => array('tl_dk_company_offer_category', 'addIcon')
),
'global_operations' => array
(
'offers' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['offers'],
'href' => 'table=tl_dk_company_offer',
'attributes' => 'onclick="Backend.getScrollOffset();"',
'icon' => 'system/modules/dk_company_offers/assets/dummyicon.gif'
)
),
'operations' => array
(
'edit' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['edit'],
'href' => 'act=edit',
'icon' => 'edit.gif',
'button_callback' => array('tl_dk_company_offer_category','deactivateButtonForDefaultCategoryButNotForAdmin'),
),
'copy' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['copy'],
'href' => 'act=copy',
'icon' => 'copy.gif',
'button_callback' => array('tl_dk_company_offer_category','deactivateButtonForDefaultCategory'),
),
'cut' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['cut'],
'href' => 'act=paste&mode=cut',
'icon' => 'cut.gif',
'button_callback' => array('tl_dk_company_offer_category','deactivateButtonForDefaultCategory'),
),
'delete' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['delete'],
'href' => 'act=delete',
'icon' => 'delete.gif',
'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['tl_dk_company_offer_category']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"',
'button_callback' => array('tl_dk_company_offer_category','deleteButtonCallback'),
),
'toggle' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['toggle'],
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'button_callback' => array('tl_dk_company_offer_category', 'toggleIcon')
),
'show' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['show'],
'href' => 'act=show',
'icon' => 'show.gif'
)
)
),
// Palettes
'palettes' => array
(
'__selector__' => array('addImage'),
'default' => '{title_legend},title,description;{image_legend},addImage;{publish_legend},published'
),
// Subpalettes
'subpalettes' => array
(
'addImage' => 'singleSRC'
),
// Fields
'fields' => array
(
'id' => array
(
'sql' => "int(10) unsigned NOT NULL auto_increment"
),
'pid' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'" // dummy-feld das für Mode 5 benötigt wird (s.o.)
),
'tstamp' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'sorting' => array
(
'label' => &$GLOBALS['TL_LANG']['MSC']['sorting'],
'flag' => 2,
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'title' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['title'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>255),
'sql' => "varchar(255) NOT NULL default ''"
),
'description' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['description'],
'exclude' => true,
'search' => true,
'inputType' => 'textarea',
'eval' => array('mandatory'=>true, 'maxlength'=>255),
'sql' => "varchar(255) NOT NULL default ''"
),
'addImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['addImage'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => array('submitOnChange'=>true),
'sql' => "char(1) NOT NULL default ''"
),
'singleSRC' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['singleSRC'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array('filesOnly'=>true, 'extensions'=>$GLOBALS['TL_CONFIG']['validImageTypes'], 'fieldType'=>'radio', 'mandatory'=>true),
'sql' => "varchar(255) NOT NULL default ''"
),
'published' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['published'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('doNotCopy'=>true),
'sql' => "char(1) NOT NULL default ''"
)
)
);
class tl_dk_company_offer_category extends Backend
{
public function __construct()
{
parent::__construct();
$this->import('BackendUser', 'User');
}
public function pasteTag(DataContainer $dc, $row, $table, $cr, $arrClipboard=false)
{
$this->import('BackendUser', 'User');
$imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id']));
if ($row['id'] == 0)
{
// direkt in die Hauptebene sollen keine Kategorien eingefügt werden, denn diese stünden
// dann oberhalb der Defaultkategorie
return '';
}
return (($arrClipboard['mode'] == 'cut' && $arrClipboard['id'] == $row['id']) || $cr) ? $this->generateImage('pasteafter_.gif').' ' : '<a href="'.$this->addToUrl('act='.$arrClipboard['mode'].'&mode=1&pid='.$row['id'].'&id='.$arrClipboard['id']).'" title="'.specialchars(sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id'])).'" onclick="Backend.getScrollOffset();">'.$imagePasteAfter.'</a> ';
}
public function deactivateButtonForDefaultCategory($row, $href, $label, $title, $icon, $attributes)
{
return ($row['id'] > 1 )? '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : '';
}
public function deactivateButtonForDefaultCategoryButNotForAdmin($row, $href, $label, $title, $icon, $attributes)
{
return ($this->User->isAdmin || $row['id'] > 1 )? '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : '';
}
public function deleteButtonCallback($row, $href, $label, $title, $icon, $attributes)
{
if ($row['id']<=1)
return '';
$result = $this->Database->prepare("SELECT count(1) AS count FROM tl_dk_company_offer WHERE pid=?")
->execute($row['id']);
return ($result->count == 0 )? '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : Image::getHtml(preg_replace('/\.gif$/i', '_.gif', $icon)).' ';
}
public function addIcon($row, $label, DataContainer $dc=null, $imageAttribute='', $blnReturnImage=false, $blnProtected=false)
{
return Image::getHtml('system/modules/dk_company_offers/assets/dummyicon'.($row['published'] ? '' : '_').'.gif').$label;
}
public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
{
// die Sichtbarkeit der Hauptkategorie kann nur vom Admin geändert werden:
if (!$this->User->isAdmin && $row['id'] <= 1 )
return '';
if (strlen(Input::get('tid')))
{
$this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1));
$this->redirect($this->getReferer());
}
// Check permissions AFTER checking the tid, so hacking attempts are logged
if (!$this->User->isAdmin && !$this->User->hasAccess('tl_dk_company_offer_category::published', 'alexf'))
{
return '';
}
$href .= '&tid='.$row['id'].'&state='.($row['published'] ? '' : 1);
if (!$row['published'])
{
$icon = 'invisible.gif';
}
return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ';
}
public function toggleVisibility($intId, $blnVisible)
{
// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_dk_company_offer_category']['fields']['published']['save_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_dk_company_offer_category']['fields']['published']['save_callback'] as $callback)
{
$this->import($callback[0]);
$blnVisible = $this->$callback[0]->$callback[1]($blnVisible, $this);
}
}
// Update the database
$this->Database->prepare("UPDATE tl_dk_company_offer_category SET tstamp=". time() .", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")
->execute($intId);
}
}
?>