The validation of the min/max value happens in the PHP class but can also be directly done in the browser because of the min and max properties of the input element.
<optiontype>boolean</optiontype>
<defaultvalue>0</defaultvalue>
</option>
-
+
<option name="enable_debug_mode">
<categoryname>module.system</categoryname>
<optiontype>boolean</optiontype>
<categoryname>general.system.http</categoryname>
<optiontype>integer</optiontype>
<defaultvalue>1</defaultvalue>
+ <minvalue>1</minvalue>
+ <maxvalue>9</maxvalue>
</option>
<!-- /general.system.http -->
<categoryname>security.general.session</categoryname>
<optiontype>integer</optiontype>
<defaultvalue>1800</defaultvalue>
- <validationpattern>^[^0]</validationpattern>
+ <minvalue>1</minvalue>
</option>
<option name="user_online_timeout">
<categoryname>security.general.session</categoryname>
<optiontype>integer</optiontype>
<defaultvalue>900</defaultvalue>
+ <minvalue>1</minvalue>
</option>
<option name="session_validate_ip_address">
<categoryname>security.general.session</categoryname>
<option name="mail_smtp_port">
<categoryname>general.mail.send</categoryname>
<optiontype>integer</optiontype>
- <defaultvalue><![CDATA[25]]></defaultvalue>
+ <defaultvalue>25</defaultvalue>
</option>
<option name="mail_smtp_user">
<categoryname>general.mail.send</categoryname>
--- /dev/null
+<input type="number" id="{$option->optionName}" name="values[{$option->optionName}]" value="{$value}"{if $option->minvalue !== null} min="{$option->minvalue}"{/if}{if $option->maxvalue !== null} max="{$option->maxvalue}"{/if}{if $inputClass} class="{@$inputClass}"{/if} />
\ No newline at end of file
--- /dev/null
+<input type="number" id="{$option->optionName}" name="values[{$option->optionName}]" value="{$value}"{if $option->minvalue !== null} min="{$option->minvalue}"{/if}{if $option->maxvalue !== null} max="{$option->maxvalue}"{/if}{if $inputClass} class="{@$inputClass}"{/if} />
\ No newline at end of file
*/
protected static $databaseTableIndexName = 'optionID';
+ /**
+ * @see wcf\data\IStorableObject::__get()
+ */
+ public function __get($name) {
+ $value = parent::__get($name);
+
+ // treat additional data as data variables if it is an array
+ if ($value === null) {
+ if (is_array($this->data['additionalData']) && isset($this->data['additionalData'][$name])) {
+ $value = $this->data['additionalData'][$name];
+ }
+ }
+
+ return $value;
+ }
+
/**
* @see wcf\data\DatabaseObject::handleData()
*/
<?php
namespace wcf\system\option;
use wcf\data\option\Option;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
/**
* Option type implementation for integer input fields.
*/
class IntegerOptionType extends TextOptionType {
/**
- * @see wcf\system\option\TextOptionType::$inputType
+ * @see wcf\system\option\TextOptionType::$inputClass
*/
- protected $inputType = 'number';
+ protected $inputClass = 'medium';
+
+ /**
+ * @see wcf\system\option\IOptionType::getFormElement()
+ */
+ public function getFormElement(Option $option, $value) {
+ WCF::getTPL()->assign(array(
+ 'option' => $option,
+ 'inputClass' => $this->inputClass,
+ 'value' => $value
+ ));
+
+ return WCF::getTPL()->fetch('integerOptionType');
+ }
/**
* @see wcf\system\option\IOptionType::getData()
public function getData(Option $option, $newValue) {
return intval($newValue);
}
+
+ /**
+ * @see wcf\system\option\IOptionType::validate()
+ */
+ public function validate(Option $option, $newValue) {
+ if ($option->minvalue !== null && $option->minvalue > $newValue) {
+ throw new UserInputException($option->optionName, 'tooLow');
+ }
+ if ($option->maxvalue !== null && $option->maxvalue < $newValue) {
+ throw new UserInputException($option->optionName, 'tooHigh');
+ }
+ }
}