/** * Bundle up a collection of variables and save in the database * * @access public * @param array $params * @param array $dynamic * @return void */ public function bundle($params = array(), $dynamic = array()) { /* Sample use --------------------------------------------------------- {exp:stash:bundle name="contact_form" context="@" unique="no" type="snippet" refresh="10"} {exp:stash:get dynamic="yes" name="orderby" output="no" default="persons_last_name" match="#^[a-zA-Z0-9_-]+$#"} {exp:stash:get dynamic="yes" name="sort" output="no" default="asc" match="#^asc$|^desc$#"} {exp:stash:get dynamic="yes" name="filter" output="no" default="" match="#^[a-zA-Z0-9_-]+$#"} {exp:stash:get dynamic="yes" name="in" output="no" default="" match="#^[a-zA-Z0-9_-]+$#"} {exp:stash:get dynamic="yes" name="field" output="no" match="#^[a-zA-Z0-9_-]+$#" default="persons_last_name"} {/exp:stash:bundle} --------------------------------------------------------- */ // is this method being called statically from PHP? if (func_num_args() > 0 && !(isset($this) && get_class($this) == __CLASS__)) { // as this function is called statically, // we need to get an instance of this object and run get() $self = new self(); // set parameters $this->EE->TMPL->tagparams = $params; // convert tagdata array if (is_array($dynamic)) { $this->EE->TMPL->tagdata = ''; foreach ($dynamic as $name => $options) { $this->EE->TMPL->tagdata .= LD . 'exp:stash:get dynamic="yes" name="' . $name . '"'; foreach ($options as $option => $value) { $this->EE->TMPL->tagdata .= ' ' . $option . '="' . $value . '"'; } $this->EE->TMPL->tagdata .= RD; } } else { $this->EE->TMPL->tagdata = $dynamic; } return $self->bundle(); } if (!!($bundle = $this->EE->TMPL->fetch_param('name', FALSE))) { // build a string of parameters to inject into nested stash tags $context = $this->EE->TMPL->fetch_param('context', NULL); $params = 'bundle="' . $bundle . '" scope="local"'; if ($context !== NULL) { $params .= ' context="' . $context . '"'; } // add params to nested tags $this->EE->TMPL->tagdata = preg_replace('/(' . LD . 'exp:stash:get|' . LD . 'exp:stash:set)/i', '$1 ' . $params, $this->EE->TMPL->tagdata); // get existing values from bundle $this->get_bundle(FALSE); // parse stash tags in the bundle $this->_parse_sub_template(); // save the bundle values $this->set_bundle(); } }