bvdputte / kirby-autopublish

Kirby plugin to schedule the automatic publishing of pages on a certain date+time. Built to work with enabled cache.
MIT License
33 stars 6 forks source link

feat: add optional toggle to en- or disable the date fields #9

Closed gearsdigital closed 2 years ago

gearsdigital commented 3 years ago

This MR closes #7 by adding an optional toggle field which allows to enable (or disable) the date fields. It utilizes the Conditional Field feature which was introduced with Kirby 3.1.0.

Bildschirmfoto 2021-11-15 um 09 42 31 Bildschirmfoto 2021-11-15 um 09 42 37

I adapted the filter callback a bit and added a condition to check wether a toogle exists or not.

If the toogle doesn't exist, the original behaviour is unchanged. If the toogle exist, the value ('true' or false) of that toogle is evaluated. If the value is true (enabled), the original behaviour kicks in If the value is false (disabled), the filter is unchanged

You can use it in blueprints like so:

fields:
  autopublishtoggle:
    type: toggle
    label: Autopublish
    text:
      - Disabled
      - Enabled
  autopublish:
    label: Publish on
    type: date
    time: true
    default: now
    when:
      autopublishtoggle: true
  autounpublishtoggle:
    type: toggle
    label: Autounpublish
    text:
      - Disabled
      - Enabled
  autounpublish:
    label: Unpublish on
    type: date
    time: true
    when:
      autounpublishtoggle: true

The actual field names are configurable by setting the proper option in /site/config.php

'fieldNameToggle' => 'autopublishtoggle',
'fieldNameUnpublishToggle' => 'autounpublishtoggle'