<?php
namespace Grav\Plugin;

use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;

class CacheOnSavePlugin extends Plugin
{
    public static function getSubscribedEvents(): array
    {
        return [
            'onFormProcessed' => ['onFormProcessed', 0],
        ];
    }

    public function onFormProcessed(Event $event): void
    {
        $form = $event['form'];
        if (!$form) {
            return;
        }
        if ($form->getName() === 'new-entry') {
            $this->grav['cache']->deleteAll();
        }
    }
}
