/** * @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 */ private function applyOnFieldDeleted($document) { if (isset($this->deletedFieldsForms[$document->getId()])) { $form = $this->deletedFieldsForms[$document->getId()]; $form->getDocumentService()->onFieldDeleted($form); unset($this->deletedFieldsForms[$document->getId()]); } }