From 9abe13fcb6d0576598d70b103a49a0f138ab6663 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 18 Feb 2014 16:19:29 +1300 Subject: [PATCH] API Refactor field mapping from FormSpamProtectionExtension into SpamProtector API EditableSpamProtectionField may now be configured for spam on an individual field basis Translations added --- code/EditableSpamProtectionField.php | 8 +++----- code/extensions/FormSpamProtectionExtension.php | 14 +++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/code/EditableSpamProtectionField.php b/code/EditableSpamProtectionField.php index faa8729..fe273b6 100644 --- a/code/EditableSpamProtectionField.php +++ b/code/EditableSpamProtectionField.php @@ -13,7 +13,6 @@ if(class_exists('EditableFormField')) { static $singular_name = 'Spam Protection Field'; static $plural_name = 'Spam Protection Fields'; - /** * Fields to include spam detection for * @@ -27,11 +26,10 @@ if(class_exists('EditableFormField')) { ); public function getFormField() { - // Get protector $protector = FormSpamProtectionExtension::get_protector(); - if(empty($protector)) return false; - + if(!$protector) return false; + // Extract saved field mappings and update this field. $fieldMapping = array(); foreach($this->getCandidateFields() as $otherField) { @@ -80,7 +78,7 @@ if(class_exists('EditableFormField')) { 'EditableSpamProtectionField.SPAMFIELDMAPPING', 'Spam Field Mapping' ))->setDescription(_t( - 'EditableSpamProtectionField.SPAMFIELDMAPPINGDESCRIPTION', + 'EditableSpamProtectionField.SPAMFIELDMAPPINGDESCRIPTION', 'Select the form fields that correspond to any relevant spam protection identifiers' )); diff --git a/code/extensions/FormSpamProtectionExtension.php b/code/extensions/FormSpamProtectionExtension.php index c9786bf..2009f98 100644 --- a/code/extensions/FormSpamProtectionExtension.php +++ b/code/extensions/FormSpamProtectionExtension.php @@ -43,7 +43,7 @@ class FormSpamProtectionExtension extends Extension { /** * Instantiate a SpamProtector instance - * + * * @param array $options Configuration options * @return SpamProtector */ @@ -51,15 +51,15 @@ class FormSpamProtectionExtension extends Extension { // generate the spam protector if(isset($options['protector'])) { $protector = $options['protector']; - - if(is_string($protector)) { - $protector = Injector::inst()->create($protector); - } } else { $protector = Config::inst()->get('FormSpamProtectionExtension', 'default_spam_protector'); - $protector = Injector::inst()->create($protector); } - return $protector; + + if($protector && class_exists($protector)) { + return Injector::inst()->create($protector); + } else { + return null; + } } /**