refactor: move coverFiles to plugin as page/file methods

Replace GeoformatPage model with a plugin registering coverFiles as a
pageMethod (available on all pages) and coverLabel as a fileMethod to
display "Carte [title]" for map children files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2026-02-26 11:28:10 +01:00
parent c8c544e427
commit 033023f6ef
4 changed files with 22 additions and 13 deletions

View file

@ -22,6 +22,7 @@ tabs:
label: Media de couverture
type: files
query: page.coverFiles
text: "{{ file.coverLabel }}"
multiple: false
width: 1/2
text:

View file

@ -18,6 +18,8 @@ tabs:
cover:
label: Image de couverture
type: files
query: page.coverFiles
text: "{{ file.coverLabel }}"
multiple: false
width: 1/2
introduction:

View file

@ -1,13 +0,0 @@
<?php
use Kirby\Cms\Page;
class GeoformatPage extends Page
{
public function coverFiles()
{
return $this->files()->add(
$this->children()->filterBy('intendedTemplate', 'map')->files()
);
}
}

View file

@ -0,0 +1,19 @@
<?php
Kirby::plugin('geoproject/cover-files', [
'pageMethods' => [
'coverFiles' => function () {
return $this->files()->add(
$this->children()->filterBy('intendedTemplate', 'map')->files()
);
}
],
'fileMethods' => [
'coverLabel' => function () {
if ($this->parent()->intendedTemplate()->name() === 'map') {
return 'Carte ' . $this->parent()->title();
}
return $this->filename();
}
]
]);