API LoginForm::authentiator_class is now deprecated, use getters or setters instead

This commit is contained in:
Robbie Averill 2018-11-05 13:47:47 +01:00
parent 3d5c330e17
commit ebfab45e23
3 changed files with 33 additions and 11 deletions

View File

@ -15,19 +15,30 @@ use SilverStripe\Forms\Form;
*/
abstract class LoginForm extends Form
{
/**
* Authenticator class to use with this login form
*
* Set this variable to the authenticator class to use with this login
* form.
* @deprecated 4.4.0:5.0.0 Use getAuthenticatorClass() or setAuthenticatorClass() instead
* @var string
*/
protected $authenticator_class;
/**
* Authenticator class to use with this login form
*
* Set this variable to the authenticator class to use with this login form.
*
* @var string
*/
protected $authenticatorClass;
/**
* Set the authenticator class name to use
*
* @param string $class
* @return $this
*/
public function setAuthenticatorClass($class)
{
$this->authenticator_class = $class;
$this->authenticatorClass = $class;
$authenticatorField = $this->Fields()->dataFieldByName('AuthenticationMethod');
if ($authenticatorField) {
$authenticatorField->setValue($class);
@ -35,6 +46,17 @@ abstract class LoginForm extends Form
return $this;
}
/**
* Returns the authenticator class name to use
*
* @return string
*/
public function getAuthenticatorClass()
{
// B/C for deprecated authenticator_class property
return $this->authenticator_class ?: $this->authenticatorClass;
}
/**
* Return the title of the form for use in the frontend
* For tabs with multiple login methods, for example.

View File

@ -30,7 +30,7 @@ class CMSMemberLoginForm extends MemberLoginForm
{
$this->controller = $controller;
$this->authenticator_class = $authenticatorClass;
$this->setAuthenticatorClass($authenticatorClass);
$fields = $this->getFormFields();
@ -48,7 +48,7 @@ class CMSMemberLoginForm extends MemberLoginForm
{
// Set default fields
$fields = FieldList::create([
HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this),
HiddenField::create("AuthenticationMethod", null, $this->getAuthenticatorClass(), $this),
HiddenField::create('tempid', null, $this->controller->getRequest()->requestVar('tempid')),
PasswordField::create("Password", _t('SilverStripe\\Security\\Member.PASSWORD', 'Password'))
]);

View File

@ -77,7 +77,7 @@ class MemberLoginForm extends BaseLoginForm
$checkCurrentUser = true
) {
$this->setController($controller);
$this->authenticator_class = $authenticatorClass;
$this->setAuthenticatorClass($authenticatorClass);
$customCSS = project() . '/css/member_login.css';
if (Director::fileExists($customCSS)) {
@ -88,7 +88,7 @@ class MemberLoginForm extends BaseLoginForm
// @todo find a more elegant way to handle this
$logoutAction = Security::logout_url();
$fields = FieldList::create(
HiddenField::create('AuthenticationMethod', null, $this->authenticator_class, $this)
HiddenField::create('AuthenticationMethod', null, $this->getAuthenticatorClass(), $this)
);
$actions = FieldList::create(
FormAction::create('logout', _t(
@ -133,7 +133,7 @@ class MemberLoginForm extends BaseLoginForm
$label = Member::singleton()->fieldLabel(Member::config()->get('unique_identifier_field'));
$fields = FieldList::create(
HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this),
HiddenField::create("AuthenticationMethod", null, $this->getAuthenticatorClass(), $this),
// Regardless of what the unique identifer field is (usually 'Email'), it will be held in the
// 'Email' value, below:
// @todo Rename the field to a more generic covering name