/** * Adds an element to the form, if element has DecoratedInterface, injects DI * * @param \Phalcon\Forms\ElementInterface $element * @param string $postion * @param bool $type If $type is TRUE, the element wile add before $postion, else is after * @return \Phalcon\Forms\Form */ public function add(ElementInterface $element, $postion = null, $type = null) { if ($element instanceof Decorator\DecoratedInterface && $element->getDecorator() instanceof DecoratorInterface) { $element->getDecorator()->setDI($this->di); } $reflectionClass = new \ReflectionClass($element); $elementType = strtolower(str_replace($reflectionClass->getNamespaceName() . '\\', '', $reflectionClass->getName())); $element->setUserOption('_type', $elementType); // hax even when $postion and $type are null by default, call parent::add($element, $postion, $type) // causes exception : Array position does not exist if (!is_null($postion) || !is_null($type)) { return parent::add($element, $postion, $type); } else { return parent::add($element); } }