mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-10-22 14:05:59 +02:00
Compare commits
2 Commits
a2a21988ed
...
ed7dc6e38e
Author | SHA1 | Date | |
---|---|---|---|
|
ed7dc6e38e | ||
|
d452367262 |
@ -130,13 +130,13 @@ class EditableSpamProtectionField extends EditableFormField
|
|||||||
*/
|
*/
|
||||||
public function onBeforeWrite()
|
public function onBeforeWrite()
|
||||||
{
|
{
|
||||||
$fieldMap = json_decode($this->SpamFieldSettings, true);
|
$fieldMap = json_decode($this->SpamFieldSettings ?? '', true);
|
||||||
if (empty($fieldMap)) {
|
if (empty($fieldMap)) {
|
||||||
$fieldMap = array();
|
$fieldMap = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->record as $key => $value) {
|
foreach ($this->record as $key => $value) {
|
||||||
if (substr($key, 0, 8) === 'spammap-') {
|
if (substr($key ?? '', 0, 8) === 'spammap-') {
|
||||||
$fieldMap[substr($key, 8)] = $value;
|
$fieldMap[substr($key, 8)] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ class EditableSpamProtectionField extends EditableFormField
|
|||||||
|
|
||||||
// Generate field specific settings
|
// Generate field specific settings
|
||||||
$mappableFields = FormSpamProtectionExtension::config()->get('mappable_fields');
|
$mappableFields = FormSpamProtectionExtension::config()->get('mappable_fields');
|
||||||
$mappableFieldsMerged = array_combine($mappableFields, $mappableFields);
|
$mappableFieldsMerged = array_combine($mappableFields ?? [], $mappableFields ?? []);
|
||||||
foreach ($this->getCandidateFields() as $otherField) {
|
foreach ($this->getCandidateFields() as $otherField) {
|
||||||
$mapSetting = "Map-{$otherField->Name}";
|
$mapSetting = "Map-{$otherField->Name}";
|
||||||
$fieldOption = DropdownField::create(
|
$fieldOption = DropdownField::create(
|
||||||
@ -200,12 +200,12 @@ class EditableSpamProtectionField extends EditableFormField
|
|||||||
*/
|
*/
|
||||||
public function spamMapValue($mapSetting)
|
public function spamMapValue($mapSetting)
|
||||||
{
|
{
|
||||||
$map = json_decode($this->SpamFieldSettings, true);
|
$map = json_decode($this->SpamFieldSettings ?? '', true);
|
||||||
if (empty($map)) {
|
if (empty($map)) {
|
||||||
$map = array();
|
$map = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($mapSetting, $map)) {
|
if (array_key_exists($mapSetting, $map ?? [])) {
|
||||||
return $map[$mapSetting];
|
return $map[$mapSetting];
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
@ -235,7 +235,7 @@ class EditableSpamProtectionField extends EditableFormField
|
|||||||
$foundError = false;
|
$foundError = false;
|
||||||
|
|
||||||
// field validate implementation may not add error to validator
|
// field validate implementation may not add error to validator
|
||||||
if (count($errors) > 0) {
|
if (count($errors ?? []) > 0) {
|
||||||
// check if error already added from fields' validate method
|
// check if error already added from fields' validate method
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as $error) {
|
||||||
if ($error['fieldName'] == $this->Name) {
|
if ($error['fieldName'] == $this->Name) {
|
||||||
|
@ -73,7 +73,7 @@ class FormSpamProtectionExtension extends Extension
|
|||||||
$protector = self::config()->get('default_spam_protector');
|
$protector = self::config()->get('default_spam_protector');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($protector && class_exists($protector)) {
|
if ($protector && class_exists($protector ?? '')) {
|
||||||
return Injector::inst()->create($protector);
|
return Injector::inst()->create($protector);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user