/**
  * Handles PRE_SAVE storage event
  *
  * @param StorageEvent $event
  */
 public function onPreSave(StorageEvent $event)
 {
     $contenttype = $event->getContentType();
     // record contenttype
     $record = $event->getContent();
     // record itself
     $created = $event->isCreate();
     // if record was created, updated or deleted, for more information see the page in the documentation
     // Do whatever you want with this data
     // See page in the documentation for a logging example
 }
Пример #2
0
 public function testIsCreate()
 {
     $app = $this->getApp();
     $content = new Content($app, 'pages');
     $content->setValue('id', 5);
     $event = new StorageEvent($content);
     $event->setArgument('create', true);
     $this->assertTrue($event->isCreate());
     $event->setArgument('create', false);
     $this->assertFalse($event->isCreate());
 }
Пример #3
0
 public function testSetup()
 {
     $app = $this->getApp();
     $content = new Content($app);
     $event = new StorageEvent($content);
     $this->assertEquals(null, $event->isCreate());
     $this->assertEquals($content, $event->getContent());
     $this->assertEquals(null, $event->getId());
     $this->assertEquals(null, $event->getContentType());
 }
 /**
  * Handles POST_SAVE storage event
  *
  * @param StorageEvent $event
  */
 public function onPostSave(StorageEvent $event)
 {
     $id = $event->getId();
     // record id
     $contenttype = $event->getContentType();
     // record contenttype
     $record = $event->getContent();
     // record itself
     $created = $event->isCreate();
     // if record was created, updated or deleted, for more information look here: https://docs.bolt.cm/extensions/essentials#adding-storage-events
 }
 /**
  * Handles PRE_SAVE storage event
  *
  * @param StorageEvent $event
  */
 public function onPreSave(StorageEvent $event)
 {
     // The ContentType of the record being saved
     $contenttype = $event->getContentType();
     // The record being saved
     $record = $event->getContent();
     // A flag to tell if the record was created, updated or deleted,
     // for more information see the page in the documentation
     $created = $event->isCreate();
     // Do whatever you want with this data
     // See page in the documentation for a logging example
 }
Пример #6
0
 /**
  * Post-save testing event.
  *
  * @param StorageEvent $event
  */
 public function eventPostSave(StorageEvent $event)
 {
     $contenttype = $event->getContentType();
     if ($contenttype === 'pages') {
         $repo = $this->app['storage']->getRepository($contenttype);
         $record = $event->getContent();
         $values = $record->serialize();
         if ($event->isCreate()) {
             // Add a unique paragraph to the end of the body
             $record->setBody($values['body'] . '<p>Snuck in to body during POST_SAVE on create: ' . date('Y-m-d H:i:s') . '</p>');
         } else {
             // Add a unique paragraph to the end of the body
             $record->setBody($values['body'] . '<p>Added to body during POST_SAVE on save: ' . date('Y-m-d H:i:s') . '</p>');
         }
         // Save the changes to the database
         $repo->save($record, true);
     }
 }