Example #1
0
 /**
  * If this field is a singleton, append it to a particular form which is not a form for singletons.
  *
  * @access  public
  * @param   Form $form
  * @throws  Exception
  * @throws  Exception\Fatal
  * @since   1.0.0-alpha
  * @version 1.0.0-alpha
  */
 public function setFormIfSingleton(Form &$form)
 {
     if ($form->getName() === 'singletons') {
         throw new Exception\Fatal('You can\'t append this field to the singletons form.');
     } elseif ($this->getFormObject()->getName() !== 'singletons') {
         throw new Exception\Fatal('This field is already appended to other form.');
     } else {
         $rules = $this->getFormObject()->getValidator()->getRules($this->getName());
         $this->oForm = $form;
         $this->oForm->addField($this);
         $this->oForm->getValidator()->rules($this->getName(), $rules);
         $this->resetAllNeededAttributes();
         $this->setWeight($this->oForm->getLastWeight());
     }
 }