/** * Add a form element in the current section * * @param string|form_abstract $type Form element type or element form * @param array $prm Parameter array for the element * @param bool $isI18n * @return form_abstract|null Reference to the added element or null if not added or i18n (name exist yet) */ public function add($type, array $prm = array(), $isI18n = false) { if ($isI18n) { $this->i18nElements[] = array('type' => $type, 'prm' => $prm); return null; } $inst = null; $name = null; if ($type instanceof form_abstract && !$this->has($name = $type->getName())) { $inst = $type; $inst->renew(); } else { if (is_string($type) && array_key_exists('name', $prm) && !$this->has($name = $prm['name'])) { $inst = $this->getNew($type, $prm); } } if ($inst) { $this->elements[$this->curSection][$name] = $inst; $this->elementsSection[$name] = $this->curSection; if ($inst instanceof form_file) { $this->hasFiles++; } return $inst; } else { return null; } }