Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add beforeRecordTransaction event that can prepend validation #194

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion php-classes/RecordsRequestHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ public static function handleMultiSaveRequest()

// try to save record
try {
// TODO: throw record validation exception if $Record->validationErrors is pre-populated

// call template function
static::onBeforeRecordSaved($Record, $datum);

Expand Down Expand Up @@ -581,12 +583,20 @@ public static function handleEditRequest(ActiveRecord $Record)
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// apply delta
static::applyRecordDelta($Record, $_REQUEST);

// fire event
Emergence\EventBus::fireEvent('beforeRecordTransaction', $className::getRootClass(), array(
'Record' => $Record,
'data' => $_REQUEST
));

// call template function
static::onBeforeRecordValidated($Record, $_REQUEST);

// validate
if ($Record->validate()) {
if (!empty($transactionErrors)) {
$Record->addValidationErrors($transactionErrors);
} elseif (!count($Record->validationErrors) && $Record->validate()) {
// call template function
static::onBeforeRecordSaved($Record, $_REQUEST);

Expand Down