Пример #1
0
 /**
  * Insert a form element before another element
  *
  * @param  string                  $name
  * @param  Element\AbstractElement $e
  * @throws Exception
  * @return Form
  */
 public function insertElementBefore($name, Element\AbstractElement $e)
 {
     $i = $this->getElementIndex($name);
     if (null === $i) {
         throw new Exception('Error: That element does not exist.');
     }
     // If the element is the top of element of a group, switch out for the new element being inserted before
     foreach ($this->groups as $key => $group) {
         if ($group == $name) {
             $this->groups[$key] = $e->getName();
         }
     }
     $this->childNodes = array_merge(array_slice($this->childNodes, 0, $i), [$e], array_slice($this->childNodes, $i));
     return $this;
 }