-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow listening to form submissions via events and webhooks
requires Nextcloud 30 Signed-off-by: Marcel Klehr <[email protected]>
- Loading branch information
1 parent
3a85a74
commit eab4d7d
Showing
5 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace OCA\Forms\Events; | ||
|
||
use OCA\Forms\Db\Form; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IWebhookCompatibleEvent; | ||
|
||
if (interface_exists(\OCP\EventDispatcher\IWebhookCompatibleEvent::class)) { | ||
abstract class AbstractFormEvent extends Event implements IWebhookCompatibleEvent { | ||
public function __construct( | ||
protected Form $form, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function getForm(): Form { | ||
return $this->form; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getWebhookSerializable(): array { | ||
return $this->form->read(); | ||
} | ||
} | ||
|
||
} else { | ||
// need this block as long as NC < 30 is supported | ||
abstract class AbstractFormEvent extends Event { | ||
public function __construct( | ||
protected Form $form, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function getForm(): Form { | ||
return $this->form; | ||
} | ||
|
||
public function getWebhookSerializable(): array { | ||
return $this->form->read(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace OCA\Forms\Events; | ||
|
||
use OCA\Forms\Db\Form; | ||
use OCA\Forms\Db\Submission; | ||
use OCP\EventDispatcher\IWebhookCompatibleEvent; | ||
|
||
class FormSubmittedEvent extends AbstractFormEvent { | ||
public function __construct( | ||
Form $form, | ||
private Submission $submission, | ||
) { | ||
parent::__construct($form); | ||
} | ||
|
||
public function getWebhookSerializable(): array { | ||
return [ | ||
'form' => $this->form->read(), | ||
'submission' => $this->submission->read(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters