/**
  * @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 $document
  * @return void
  * @throws form_FieldLockedException
  */
 protected function preUpdate($document)
 {
     if ($document->getIsLocked() && $document->isPropertyModified("fieldName")) {
         throw new form_FieldLockedException("Cannot update the field name of a locked field: " . $document->__toString() . " " . $document->getFieldName());
     }
 }