From fc3c9920afd7456f01695b4a5c345071d9c7ddd8 Mon Sep 17 00:00:00 2001 From: Nicholas Byfleet Date: Tue, 13 Aug 2019 16:09:16 +1200 Subject: [PATCH 1/4] Upgrading package to silverstripe 4.x --- code/HoneyPotField.php | 16 ++++++++++++++++ code/HoneyPotSpamProtector.php | 26 +++++++++++++++----------- composer.json | 4 ++-- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/code/HoneyPotField.php b/code/HoneyPotField.php index 2115faf..f3b9787 100644 --- a/code/HoneyPotField.php +++ b/code/HoneyPotField.php @@ -1,8 +1,20 @@ value) || $this->value === '')) { @@ -18,6 +30,10 @@ public function validate($validator) return true; } + /** + * @param array $properties + * @return \SilverStripe\ORM\FieldType\DBHTMLText + */ public function FieldHolder($properties = array()) { return $this->renderWith('HoneyPotField_holder'); diff --git a/code/HoneyPotSpamProtector.php b/code/HoneyPotSpamProtector.php index 331a143..2769c3d 100644 --- a/code/HoneyPotSpamProtector.php +++ b/code/HoneyPotSpamProtector.php @@ -1,23 +1,27 @@ Date: Tue, 13 Aug 2019 16:41:48 +1200 Subject: [PATCH 2/4] Trying to get autoloading working. --- composer.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/composer.json b/composer.json index aac9350..df0418b 100644 --- a/composer.json +++ b/composer.json @@ -4,5 +4,11 @@ "require": { "silverstripe/spamprotection": "~3.0.0", "composer/installers": "~1.0" + }, + "autoload": { + "psr-4": { + "Heyday\\SilverStripe\\HoneyPot": "code/" + + } } } From 21ff137a18c02aa97ef4d941fddfe3fb8bdccb38 Mon Sep 17 00:00:00 2001 From: Nicholas Byfleet Date: Tue, 13 Aug 2019 16:43:42 +1200 Subject: [PATCH 3/4] Trying to get autoloading working. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index df0418b..0a7f01e 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ }, "autoload": { "psr-4": { - "Heyday\\SilverStripe\\HoneyPot": "code/" + "Heyday\\SilverStripe\\HoneyPot\\": "code/" } } From d8f1a56f71c6745a9b480d086a38928f8ba8c11a Mon Sep 17 00:00:00 2001 From: Nicholas Byfleet Date: Wed, 14 Aug 2019 10:49:43 +1200 Subject: [PATCH 4/4] Completed basic SilverStripe 4 upgrade of package. --- README.md | 35 +++++++++++++++---- .../templates}/HoneyPotField_holder.ss | 0 composer.json | 1 - 3 files changed, 29 insertions(+), 7 deletions(-) rename {templates => code/templates}/HoneyPotField_holder.ss (100%) diff --git a/README.md b/README.md index e0400d7..eb6dce3 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,38 @@ -# SilverStripe honeypot +# SilverStripe Honey Pot -For a SilverStripe `2.4` compatible version use the branch `1.0` +A SilverStripe 4.x compatible version of camspiers/honeypot ## Installation (with composer) - $ composer require camspiers/honeypot + $ composer require heyday/silverstripe-honeypot -Set the default spam protector in *mysite/_config/spamprotection.yml* +Set the default spam protector in *app/_config/spamprotection.yml* --- name: spamprotection --- - FormSpamProtectionExtension: - default_spam_protector: HoneyPotSpamProtector \ No newline at end of file + SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension: + default_spam_protector: Heyday\SilverStripe\HoneyPot\HoneyPotSpamProtector + +Or, on a form by form basis + + use Heyday\SilverStripe\HoneyPot\HoneyPotField; + use SilverStripe\Forms\Form; + use SilverStripe\Control\Controller; + use SilverStripe\Forms\FieldList; + + /** + * Class SomeForm + */ + class SomeForm extends Form + { + /** + * @param Controller $controller + */ + public function __construct(Controller $controller) + { + $fields = new FieldList(); + $fields->push(new HoneyPotField('Website')); // 'Website' here can be any old string + ... + } + } \ No newline at end of file diff --git a/templates/HoneyPotField_holder.ss b/code/templates/HoneyPotField_holder.ss similarity index 100% rename from templates/HoneyPotField_holder.ss rename to code/templates/HoneyPotField_holder.ss diff --git a/composer.json b/composer.json index 0a7f01e..9eb53e8 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,6 @@ "autoload": { "psr-4": { "Heyday\\SilverStripe\\HoneyPot\\": "code/" - } } }