From 386ef27f655d4470d6f74f2d10b0017be409f104 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 23 Mar 2018 15:28:00 +1300 Subject: [PATCH] Update requesthandlers with missing extension points --- src/Forms/FormField.php | 4 +++- src/Forms/FormRequestHandler.php | 14 ++++++------ .../ChangePasswordHandler.php | 22 +++++++++---------- .../MemberAuthenticator/LoginHandler.php | 19 ++++++++-------- .../LostPasswordHandler.php | 21 ++++++++++-------- src/Security/Security.php | 4 +++- 6 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/Forms/FormField.php b/src/Forms/FormField.php index 0c9108fcd..8b6c3a571 100644 --- a/src/Forms/FormField.php +++ b/src/Forms/FormField.php @@ -363,7 +363,9 @@ class FormField extends RequestHandler */ public function Link($action = null) { - return Controller::join_links($this->form->FormAction(), 'field/' . $this->name, $action); + $link = Controller::join_links($this->form->FormAction(), 'field/' . $this->name, $action); + $this->extend('updateLink', $link, $action); + return $link; } /** diff --git a/src/Forms/FormRequestHandler.php b/src/Forms/FormRequestHandler.php index 0244a11f5..408f57d77 100644 --- a/src/Forms/FormRequestHandler.php +++ b/src/Forms/FormRequestHandler.php @@ -85,15 +85,15 @@ class FormRequestHandler extends RequestHandler // Respect FormObjectLink() method if ($controller->hasMethod("FormObjectLink")) { - return Controller::join_links( - $controller->FormObjectLink($this->form->getName()), - $action, - '/' - ); + $base = $controller->FormObjectLink($this->form->getName()); + } else { + $base = Controller::join_links($controller->Link(), $this->form->getName()); } - // Default form link - return Controller::join_links($controller->Link(), $this->form->getName(), $action, '/'); + // Join with action and decorate + $link = Controller::join_links($base, $action, '/'); + $this->extend('updateLink', $link, $action); + return $link; } /** diff --git a/src/Security/MemberAuthenticator/ChangePasswordHandler.php b/src/Security/MemberAuthenticator/ChangePasswordHandler.php index 3149f3404..74cc528fe 100644 --- a/src/Security/MemberAuthenticator/ChangePasswordHandler.php +++ b/src/Security/MemberAuthenticator/ChangePasswordHandler.php @@ -7,7 +7,6 @@ use Psr\Container\NotFoundExceptionInterface; use SilverStripe\Control\Controller; use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\RequestHandler; -use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBField; @@ -25,9 +24,11 @@ class ChangePasswordHandler extends RequestHandler protected $authenticator; /** + * Link to this handler + * * @var string */ - protected $link; + protected $link = null; /** * @var array Allowed Actions @@ -123,8 +124,8 @@ class ChangePasswordHandler extends RequestHandler . '

You can request a new one here or change your password after' . ' you logged in.

', [ - 'link1' => $this->link('lostpassword'), - 'link2' => $this->link('login') + 'link1' => $this->Link('lostpassword'), + 'link2' => $this->Link('login') ] ) ); @@ -164,16 +165,15 @@ class ChangePasswordHandler extends RequestHandler /** * Return a link to this request handler. * The link returned is supplied in the constructor - * @param null $action + * + * @param string|null $action * @return string */ - public function link($action = null) + public function Link($action = null) { - if ($action) { - return Controller::join_links($this->link, $action); - } - - return $this->link; + $link = Controller::join_links($this->link, $action); + $this->extend('updateLink', $link, $action); + return $link; } /** diff --git a/src/Security/MemberAuthenticator/LoginHandler.php b/src/Security/MemberAuthenticator/LoginHandler.php index 2058c7864..f97538810 100644 --- a/src/Security/MemberAuthenticator/LoginHandler.php +++ b/src/Security/MemberAuthenticator/LoginHandler.php @@ -41,9 +41,11 @@ class LoginHandler extends RequestHandler ]; /** - * @var string Called link on this handler + * Link to this handler + * + * @var string */ - private $link; + protected $link = null; /** * @param string $link The URL to recreate this request handler @@ -59,16 +61,15 @@ class LoginHandler extends RequestHandler /** * Return a link to this request handler. * The link returned is supplied in the constructor + * * @param null|string $action * @return string */ - public function link($action = null) + public function Link($action = null) { - if ($action) { - return Controller::join_links($this->link, $action); - } - - return $this->link; + $link = Controller::join_links($this->link, $action); + $this->extend('updateLink', $link, $action); + return $link; } /** @@ -152,7 +153,7 @@ class LoginHandler extends RequestHandler public function getReturnReferer() { - return $this->link(); + return $this->Link(); } /** diff --git a/src/Security/MemberAuthenticator/LostPasswordHandler.php b/src/Security/MemberAuthenticator/LostPasswordHandler.php index d5d4b4e22..5086e525c 100644 --- a/src/Security/MemberAuthenticator/LostPasswordHandler.php +++ b/src/Security/MemberAuthenticator/LostPasswordHandler.php @@ -44,7 +44,12 @@ class LostPasswordHandler extends RequestHandler 'passwordsent', ]; - private $link = null; + /** + * Link to this handler + * + * @var string + */ + protected $link = null; /** * @param string $link The URL to recreate this request handler @@ -59,16 +64,14 @@ class LostPasswordHandler extends RequestHandler * Return a link to this request handler. * The link returned is supplied in the constructor * - * @param string $action + * @param string|null $action * @return string */ - public function link($action = null) + public function Link($action = null) { - if ($action) { - return Controller::join_links($this->link, $action); - } - - return $this->link; + $link = Controller::join_links($this->link, $action); + $this->extend('updateLink', $link, $action); + return $link; } /** @@ -261,7 +264,7 @@ class LostPasswordHandler extends RequestHandler protected function redirectToSuccess(array $data) { $link = Controller::join_links( - $this->link('passwordsent'), + $this->Link('passwordsent'), rawurlencode($data['Email']), '/' ); diff --git a/src/Security/Security.php b/src/Security/Security.php index 675ff0ba0..e3952c056 100644 --- a/src/Security/Security.php +++ b/src/Security/Security.php @@ -483,7 +483,9 @@ class Security extends Controller implements TemplateGlobalProvider public function Link($action = null) { /** @skipUpgrade */ - return Controller::join_links(Director::baseURL(), "Security", $action); + $link = Controller::join_links(Director::baseURL(), "Security", $action); + $this->extend('updateLink', $link, $action); + return $link; } /**