/**
  * @param form_persistentdocument_field $document
  */
 public function fixRequiredConstraint($document)
 {
     $constraintArray = $document->getConstraintArray();
     if ($document->getRequired()) {
         if (!isset($constraintArray['blank']) || $constraintArray['blank'] != 'false') {
             $constraintArray['blank'] = 'false';
         }
     }
     $strArray = array();
     foreach ($constraintArray as $k => $v) {
         $strArray[] = $k . ':' . $v;
     }
     $document->setValidators(join(";", $strArray));
 }
 /**
  * @param form_persistentdocument_field $field
  * @param integer $parentNodeId
  * @throws form_FormException When $field is not inside a form
  * @throws form_FieldAlreadyExistsException When the name of $field is not available
  */
 public function checkFieldNameAvailable($field, $parentNodeId)
 {
     $fieldName = $field->getFieldName();
     $parent = DocumentHelper::getDocumentInstance($parentNodeId);
     if ($parent instanceof form_persistentdocument_baseform) {
         $form = $parent;
     } else {
         $form = $this->getAncestorFormByDocument($parent);
         if ($form === null) {
             throw new form_FormException("Field \"" . $field->__toString() . "\" is not inside a form.");
         }
     }
     $query = $this->getPersistentProvider()->createQuery('modules_form/field');
     $query->add(Restrictions::descendentOf($form->getId()));
     $query->add(Restrictions::eq('fieldName', $fieldName));
     $result = $query->findUnique();
     if ($result !== null && $result->getId() != $field->getId()) {
         throw new form_FieldAlreadyExistsException(f_Locale::translate('&modules.form.bo.errors.Field-name-alreay-used;', array('fieldName' => $fieldName)));
     }
 }
 /**
  * @param form_persistentdocument_field $list
  * @param String $value
  */
 private function getLabelByListAndValue($list, $value)
 {
     if ($list instanceof form_persistentdocument_boolean) {
         return $value;
     } else {
         foreach ($list->getItems() as $item) {
             if ($item->getValue() == $value) {
                 return $item->getLabel();
             }
         }
     }
     return null;
 }