/** * Display a form to create a new backend */ public function createbackendAction() { $form = new BackendConfigForm(); $form->setTitle($this->translate('Add New Backend')); $form->setIniConfig($this->Config('backends')); $form->setResourceConfig(ResourceFactory::getResourceConfigs()); $form->setRedirectUrl('monitoring/config'); $form->handleRequest(); $this->view->form = $form; }
/** * Create a new monitoring backend */ public function createbackendAction() { $form = new BackendConfigForm(); $form->setRedirectUrl('monitoring/config'); $form->setTitle($this->translate('Create New Monitoring Backend')); $form->setIniConfig($this->Config('backends')); try { $form->setResourceConfig(ResourceFactory::getResourceConfigs()); } catch (ConfigurationError $e) { if ($this->hasPermission('config/application/resources')) { Notification::error($e->getMessage()); $this->redirectNow('config/createresource'); } throw $e; // No permission for resource configuration, show the error } $form->setOnSuccess(function (BackendConfigForm $form) { try { $form->add(array_filter($form->getValues())); } catch (Exception $e) { $form->error($e->getMessage()); return false; } if ($form->save()) { Notification::success(t('Monitoring backend successfully created')); return true; } return false; }); $form->handleRequest(); $this->view->form = $form; $this->render('form'); }