_element = $this->_createElement($type, $name); foreach ($element as $method => $params) { $methodName = 'set' . ucfirst($method); if (method_exists($this->_element, $methodName) && !empty($element[$method])) { $this->_element->$methodName( $this->_prepareData($params)); } } } else { $type = (string)$element; $this->_element = $this->_createElement($type, $name); } $this->_element->setValue($value); // add header and body code /* @var \Cube\View\Helper\Script $helper */ $helper = $this->getView()->getHelper('script'); $headerCode = $this->_element->getHeaderCode(); foreach ($headerCode as $code) { $helper->addHeaderCode($code); } $bodyCode = $this->_element->getBodyCode(); foreach ($bodyCode as $code) { $helper->addBodyCode($code); } return $this->_element; } /** * * prepare serialized data and return it as an array which is parsable by the class methods * * @param mixed $data * * @return array */ protected function _prepareData($data) { if (!is_array($data)) { $array = @unserialize($data); if ($array === false) { return $data; } $keys = (isset($array['key'])) ? array_values($array['key']) : array(); $values = (isset($array['value'])) ? array_values($array['value']) : array(); return array_filter( array_combine($keys, $values)); } return $data; } }