Skip to content

Commit

Permalink
Fix bug with toggle operation, #83
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Mar 23, 2023
1 parent 17401d2 commit 904d115
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/Resources/contao/dca/tl_rocksolid_slide.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
),
'toggle' => array(
'label' => &$GLOBALS['TL_LANG']['tl_rocksolid_slide']['toggle'],
'href' => 'act=toggle&field=published',
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'button_callback' => array('MadeYourDay\\RockSolidSlider\\Slider', 'toggleSlideIcon'),
),
'show' => array(
Expand Down Expand Up @@ -415,6 +415,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_rocksolid_slide']['published'],
'exclude' => true,
'filter' => true,
'toggle' => true,
'flag' => 1,
'inputType' => 'checkbox',
'eval' => array('doNotCopy'=>true),
Expand Down
34 changes: 2 additions & 32 deletions src/Slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,13 @@ class Slider extends Backend
*/
public function toggleSlideIcon($row, $href, $label, $title, $icon, $attributes)
{
if (strlen(Input::get('tid'))) {
$this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1));
if (Environment::get('isAjaxRequest')) {
exit;
}
$this->redirect($this->getReferer());
}

$href .= '&id=' . Input::get('id') . '&tid=' . $row['id'] . '&state=' . ($row['published'] ? '' : 1);
$href .= '&id=' . $row['id'];

if (! $row['published']) {
$icon = 'invisible.gif';
}

return '<a href="' . $this->addToUrl($href) . '" title="' . StringUtil::specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label) . '</a> ';
}

/**
* Disable/enable a slide
*/
public function toggleVisibility($intId, $blnVisible)
{
$this->createInitialVersion('tl_rocksolid_slide', $intId);

// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_rocksolid_slide']['fields']['published']['save_callback'] ?? null)) {
foreach ($GLOBALS['TL_DCA']['tl_rocksolid_slide']['fields']['published']['save_callback'] as $callback) {
$this->import($callback[0]);
$blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $this);
}
}

$this->Database
->prepare("UPDATE tl_rocksolid_slide SET tstamp=". time() .", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")
->execute($intId);

$this->createNewVersion('tl_rocksolid_slide', $intId);
return '<a href="' . $this->addToUrl($href) . '" title="' . StringUtil::specialchars($title) . '" onclick="Backend.getScrollOffset();return AjaxRequest.toggleField(this,true)">' . Image::getHtml($icon, $label, 'data-icon="' . Image::getPath('visible.svg') . '" data-icon-disabled="' . Image::getPath('invisible.svg') . '" data-state="' . ($row['published'] ? 1 : 0) . '"') . '</a> ';
}

public function sliderLicenseButton($href, $label, $title, $class, $attributes)
Expand Down

0 comments on commit 904d115

Please sign in to comment.