/**
  * @param \Zend\Form\Form $form
  */
 public function updateOrCreate($form)
 {
     $checkEntityNotExist = false;
     $formName = $form->getName();
     $data = $this->params()->fromPost();
     if (!empty($formName) && $form->wrapElements()) {
         $data = $data[$formName];
     }
     $codigo = $this->getIdentifierData($form, $data);
     if ($codigo) {
         $entity = $this->getService()->find($codigo);
         if (!$entity) {
             $checkEntityNotExist = true;
         } else {
             $form->bind($entity);
         }
     } else {
         $checkEntityNotExist = true;
     }
     $form->setData($data);
     if ($form->isValid()) {
         if (!$checkEntityNotExist) {
             $entity = $this->getService()->update($entity);
             $this->setEntity($entity);
             return 1;
         } else {
             if ($this->getFormCreate()) {
                 $entity = $this->getService()->create($entity);
                 $this->setEntity($entity);
                 return 2;
             }
             throw new BaseException($this->getTranslator()->translate('e_entity_not_found'), BaseException::ERROR_ENTITY_NOT_EXIST);
         }
     }
     return false;
 }