How to customize
iskrisis opened this issue · 2 comments
Writing this down for anyone who shows up here. There are probably two things you will want to customise.
- worker.php - the default worker works only in the most basic situation. You need to change it if you have any kind of special folder setup. Instead of editing worker.php i advise you to copy it somewhere outside of plugin and call it from there because it would be overwritten otherwise next time you update.
It doesn't matter where the file is but you need to require kirby/bootstrap.php
this will load Kirby/project claases. Then create instance of kirby and set 'kirby', 'content' and 'site' roots. Something like so:
<?php
use bvdputte\kirbyAutopublish\Autopublish;
$projectRoot = dirname(__DIR__) . '/../../';
require $projectRoot . 'kirby/bootstrap.php';
// Instantiate Kirby
$kirby = new Kirby([
'options' => [
'debug' => true,
],
'roots' => [
'kirby' => $projectRoot . 'kirby',
'content' => $projectRoot. 'content',
'site' => $projectRoot. 'site',
],
]);
// Work the queue
Autopublish::publish();
exit();
- autoPublishedDrafts collection - this is the main collection that searches for not published fields that need to be published. It's implemented like so
'autoPublishedDrafts' => function ($site) {
$autopublishfield = option("bvdputte.kirbyAutopublish.fieldName");
$drafts = $site->pages()->drafts();
$autoPublishedDrafts = $drafts->filter(function ($draft) use ($autopublishfield) {
return ($draft->$autopublishfield()->exists()) && (!$draft->$autopublishfield()->isEmpty());
});
return $autoPublishedDrafts;
}
This has one limiation it looks only in $drafts = $site->pages()->drafts();
pages() mean first level pages. I would expect this to be $drafts = $site->index()->drafts();
so it checks every page on site but it might be whatever you need. Again instead of editing kirby-autopublish/index.php
you can crate site/collections/autoPublishedDrafts.php
and change your logic there.
Thanks for the explanation.
Do you also know how to use just a toggle instead of a separate date field? I would like to continue using my default date fields and have an additional toggle for autopublishing.
bvdputte.kirbyAutopublish.fieldName => 'date' doesn't seem to work for me.
And I would also like to use it for unlisted pages.