Blueprint Date K2 Override Behavior

How can I replicate the Kirby 2 behavior for the date picker where it could “override” on save.

I really liked having a “last updated” field that captured when the page was last updated, but it doesn’t seem like this feature was carried over into Kirby 3.

1 Like

Yes, right, there’s no such option anymore.

Possible solutions:

  • your own data field
  • a hook that updates the page on save.

What would be the proper way of doing it?

I am doing this and it’s working:

// hook within a plugin
'hooks' => [
  'page.update:after' => function ( $page ) {

    if( $page->last_updated()->exists() ){
      $page->update([
        'last_updated' => date( 'Y-m-d H:i' )
      ]);
    }

  }
]

Is that all, or is there something missing?

@moritzebeling That’s all there is to it. I’d make this field readonly (or hide it), so the user doesn’t try to interact with it.

1 Like

Thank you!
Exactly. That’s how my field looks:

last_updated:
  label: Last updated on
  type: date
  translate: false
  disabled: true
  empty: Date on which this page was last updated
  time: true
  step: 1