Skip to content

Commit

Permalink
Fix parsing listing views
Browse files Browse the repository at this point in the history
  • Loading branch information
billtomczak committed Jul 14, 2022
1 parent c1f3ccb commit 2ab8602
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/site/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,19 @@ public function __construct($app = null, $menu = null)
$router->attachParseRule([$this, 'parseProcessAfter'], Router::PROCESS_AFTER);
}

/**
* Allow to set custom segments for routes.
*
* @param string[] $segments
*/
protected function setCustomSegments(array $segments = [])
{
$params = ComponentHelper::getParams('com_osdownloads');

// Default values
$default = ['files' => $params->get('route_segment_files') ?: 'files'];

$this->customSegments = array_merge($default, $segments);
}

/**
* Get a list of custom segments.
*
* @return string[]
*/
protected function getCustomSegments(): array
{
if (!isset($this->customSegments)) {
$this->setCustomSegments();
if ($this->customSegments === null) {
$params = ComponentHelper::getParams('com_osdownloads');

$this->customSegments = [
'files' => $params->get('route_segment_files') ?: 'files'
];
}

return $this->customSegments;
Expand Down Expand Up @@ -482,10 +471,8 @@ public function parse(&$segments)
break;
}

if (
isset($this->customSegments['files'])
&& $this->customSegments['files'] === $lastSegment
) {
$listSegment = $this->getCustomSegments()['files'];
if ($listSegment === $lastSegment) {
$vars['view'] = 'downloads';

array_pop($segments);
Expand Down

0 comments on commit 2ab8602

Please sign in to comment.