public function addElement() { // get request vars $element = YRequest::getWord('element', 'text'); $count = YRequest::getVar('count', 0); // load element $this->element = ElementHelper::loadElement($element, $this->application->getPath() . '/elements'); $this->var = 'new_elements[' . $count . ']'; // display view $this->getView()->setLayout('addElement')->display(); }
public static function saveElements($post, Type $type) { // init vars $elements = array(); // update old elements foreach ($type->getElements() as $identifier => $element) { if (isset($post['elements'][$identifier])) { $data = $post['elements'][$identifier]; // bind data $element->bindConfig($data); // add to element array $elements[$data['ordering']] = $element; } } // add new elements if (isset($post['new_elements'])) { foreach ($post['new_elements'] as $data) { $element = ElementHelper::loadElement($data['type'], $type->getApplication()->getPath() . '/elements'); $element->setType($type); // set identifier (UUID) $data['identifier'] = YUtility::generateUUID(); // bind data $element->bindConfig($data); // add to element array $elements[$data['ordering']] = $element; } } // sort elements ksort($elements); $type->setXML(self::toXML($elements)); $type->clearElements(); return true; }