FIX: Fixes suggested in PR, mostly minor

This commit is contained in:
Gordon Anderson 2018-04-20 11:13:48 +07:00
parent fb23959f60
commit c8084968c5
1 changed files with 9 additions and 9 deletions

View File

@ -37,7 +37,7 @@ class MathSpamProtectorField extends TextField
public function Field($properties = array()) public function Field($properties = array())
{ {
if (Config::inst()->get('SilverStripe\SpamProtection\Maths\MathSpamProtectorField', 'enabled')) { if ($this->config()->get('enabled')) {
return parent::Field($properties); return parent::Field($properties);
} }
@ -46,7 +46,7 @@ class MathSpamProtectorField extends TextField
public function FieldHolder($properties = array()) public function FieldHolder($properties = array())
{ {
if (Config::inst()->get('SilverStripe\SpamProtection\Maths\MathSpamProtectorField', 'enabled')) { if ($this->config()->get('enabled')) {
return parent::FieldHolder($properties); return parent::FieldHolder($properties);
} }
@ -60,7 +60,7 @@ class MathSpamProtectorField extends TextField
*/ */
public function Title() public function Title()
{ {
$prefix = Config::inst()->get('SilverStripe\SpamProtection\Maths\MathSpamProtection', 'question_prefix'); $prefix = $this->config()->get('question_prefix');
if (!$prefix) { if (!$prefix) {
$prefix = _t('MathSpamProtectionField.SPAMQUESTION', "Spam protection question: %s"); $prefix = _t('MathSpamProtectionField.SPAMQUESTION', "Spam protection question: %s");
@ -68,7 +68,7 @@ class MathSpamProtectorField extends TextField
return sprintf( return sprintf(
$prefix, $prefix,
$this->get_math_question() $this->getMathsQuestion()
); );
} }
@ -81,11 +81,11 @@ class MathSpamProtectorField extends TextField
*/ */
public function validate($validator) public function validate($validator)
{ {
if (!Config::inst()->get('SilverStripe\SpamProtection\Maths\MathSpamProtectorField', 'enabled')) { if (!$this->config()->get( 'enabled')) {
return true; return true;
} }
if (!$this->correct_answer($this->Value())) { if (!$this->isCorrectAnswer($this->Value())) {
$validator->validationError( $validator->validationError(
$this->name, $this->name,
_t( _t(
@ -107,7 +107,7 @@ class MathSpamProtectorField extends TextField
* *
* @return string * @return string
*/ */
public function get_math_question() public function getMathsQuestion()
{ {
/** @var Session $session */ /** @var Session $session */
$session = Controller::curr()->getRequest()->getSession(); $session = Controller::curr()->getRequest()->getSession();
@ -138,7 +138,7 @@ class MathSpamProtectorField extends TextField
* *
* @return bool * @return bool
*/ */
public function correct_answer($answer) public function isCorrectAnswer($answer)
{ {
$session = Controller::curr()->getRequest()->getSession(); $session = Controller::curr()->getRequest()->getSession();
@ -151,7 +151,7 @@ class MathSpamProtectorField extends TextField
$word = MathSpamProtectorField::digit_to_word($v1 + $v2); $word = MathSpamProtectorField::digit_to_word($v1 + $v2);
return ($word == strtolower($answer) || (Config::inst()->get('MathSpamProtectorField', 'allow_numeric_answer') && (($v1 + $v2) == $answer))); return ($word == strtolower($answer) || ($this->config()->get('allow_numeric_answer') && (($v1 + $v2) == $answer)));
} }
/** /**