public function to_object() { $data = parent::to_object(); if (in_array($this->type, self::$buttons)) { $data['element'] = 'button'; } else { $data['element'] = 'input'; } if (array_key_exists('options', $data)) { $opts = array(); foreach ($data['options'] as $key => $value) { $name = $value; if (is_object($name) && $name instanceof \System\Model\Attr) { $name = $name->name; } if (is_array($value) && array_key_exists('name', $value) && array_key_exists('name', $value)) { $opts[] = $value; } else { $opts[] = array("name" => $name, "value" => $key); } } $data['options'] = $opts; } return $data; }
/** Add element to the list * @param \System\Form\Element $el * @return void; */ public function &add_element(\System\Form\Element $el) { $el->form($this->form()); $fits = false; foreach ($this->get_expected_class() as $cname) { if ($el instanceof $cname) { $fits = true; break; } } if ($fits) { $this->elements[$el->name] = $el; } else { throw new \System\Error\Form(sprintf('Form container %s cannot accomodate element of type %s', $this->type, get_class($el))); } return $el; }