/** * 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']); } }