loadDatatype() public static method

Load Datatype
public static loadDatatype ( Zend\ServiceManager\ServiceManager $serviceManager, integer $datatypeId, integer $documentId = null ) : mixed
$serviceManager Zend\ServiceManager\ServiceManager Service manager
$datatypeId integer Datatype id
$documentId integer Optional document id
return mixed
Ejemplo n.º 1
0
 /**
  * Edit datatype
  *
  * @return \Zend\View\Model\ViewModel|array
  */
 public function editAction()
 {
     $datatypeModel = Datatype\Model::fromId($this->getRouteMatch()->getParam('id'));
     if (empty($datatypeModel)) {
         return $this->redirect()->toRoute('development/datatype');
     }
     $datatype = Datatype\Model::loadDatatype($this->getServiceLocator(), $this->getRouteMatch()->getParam('id'));
     $datatypeForm = new DatatypeForm();
     $datatypeForm->setAttribute('action', $this->url()->fromRoute('development/datatype/edit', array('id' => $this->getRouteMatch()->getParam('id'))));
     DatatypeForm::addContent($datatypeForm, Datatype\Model::loadPrevalueEditor($datatype));
     $datatypeForm->loadValues($datatypeModel);
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost()->toArray();
         $datatypeForm->setData($post);
         if (!$datatypeForm->isValid()) {
             $this->flashMessenger()->addErrorMessage('Can not save datatype');
             $this->useFlashMessenger();
         } else {
             if ($datatypeModel->getModel() != $datatypeForm->getValue('model')) {
                 $datatypeModel->setPrevalueValue(array());
             } else {
                 $datatypeModel->setPrevalueValue(Datatype\Model::savePrevalueEditor($datatype));
             }
             try {
                 $datatypeModel->addData($datatypeForm->getInputFilter()->getValues());
                 if ($datatypeModel->save()) {
                     $this->flashMessenger()->addSuccessMessage('This datatype has been saved');
                     return $this->redirect()->toRoute('development/datatype/edit', array('id' => $datatypeModel->getId()));
                 }
             } catch (Exception $e) {
                 throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
             }
             $this->flashMessenger()->addErrorMessage('Error during editing.');
             return $this->redirect()->toRoute('development/datatype/edit', array('id' => $datatypeModel->getId()));
         }
     }
     return array('form' => $datatypeForm, 'infos' => $datatype->getInfos());
 }
Ejemplo n.º 2
0
 /**
  * Test
  *
  * @return void
  */
 public function testLoadDatatype()
 {
     $this->assertInstanceOf('Gc\\Datatype\\AbstractDatatype', Model::loadDatatype(Registry::get('Application')->getServiceManager(), $this->object->getId()));
 }