| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.0.1 |
| 5 |
* |
| 6 |
* @author FirePlugins <[email protected]> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2021 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FPFramework\Base\Fields; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
use FPFramework\Base\Field; |
| 20 |
use FPFramework\Libs\Registry; |
| 21 |
|
| 22 |
class Number extends Field |
| 23 |
{ |
| 24 |
/** |
| 25 |
* Set specific field options |
| 26 |
* |
| 27 |
* @param array $options |
| 28 |
* |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
protected function setFieldOptions($options) |
| 32 |
{ |
| 33 |
$options = new Registry($options); |
| 34 |
|
| 35 |
$this->field_options = [ |
| 36 |
'min' => $options->get('min', 0), |
| 37 |
'max' => $options->get('max', ''), |
| 38 |
'step' => $options->get('step', 1), |
| 39 |
'addon' => $options->get('addon', ''), |
| 40 |
'filter' => $options->get('filter', 'sanitize_key') |
| 41 |
]; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Prepares the field data after field default settings and any field specifc settings have been combined |
| 46 |
* |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
protected function prePrepareData() |
| 50 |
{ |
| 51 |
parent::prePrepareData(); |
| 52 |
|
| 53 |
$number_atts = []; |
| 54 |
if (isset($this->options['min']) && is_numeric($this->options['min'])) |
| 55 |
{ |
| 56 |
$number_atts['min'] = $this->options['min']; |
| 57 |
} |
| 58 |
if (isset($this->options['max']) && is_numeric($this->options['max'])) |
| 59 |
{ |
| 60 |
$number_atts['max'] = $this->options['max']; |
| 61 |
} |
| 62 |
if (isset($this->options['step']) && is_numeric($this->options['step'])) |
| 63 |
{ |
| 64 |
$number_atts['step'] = $this->options['step']; |
| 65 |
} |
| 66 |
$this->options['number_atts'] = \FPFramework\Helpers\FieldsHelper::getHTMLAttributes($number_atts); |
| 67 |
} |
| 68 |
} |