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:
parent
c8c544e427
commit
033023f6ef
4 changed files with 22 additions and 13 deletions
|
|
@ -22,6 +22,7 @@ tabs:
|
|||
label: Media de couverture
|
||||
type: files
|
||||
query: page.coverFiles
|
||||
text: "{{ file.coverLabel }}"
|
||||
multiple: false
|
||||
width: 1/2
|
||||
text:
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ tabs:
|
|||
cover:
|
||||
label: Image de couverture
|
||||
type: files
|
||||
query: page.coverFiles
|
||||
text: "{{ file.coverLabel }}"
|
||||
multiple: false
|
||||
width: 1/2
|
||||
introduction:
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
19
public/site/plugins/cover-files/index.php
Normal file
19
public/site/plugins/cover-files/index.php
Normal 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();
|
||||
}
|
||||
]
|
||||
]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue