/** * when constructing a proper form section, calls _construct_finalize on children * so that they know who their parent is, and what name they've been given. * @param array $options_array { * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name * @type $include string[] numerically-indexed where values are section names to be included, * and in that order. This is handy if you want * the subsections to be ordered differently than the default, and if you override which fields are shown * @type $exclude string[] values are subsections to be excluded. This is handy if you want * to remove certain default subsections (note: if you specify BOTH 'include' AND 'exclude', * the inclusions will be applied first, and the exclusions will exclude items from that list of inclusions) * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form * } @see EE_Form_Section_Validatable::__construct() * */ public function __construct($options_array = array()) { EE_Registry::instance()->load_helper('Formatter'); //call parent first, as it may be setting the name parent::__construct($options_array); //if they've included subsections in the constructor, add them now if (isset($options_array['include'])) { //we are going to make sure we ONLY have those subsections to include //AND we are going to make sure they're in that specified order $reordered_subsections = array(); foreach ($options_array['include'] as $input_name) { if (isset($this->_subsections[$input_name])) { $reordered_subsections[$input_name] = $this->_subsections[$input_name]; } } $this->_subsections = $reordered_subsections; } if (isset($options_array['exclude'])) { $exclude = $options_array['exclude']; $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); } if (isset($options_array['layout_strategy'])) { $this->_layout_strategy = $options_array['layout_strategy']; } if (!$this->_layout_strategy) { $this->_layout_strategy = new EE_Two_Column_Layout(); } $this->_layout_strategy->_construct_finalize($this); add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); }
/** * when constructing a proper form section, calls _construct_finalize on children * so that they know who their parent is, and what name they've been given. * * @param array $options_array { * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name * @type $include string[] numerically-indexed where values are section names to be included, * and in that order. This is handy if you want * the subsections to be ordered differently than the default, and if you override which fields are shown * @type $exclude string[] values are subsections to be excluded. This is handy if you want * to remove certain default subsections (note: if you specify BOTH 'include' AND 'exclude', * the inclusions will be applied first, and the exclusions will exclude items from that list of inclusions) * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form * } @see EE_Form_Section_Validatable::__construct() * @throws \EE_Error */ public function __construct($options_array = array()) { $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, $this); //call parent first, as it may be setting the name parent::__construct($options_array); //if they've included subsections in the constructor, add them now if (isset($options_array['include'])) { //we are going to make sure we ONLY have those subsections to include //AND we are going to make sure they're in that specified order $reordered_subsections = array(); foreach ($options_array['include'] as $input_name) { if (isset($this->_subsections[$input_name])) { $reordered_subsections[$input_name] = $this->_subsections[$input_name]; } } $this->_subsections = $reordered_subsections; } if (isset($options_array['exclude'])) { $exclude = $options_array['exclude']; $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); } if (isset($options_array['layout_strategy'])) { $this->_layout_strategy = $options_array['layout_strategy']; } if (!$this->_layout_strategy) { $this->_layout_strategy = new EE_Two_Column_Layout(); } $this->_layout_strategy->_construct_finalize($this); //ok so we are definitely going to want the forms JS, //so enqueue it or remember to enqueue it during wp_enqueue_scripts if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { //ok so they've constructed this object after when they should have. //just enqueue the generic form scripts and initialize the form immediately in the JS \EE_Form_Section_Proper::wp_enqueue_scripts(true); } else { add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); } add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); if (isset($options_array['name'])) { $this->_construct_finalize(null, $options_array['name']); } }
/** * @param array $input_args { * @type string $html_name the html name for the input * @type string $html_label_id the id attribute to give to the html label tag * @type string $html_label_class the class attribute to give to the html label tag * @type string $html_label_style the style attribute to give ot teh label tag * @type string $html_label_text the text to put in the label tag * @type string $html_label the full html label. If used, all other html_label_* args are invalid * @type string $html_help_text text to put in help element * @type string $html_help_style style attribute to give to teh help element * @type string $html_help_class class attribute to give to the help element * @type string $default default value NORMALIZED (eg, if providing the default for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') * @type EE_Display_Strategy_Base $display strategy * @type EE_Normalization_Strategy_Base $normalization_strategy * @type EE_Validation_Strategy_Base[] $validation_strategies * } */ public function __construct($input_args = array()) { // the following properties must be cast as arrays $set_as_array = array('validation_strategies'); // loop thru incoming options foreach ($input_args as $key => $value) { // add underscore to $key to match property names $_key = '_' . $key; if (property_exists($this, $_key)) { // first check if this property needs to be set as an array if (isset($set_as_array[$key])) { // ensure value is an array $value = is_array($value) ? $value : array($value); // and merge with existing values $this->{$_key} = array_merge($this->{$_key}, $value); } else { $this->{$_key} = $value; } } } // ensure that "required" is set correctly $this->set_required($this->_required, isset($input_args['required_validation_error_message']) ? $input_args['required_validation_error_message'] : NULL); $this->_html_name_specified = isset($input_args['html_name']) ? TRUE : FALSE; $this->_display_strategy->_construct_finalize($this); if ($this->_validation_strategies) { foreach ($this->_validation_strategies as $validation_strategy) { $validation_strategy->_construct_finalize($this); } } if (!$this->_normalization_strategy) { $this->_normalization_strategy = new EE_Text_Normalization(); } $this->_normalization_strategy->_construct_finalize($this); //at least we can use the normalization strategy to populate the default if (isset($input_args['default'])) { $this->set_default($input_args['default']); } if (!$this->_sensitive_data_removal_strategy) { $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); } $this->_sensitive_data_removal_strategy->_construct_finalize($this); parent::__construct($input_args); }
/** * @param array $input_args { * @type string $html_name the html name for the input * @type string $html_label_id the id attribute to give to the html label tag * @type string $html_label_class the class attribute to give to the html label tag * @type string $html_label_style the style attribute to give ot teh label tag * @type string $html_label_text the text to put in the label tag * @type string $html_label the full html label. If used, * all other html_label_* args are invalid * @type string $html_help_text text to put in help element * @type string $html_help_style style attribute to give to teh help element * @type string $html_help_class class attribute to give to the help element * @type string $default default value NORMALIZED (eg, if providing the default for a Yes_No_Input, * you should provide TRUE or FALSE, not '1' or '0') * @type EE_Display_Strategy_Base $display strategy * @type EE_Normalization_Strategy_Base $normalization_strategy * @type EE_Validation_Strategy_Base[] $validation_strategies * } */ public function __construct($input_args = array()) { $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); // the following properties must be cast as arrays if (isset($input_args['validation_strategies'])) { foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { if ($validation_strategy instanceof EE_Validation_Strategy_Base) { $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; } } unset($input_args['validation_strategies']); } // loop thru incoming options foreach ($input_args as $key => $value) { // add underscore to $key to match property names $_key = '_' . $key; if (property_exists($this, $_key)) { $this->{$_key} = $value; } } // ensure that "required" is set correctly $this->set_required($this->_required, isset($input_args['required_validation_error_message']) ? $input_args['required_validation_error_message'] : null); //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; $this->_display_strategy->_construct_finalize($this); foreach ($this->_validation_strategies as $validation_strategy) { $validation_strategy->_construct_finalize($this); } if (!$this->_normalization_strategy) { $this->_normalization_strategy = new EE_Text_Normalization(); } $this->_normalization_strategy->_construct_finalize($this); //at least we can use the normalization strategy to populate the default if (isset($input_args['default'])) { $this->set_default($input_args['default']); } if (!$this->_sensitive_data_removal_strategy) { $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); } $this->_sensitive_data_removal_strategy->_construct_finalize($this); parent::__construct($input_args); }