get('default_spam_protector'); } if ($protector && class_exists($protector ?? '')) { return Injector::inst()->create($protector); } else { return null; } } /** * Activates the spam protection module. * * @param array $options * @throws LogicException when get_protector method returns NULL. * @return Object */ public function enableSpamProtection($options = array()) { // captcha form field name (must be unique) if (isset($options['name'])) { $name = $options['name']; } else { $name = $this->config()->get('field_name'); } // captcha field title if (isset($options['title'])) { $title = $options['title']; } else { $title = ''; } // set custom mapping on this form $protector = self::get_protector($options); if ($protector === null) { throw new LogicException('No spam protector has been set. Null is not valid value.'); } if ($protector && isset($options['mapping'])) { $protector->setFieldMapping($options['mapping']); } if ($protector) { // add the form field if ($field = $protector->getFormField($name, $title)) { $field->setForm($this->owner); // Add before field specified by insertBefore $inserted = false; if (!empty($options['insertBefore'])) { $inserted = $this->owner->Fields()->insertBefore($options['insertBefore'], $field); } if (!$inserted) { // Add field to end if not added already $this->owner->Fields()->push($field); } } } return $this->owner; } }