Skip to content

Commit

Permalink
Add support for backend jump targets in Contao 5.3 (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbableck authored Mar 8, 2024
1 parent 1787c64 commit 4e44465
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 25 deletions.
43 changes: 32 additions & 11 deletions src/Widget/GroupStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace MadeYourDay\RockSolidCustomElements\Widget;

use Contao\CoreBundle\ContaoCoreBundle;
use Contao\System;
use Contao\Widget;

Expand Down Expand Up @@ -47,16 +48,36 @@ public function generate()
$classes[] = 'collapsed';
}

return '</fieldset>'
. '<div class="clear"></div>'
. '<fieldset'
. ' id="pal_' . $this->strId . '"'
. ' class="' . implode(' ', $classes) . '"'
. '>'
. '<legend'
. ' onclick="AjaxRequest.toggleFieldset(this, &quot;' . $this->strId . '&quot;, &quot;' . $this->strTable . '&quot;)"'
. '>' . $this->strLabel
. '</legend>'
. ($this->description ? '<p class="rsce_group_description">' . $this->description . '</p>' : '');
if (version_compare(ContaoCoreBundle::getVersion(), '5.3', '>=')) {
return '</fieldset>'
. '<div class="clear"></div>'
. '<fieldset'
. ' id="pal_' . $this->strId . '"'
. ' class="' . implode(' ', $classes) . '"'
. ' data-controller="contao--toggle-fieldset" data-contao--toggle-fieldset-id-value="pal_' . $this->strId . '"'
. ' data-contao--toggle-fieldset-table-value="' . $this->strTable . '"'
. ' data-contao--toggle-fieldset-collapsed-class="collapsed"'
. ' data-contao--jump-targets-target="section"'
. ' data-contao--jump-targets-label-value="' . $this->strLabel . '"'
. ' data-action="contao--jump-targets:scrollto->contao--toggle-fieldset#open"'
. '>'
. '<legend'
. ' data-action="click->contao--toggle-fieldset#toggle"'
. '>' . $this->strLabel
. '</legend>'
. ($this->description ? '<p class="rsce_group_description">' . $this->description . '</p>' : '');
} else {
return '</fieldset>'
. '<div class="clear"></div>'
. '<fieldset'
. ' id="pal_' . $this->strId . '"'
. ' class="' . implode(' ', $classes) . '"'
. '>'
. '<legend'
. ' onclick="AjaxRequest.toggleFieldset(this, &quot;' . $this->strId . '&quot;, &quot;' . $this->strTable . '&quot;)"'
. '>' . $this->strLabel
. '</legend>'
. ($this->description ? '<p class="rsce_group_description">' . $this->description . '</p>' : '');
}
}
}
52 changes: 38 additions & 14 deletions src/Widget/ListStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace MadeYourDay\RockSolidCustomElements\Widget;

use Contao\CoreBundle\ContaoCoreBundle;
use Contao\System;
use Contao\Widget;

Expand Down Expand Up @@ -56,19 +57,42 @@ public function generate()
'maxItems' => $this->maxItems,
);

return '</fieldset>'
. '<div class="clear"></div>'
. '<fieldset'
. ' id="pal_' . $this->strId . '"'
. ' class="' . implode(' ', $classes) . '"'
. ' data-config="' . htmlspecialchars(json_encode($config), ENT_QUOTES) . '"'
. $this->getAttributes()
. '>'
. '<legend'
. ' onclick="AjaxRequest.toggleFieldset(this, &quot;' . $this->strId . '&quot;, &quot;' . $this->strTable . '&quot;)"'
. '>' . $this->strLabel
. '</legend>'
. $toolbar
. ($this->description ? '<p class="rsce_list_description">' . $this->description . '</p>' : '');
if (version_compare(ContaoCoreBundle::getVersion(), '5.3', '>=')) {
return '</fieldset>'
. '<div class="clear"></div>'
. '<fieldset'
. ' id="pal_' . $this->strId . '"'
. ' class="' . implode(' ', $classes) . '"'
. ' data-controller="contao--toggle-fieldset" data-contao--toggle-fieldset-id-value="pal_' . $this->strId . '"'
. ' data-contao--toggle-fieldset-table-value="' . $this->strTable . '"'
. ' data-contao--toggle-fieldset-collapsed-class="collapsed"'
. ' data-contao--jump-targets-target="section"'
. ' data-contao--jump-targets-label-value="' . $this->strLabel . '"'
. ' data-action="contao--jump-targets:scrollto->contao--toggle-fieldset#open"'
. ' data-config="' . htmlspecialchars(json_encode($config), ENT_QUOTES) . '"'
. $this->getAttributes()
. '>'
. '<legend'
. ' data-action="click->contao--toggle-fieldset#toggle"'
. '>' . $this->strLabel
. '</legend>'
. $toolbar
. ($this->description ? '<p class="rsce_list_description">' . $this->description . '</p>' : '');
} else {
return '</fieldset>'
. '<div class="clear"></div>'
. '<fieldset'
. ' id="pal_' . $this->strId . '"'
. ' class="' . implode(' ', $classes) . '"'
. ' data-config="' . htmlspecialchars(json_encode($config), ENT_QUOTES) . '"'
. $this->getAttributes()
. '>'
. '<legend'
. ' onclick="AjaxRequest.toggleFieldset(this, &quot;' . $this->strId . '&quot;, &quot;' . $this->strTable . '&quot;)"'
. '>' . $this->strLabel
. '</legend>'
. $toolbar
. ($this->description ? '<p class="rsce_list_description">' . $this->description . '</p>' : '');
}
}
}

0 comments on commit 4e44465

Please sign in to comment.