Skip to content

Commit

Permalink
Support auto_item attribute in UrlParameterBag (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi authored May 8, 2023
1 parent 5a9b89c commit 034f83f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CalendarNavigationListener extends AbstractNavigationListener
{
protected function getUrlKey(): string
{
return 'events';
return isset($GLOBALS['TL_CONFIG']['useAutoItem']) ? 'events' : 'auto_item';
}

protected function findCurrent(): ?CalendarEventsModel
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/Navigation/FaqNavigationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FaqNavigationListener extends AbstractNavigationListener
{
protected function getUrlKey(): string
{
return 'items';
return isset($GLOBALS['TL_CONFIG']['useAutoItem']) ? 'items' : 'auto_item';
}

protected function findCurrent(): ?FaqModel
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/Navigation/NewsNavigationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NewsNavigationListener extends AbstractNavigationListener
{
protected function getUrlKey(): string
{
return 'items';
return isset($GLOBALS['TL_CONFIG']['useAutoItem']) ? 'items' : 'auto_item';
}

protected function findCurrent(): ?NewsModel
Expand Down
13 changes: 2 additions & 11 deletions src/Navigation/UrlParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,8 @@ public function generateParameters(): ?string
return null;
}

if (isset($attributes['auto_item'])) {
throw new \RuntimeException('Do not set auto_item parameter');
}

// Contao 5 always uses auto_item
if (!\array_key_exists('useAutoItem', $GLOBALS['TL_CONFIG'])) {
$key = key($attributes);
$auto_item = $attributes[$key];
unset($attributes[$key]);
} elseif ($GLOBALS['TL_CONFIG']['useAutoItem']) {
$auto_item = array_intersect_key($attributes, array_flip((array) ($GLOBALS['TL_AUTO_ITEM'] ?? [])));
if ($GLOBALS['TL_CONFIG']['useAutoItem'] ?? true) {
$auto_item = array_intersect_key($attributes, array_flip(array_merge((array) ($GLOBALS['TL_AUTO_ITEM'] ?? []), ['auto_item'])));

switch (\count($auto_item)) {
case 0:
Expand Down

0 comments on commit 034f83f

Please sign in to comment.