-
Notifications
You must be signed in to change notification settings - Fork 0
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
NEW: Event-driven snapshot actions #3
NEW: Event-driven snapshot actions #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! I really like this event based approach :), the code looks more DRY as well. I found some issues and I have some suggestions.
*/ | ||
public function afterCallFormHandler (HTTPRequest $request, $funcName, $vars, $form): void | ||
{ | ||
Dispatcher::singleton()->trigger('formSubmitted', new FormContext($funcName, $form, $request, $vars)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dispatcher::singleton()->trigger('formSubmitted', new FormContext($funcName, $form, $request, $vars)); | |
$this->triggerAction($request, $funcName, $vars, $form); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is that method defined?
public function afterCallFormHandler (HTTPRequest $request, $funcName, $vars, $form): void | ||
{ | ||
Dispatcher::singleton()->trigger('formSubmitted', new FormContext($funcName, $form, $request, $vars)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
} | |
/** | |
* Extension point in @see FormRequestHandler::httpSubmission | |
* form handler action via form submission action | |
* | |
* @param HTTPRequest $request | |
* @param $funcName | |
* @param $vars | |
* @param Form $form | |
*/ | |
public function afterCallFormHandlerMethod(HTTPRequest $request, $funcName, $vars, $form): void | |
{ | |
$this->triggerAction($request, $funcName, $vars, $form); | |
} | |
/** | |
* Extension point in @see FormRequestHandler::httpSubmission | |
* form method action via form submission action | |
* | |
* @param HTTPRequest $request | |
* @param $funcName | |
* @param $vars | |
* @param Form $form | |
*/ | |
public function afterCallFormHandlerFormMethod(HTTPRequest $request, $funcName, $vars, $form): void | |
{ | |
$this->triggerAction($request, $funcName, $vars, $form); | |
} | |
/** | |
* Extension point in @see FormRequestHandler::httpSubmission | |
* form field method action via form submission action | |
* | |
* @param HTTPRequest $request | |
* @param $funcName | |
* @param $vars | |
* @param Form $form | |
*/ | |
public function afterCallFormHandlerFieldMethod(HTTPRequest $request, $funcName, $vars, $form): void | |
{ | |
$this->triggerAction($request, $funcName, $vars, $form); | |
} | |
/** | |
* @param HTTPRequest $request | |
* @param $funcName | |
* @param $vars | |
* @param Form $form | |
*/ | |
private function triggerAction(HTTPRequest $request, $funcName, $vars, $form): void | |
{ | |
Dispatcher::singleton()->trigger('formSubmitted', new FormContext($funcName, $form, $request, $vars)); | |
} |
This needs to cover all 4 extension points for Form submissions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the revision I made to that PR. I didn't think we needed four hooks. silverstripe/silverstripe-framework#9340
@unclecheese I have a test integration here which is helpful to cover all the test cases: |
71ff7e1
to
8a10e51
Compare
@unclecheese Thanks for the new fixes :). it seems to be working reasonably well now. I am now confident that all requirements from previous version were retained. I'm moving the development of this feature to the terraformers repo as this will allow more people to collaborate more easily. Feel free to continue providing awesome feedback / fixes. Here is the new PR: I added one more commit with some fixes: I also updated the TNZ integration branch which now supports almost all actions that were available previously. I recommend using this branch for testing out Snapshots features on a real project, it makes catching bugs much easier: |
Excellent. I was just working on testing it with TNZ, so this is great. |
I'll get working on the test suite to get this green, and cover the new API surface. |
Summary
This pull request makes a number of improvements to the public API for action-driven snapshot creation. While most of the core functionality around how snapshots are created in certain contexts is preserved, the execution path to get there, and the way a developer can customise and/or extend that pattern is improved using a more event-driven paradigm.
Problems addressed
if ($action === 'save')
Key solutions
Dispatcher
instance that fires events.HandlerInterface
)EventContext
objects that provide relevant event metadata.EventContext
objects must declare an action identifier (getAction(): string
)Complex computations around extracting action identifiers (e.g. from GridField state or GraphQL queries) is now the concern ofEventContext
classes.$action === 'save'
are done reactively with a custom event handler, e.g.formSubmitted.save
For discussion
The entire event API (everything in
Dispatch
andListener
) has no concerns about snapshots. Only the event handlers that create the snapshots do (everything inHandler
). I think it would make good sense to spin off the events into a separate module to maintain a nice separation of concerns and afford devs a chance to plug into reactive programming in the CMS without installing snapshots.