mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
CMS action related extension points (#9340)
* CMS action related extension points * Refactor to use fewer extension points * Remove explicit return type Co-authored-by: Aaron Carlino <unclecheese@leftandmain.com>
This commit is contained in:
parent
53fcd47dfc
commit
9c38c5f625
@ -225,25 +225,26 @@ class FormRequestHandler extends RequestHandler
|
||||
|
||||
// First, try a handler method on the controller (has been checked for allowed_actions above already)
|
||||
$controller = $this->form->getController();
|
||||
$args = [$funcName, $request, $vars];
|
||||
if ($controller && $controller->hasMethod($funcName)) {
|
||||
$controller->setRequest($request);
|
||||
return $controller->$funcName($vars, $this->form, $request, $this);
|
||||
return $this->invokeFormHandler($controller, ...$args);
|
||||
}
|
||||
|
||||
// Otherwise, try a handler method on the form request handler.
|
||||
if ($this->hasMethod($funcName)) {
|
||||
return $this->$funcName($vars, $this->form, $request, $this);
|
||||
return $this->invokeFormHandler($this, ...$args);
|
||||
}
|
||||
|
||||
// Otherwise, try a handler method on the form itself
|
||||
if ($this->form->hasMethod($funcName)) {
|
||||
return $this->form->$funcName($vars, $this->form, $request, $this);
|
||||
return $this->invokeFormHandler($this->form, ...$args);
|
||||
}
|
||||
|
||||
// Check for inline actions
|
||||
$field = $this->checkFieldsForAction($this->form->Fields(), $funcName);
|
||||
if ($field) {
|
||||
return $field->$funcName($vars, $this->form, $request, $this);
|
||||
return $this->invokeFormHandler($field, ...$args);
|
||||
}
|
||||
} catch (ValidationException $e) {
|
||||
// The ValdiationResult contains all the relevant metadata
|
||||
@ -515,4 +516,20 @@ class FormRequestHandler extends RequestHandler
|
||||
{
|
||||
return $this->form->forTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $subject
|
||||
* @param string $funcName
|
||||
* @param HTTPRequest $request
|
||||
* @param array $vars
|
||||
* @return mixed
|
||||
*/
|
||||
private function invokeFormHandler($subject, string $funcName, HTTPRequest $request, array $vars)
|
||||
{
|
||||
$this->extend('beforeCallFormHandler', $request, $funcName, $vars, $this->form, $subject);
|
||||
$result = $subject->$funcName($vars, $this->form, $request, $this);
|
||||
$this->extend('afterCallFormHandler', $request, $funcName, $vars, $this->form, $subject, $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -1133,7 +1133,11 @@ class GridField extends FormField
|
||||
}
|
||||
|
||||
try {
|
||||
$this->extend('beforeCallActionURLHandler', $request, $action);
|
||||
|
||||
$result = $component->$action($this, $request);
|
||||
|
||||
$this->extend('afterCallActionURLHandler', $request, $action, $result);
|
||||
} catch (HTTPResponse_Exception $responseException) {
|
||||
$result = $responseException->getResponse();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user