Skip to content

Commit

Permalink
Fix modules in site
Browse files Browse the repository at this point in the history
  • Loading branch information
medienbaecker committed May 15, 2023
1 parent 5b43b01 commit 404ae15
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 1 addition & 5 deletions lib/fields/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
return [
'computed' => [
'redirect' => function () {
if ($this->model()->isHomePage()) {
return $this->model()->site()->panel()->url();
} else {
return $this->model()->parent()->panel()->url();
}
return $this->model()->parents()->count() > 0 ? $this->model()->parents()->first()->panel()->url() : $this->model()->site()->panel()->url();
}
]
];
15 changes: 9 additions & 6 deletions lib/models.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ public static function create(array $props) {
}
return parent::create($props);
}
public function parentUrl(): string {
return $this->parents()->count() > 0 ? $this->parents()->first()->url() : $this->site()->url();
}
public function url($options = null): string {
return $this->parents()->filterBy('intendedTemplate', '!=', 'modules')->first()->url() . '#' . $this->slug();
return $this->parentUrl() . '#' . $this->slug();
}
public function render(array $data = [], $contentType = 'html'): string {
go($this->parents()->filterBy('intendedTemplate', '!=', 'modules')->first()->url() . '#' . $this->slug());
go($this->parentUrl() . '#' . $this->slug());
}
public function renderModule() {
$moduleTemplate = new Template($this->intendedTemplate());
echo $moduleTemplate->render([
'page' => $this->parent()->parent(),
'page' => $this->parents()->first() ?? $this->site(),
'module' => $this,
'site' => $this->site()
]);
Expand All @@ -29,17 +32,17 @@ public function moduleName() {
public function moduleId() {
return str_replace('.', '__', $this->intendedTemplate());
}
public function parents(){
public function parents() {
$parents = parent::parents();
return $parents->filter('slug', '!=', 'modules');
}
}

class ModulesPage extends Page {
public function url($options = null): string {
return $this->parent()->url();
return $this->parentUrl();
}
public function render(array $data = [], $contentType = 'html'): string {
go($this->parent()->url());
go($this->parentUrl());
}
}
3 changes: 2 additions & 1 deletion lib/sections/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
},
'image' => false,
'parent' => function ($parent = null) {
return $this->model()->find('modules') ? 'page.find("modules")' : $parent;
$class = get_class($this->model()) === 'Kirby\Cms\Site' ? 'site' : 'page';
return $this->model()->find('modules') ? $class . '.find("modules")' : $parent;
},
'layout' => function (string $layout = 'list') {
$layouts = ['list', 'cardlets', 'cards', 'table', 'module'];
Expand Down

0 comments on commit 404ae15

Please sign in to comment.