Add a created and updated date field blueprint and a hook that automatically updates the updated date when saving a page.
This commit is contained in:
19
blueprints/fields/dates.yml
Normal file
19
blueprints/fields/dates.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
type: fields
|
||||||
|
|
||||||
|
fields:
|
||||||
|
created:
|
||||||
|
label: Created
|
||||||
|
type: date
|
||||||
|
default: now
|
||||||
|
required: true
|
||||||
|
time:
|
||||||
|
notation: 12
|
||||||
|
step: 1
|
||||||
|
updated:
|
||||||
|
label: Updated
|
||||||
|
type: date
|
||||||
|
default: now
|
||||||
|
required: true
|
||||||
|
time:
|
||||||
|
notation: 12
|
||||||
|
step: 1
|
||||||
@@ -24,6 +24,7 @@ Kirby::plugin(
|
|||||||
"blueprints" => [
|
"blueprints" => [
|
||||||
"fields/link-locations" => __DIR__ . "/blueprints/fields/link-locations.yml",
|
"fields/link-locations" => __DIR__ . "/blueprints/fields/link-locations.yml",
|
||||||
"fields/link-location" => __DIR__ . "/blueprints/fields/link-location.yml",
|
"fields/link-location" => __DIR__ . "/blueprints/fields/link-location.yml",
|
||||||
|
"fields/dates" => __DIR__ . "/blueprints/fields/dates.yml",
|
||||||
],
|
],
|
||||||
"snippets" => [
|
"snippets" => [
|
||||||
"navbar/primary" => __DIR__ . "/snippets/navbar/primary.php",
|
"navbar/primary" => __DIR__ . "/snippets/navbar/primary.php",
|
||||||
@@ -114,6 +115,14 @@ Kirby::plugin(
|
|||||||
|
|
||||||
return $links;
|
return $links;
|
||||||
},
|
},
|
||||||
|
"page.update:after" => function ($newPage, $oldPage) {
|
||||||
|
if ($newPage->updated()->exists()) {
|
||||||
|
# Set the last updated time to now.
|
||||||
|
$newPage->update([
|
||||||
|
"updated" => date("Y-m-d H:i"),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
},
|
||||||
],
|
],
|
||||||
"siteMethods" => [
|
"siteMethods" => [
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user