1: <?php
2:
3: class Sidecar_Form_Settings extends Sidecar_Settings_Base {
4:
5: /**
6: * @var array List of names for required fields.
7: */
8: private $_required_fields = array();
9:
10: /**
11: * Register a setting
12: * @param string $setting_name
13: * @param bool|mixed $value
14: */
15: function register_setting( $setting_name, $value = false ) {
16: if ( ! $this->offsetExists( $setting_name ) )
17: $this->offsetSet( $setting_name, $value );
18: }
19:
20: /**
21: * @return array
22: */
23: function get_empty_field_values() {
24: return array_fill_keys( array_keys( (array)$this ), false );
25: }
26:
27: /**
28: * Set the list of required settings names for this form.
29: * @param bool|array $required_fields
30: */
31: function set_required_fields( $required_fields = false ) {
32: $this->_required_fields = $required_fields;
33: }
34:
35: /**
36: * @return bool
37: */
38: function has_required_fields() {
39: $has_required_fields = true;
40: /** @var Sidecar_Form $form */
41: foreach( $this->_required_fields as $setting_name ) {
42: if ( ! $this[$setting_name] ) {
43: $has_required_fields = false;
44: break;
45: }
46: }
47: return $has_required_fields;
48: }
49:
50:
51: }
52: