Publication Period Add-on

Taking in consideration the questions in created a new add-on that may help on the situations we need to set one or more collections entries only available in a particular day or period.

1 Like

One improvement:

use the collections.find.before event and extend the filter option


1 Like

Humm, not sure if got it, on the collections.find.before don’t have access to the collection entries!

you don’t have to, you extend the filter option to let the db do the filtering:

$app->on('collections.find.before', function ($name, &$options) use ($app) {

  // Get the collection.
  $collection = $this->module('collections')->collection($name);

  foreach ($collection['fields'] as $field) {

    if ($field['type'] == 'publicationperiod') {

      $name = $field['name'];

      $options['filter']['$or'] = [
         ["{$name}" => ['$exists' => false]],
         ["{$name}" => ''],
         ["{$name}" => ['$gte' => DATE, '$lte' => DATE]]


Ok, will check, it seems a clever way

I tried this today, but it doesn’t seem to be working. Whenever I use this field, the collections using the field don’t return any entry data. I’ve tried leaving it empty, using a date from the past, and selecting a past date with a future end date.

Any suggestions?

Are you using Mongodb or sqlite?

I’m currently using sqlite

Yep, for sqlite wasn’t working, should be ok now

Wow, thanks so much! I really appreciate your help!