/** * Adds the link to the element containing current * * @param HTML_QuickForm2_Container $container Element containing * the current one, null if the link should * really be removed (if removing from container) * * @throws HTML_QuickForm2_InvalidArgumentException If trying to set a * child of an element as its container */ protected function setContainer(HTML_QuickForm2_Container $container = null) { if (null !== $container) { $check = $container; do { if ($this === $check) { throw new HTML_QuickForm2_InvalidArgumentException('Cannot set an element or its child as its own container'); } } while ($check = $check->getContainer()); if (null !== $this->container && $container !== $this->container) { $this->container->removeChild($this); } } $this->container = $container; if (null !== $container) { $this->updateValue(); } }
/** * Removes the element from this container * * If the reference object is not given, the element will be appended. * * @param HTML_QuickForm2_Node Element to remove * @return HTML_QuickForm2_Node Removed object */ public function removeChild(HTML_QuickForm2_Node $element) { $element = parent::removeChild($element); if ($this->prependsName()) { $name = preg_replace('/^' . $this->getName() . '\\[([^\\]]*)\\]/', '\\1', $element->getName()); $element->setName($name); } return $element; }
/** * Sets the Container that will be used as a prototype for repeating * * @param HTML_QuickForm2_Container $prototype prototype container * * @return $this */ public function setPrototype(HTML_QuickForm2_Container $prototype) { if (!empty($this->elements[0])) { parent::removeChild($this->elements[0]); $this->elements = array(); } parent::appendChild($prototype); return $this; }