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.


One improvement:

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



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