<commit_before><?php

/**
 * Editable Spam Protecter Field. Used with the User Defined Forms module (if 
 * installed) to allow the user to have captcha fields with their custom forms
 * 
 * @package spamprotection
 */
if(class_exists('EditableFormField')) {
	
	class EditableSpamProtectionField extends EditableFormField {
	
		static $singular_name = 'Spam Protection Field';
	
		static $plural_name = 'Spam Protection Fields';
		/**
		 * Fields to include spam detection for
		 *
		 * @var array
		 * @config
		 */
		private static $check_fields = array(
			'EditableEmailField',
			'EditableTextField',
			'EditableNumericField'
		);
	
		public function getFormField() {
			// Get protector
			$protector = FormSpamProtectionExtension::get_protector();
			if(!$protector) return false;

			// Extract saved field mappings and update this field.
			$fieldMapping = array();
			foreach($this->getCandidateFields() as $otherField) {
				$mapSetting = "Map-{$otherField->Name}";
				$spamField = $this->getSetting($mapSetting);
				$fieldMapping[$otherField->Name] = $spamField;
			}
			$protector->setFieldMapping($fieldMapping);

			// Generate field
			return $protector->getFormField($this->Name, $this->Title, null);
		}

		/**
		 * Gets the list of all candidate spam detectable fields on this field's form
		 *
		 * @return DataList
		 */
		protected function getCandidateFields() {

			// Get list of all configured classes available for spam detection
			$types = self::config()->check_fields;
			$typesInherit = array();
			foreach ($types as $type) {
				$subTypes = ClassInfo::subclassesFor($type);
				$typesInherit = array_merge($typesInherit, $subTypes);
			}

			// Get all candidates of the above types
			return $this
				->Parent()
				->Fields()
				->filter('ClassName', $typesInherit)
				->exclude('Title', ''); // Ignore this field and those without titles
		}

		public function getFieldConfiguration() {
			$fields = parent::getFieldConfiguration();

			// Get protector
			$protector = FormSpamProtectionExtension::get_protector();
			if (empty($protector)) return fields;
			
			// Each other text field in this group can be assigned a field mapping
			$mapGroup = FieldGroup::create(_t(
				'EditableSpamProtectionField.SPAMFIELDMAPPING',
				'Spam Field Mapping'
			))->setDescription(_t(
				'EditableSpamProtectionField.SPAMFIELDMAPPINGDESCRIPTION',<commit_msg>FIX: typo in field name<commit_after><?php

/**
 * Editable Spam Protecter Field. Used with the User Defined Forms module (if 
 * installed) to allow the user to have captcha fields with their custom forms
 * 
 * @package spamprotection
 */
if(class_exists('EditableFormField')) {
	
	class EditableSpamProtectionField extends EditableFormField {
	
		static $singular_name = 'Spam Protection Field';
	
		static $plural_name = 'Spam Protection Fields';
		/**
		 * Fields to include spam detection for
		 *
		 * @var array
		 * @config
		 */
		private static $check_fields = array(
			'EditableEmailField',
			'EditableTextField',
			'EditableNumericField'
		);
	
		public function getFormField() {
			// Get protector
			$protector = FormSpamProtectionExtension::get_protector();
			if(!$protector) return false;

			// Extract saved field mappings and update this field.
			$fieldMapping = array();
			foreach($this->getCandidateFields() as $otherField) {
				$mapSetting = "Map-{$otherField->Name}";
				$spamField = $this->getSetting($mapSetting);
				$fieldMapping[$otherField->Name] = $spamField;
			}
			$protector->setFieldMapping($fieldMapping);

			// Generate field
			return $protector->getFormField($this->Name, $this->Title, null);
		}

		/**
		 * Gets the list of all candidate spam detectable fields on this field's form
		 *
		 * @return DataList
		 */
		protected function getCandidateFields() {

			// Get list of all configured classes available for spam detection
			$types = self::config()->check_fields;
			$typesInherit = array();
			foreach ($types as $type) {
				$subTypes = ClassInfo::subclassesFor($type);
				$typesInherit = array_merge($typesInherit, $subTypes);
			}

			// Get all candidates of the above types
			return $this
				->Parent()
				->Fields()
				->filter('ClassName', $typesInherit)
				->exclude('Title', ''); // Ignore this field and those without titles
		}

		public function getFieldConfiguration() {
			$fields = parent::getFieldConfiguration();

			// Get protector
			$protector = FormSpamProtectionExtension::get_protector();
			if (!$protector) return $fields;
			
			// Each other text field in this group can be assigned a field mapping
			$mapGroup = FieldGroup::create(_t(
				'EditableSpamProtectionField.SPAMFIELDMAPPING',
				'Spam Field Mapping'
			))->setDescription(_t(
				'EditableSpamProtectionField.SPAMFIELDMAPPINGDESCRIPTION',
{'fraction_non_alphanumeric': 0.1171434537481729, 'fraction_numerical': 0.0, 'mean_word_length': 3.8629441624365484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '804073', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1374, 'n_words': 385}