Skip to content

Commit

Permalink
Fix bug with toggle operation
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Mar 23, 2023
1 parent b1233ac commit e6b31b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
34 changes: 2 additions & 32 deletions src/MegaMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,13 @@ class MegaMenu extends Backend
*/
public function toggleColumnIcon($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 column
*/
public function toggleVisibility($intId, $blnVisible)
{
$this->createInitialVersion('tl_rocksolid_mega_menu_column', $intId);

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

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

$this->createNewVersion('tl_rocksolid_mega_menu_column', $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> ';
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Resources/contao/dca/tl_rocksolid_mega_menu_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
),
'toggle' => array(
'label' => &$GLOBALS['TL_LANG']['tl_rocksolid_mega_menu_column']['toggle'],
'href' => 'act=toggle&amp;field=published',
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'button_callback' => array('MadeYourDay\\RockSolidMegaMenu\\MegaMenu', 'toggleColumnIcon'),
'button_callback' => array('MadeYourDay\\RockSolidSlider\\Slider', 'toggleSlideIcon'),
),
'show' => array(
'label' => &$GLOBALS['TL_LANG']['tl_rocksolid_mega_menu_column']['show'],
Expand Down Expand Up @@ -281,6 +281,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_rocksolid_mega_menu_column']['published'],
'exclude' => true,
'filter' => true,
'toggle' => true,
'flag' => 1,
'inputType' => 'checkbox',
'eval' => array('doNotCopy'=>true),
Expand Down

0 comments on commit e6b31b4

Please sign in to comment.