/** * @return Form */ public function getDataTransferForm($request) { // Performs canView permission check by limiting visible projects $envs = $this->getCurrentProject()->DNEnvironmentList()->filterByCallback(function ($item) { return $item->canBackup(); }); if (!$envs) { return new SS_HTTPResponse("Environment '" . Convert::raw2xml($request->latestParam('Environment')) . "' not found.", 404); } $form = new Form($this, 'DataTransferForm', new FieldList(new HiddenField('Direction', false, 'get'), new DropdownField('EnvironmentID', 'Environment', $envs->map()), new DropdownField('Mode', 'Transfer', DNDataArchive::get_mode_map())), new FieldList(FormAction::create('doDataTransfer', 'Create')->addExtraClass('btn'))); $form->setFormAction($request->getURL() . '/DataTransferForm'); return $form; }
/** * @param SS_HTTPRequest|null $request * * @return Form */ public function getDataTransferForm(SS_HTTPRequest $request = null) { // Performs canView permission check by limiting visible projects $envs = $this->getCurrentProject()->DNEnvironmentList()->filterByCallback(function ($item) { return $item->canBackup(); }); if (!$envs) { return $this->environment404Response(); } $form = Form::create($this, 'DataTransferForm', FieldList::create(HiddenField::create('Direction', null, 'get'), DropdownField::create('EnvironmentID', 'Environment', $envs->map())->setEmptyString('Select an environment'), DropdownField::create('Mode', 'Transfer', DNDataArchive::get_mode_map())), FieldList::create(FormAction::create('doDataTransfer', 'Create')->addExtraClass('btn'))); $form->setFormAction($this->getRequest()->getURL() . '/DataTransferForm'); return $form; }
/** * @param \SS_HTTPRequest|null $request * * @return Form */ public function getDataTransferForm(\SS_HTTPRequest $request = null) { // Performs canView permission check by limiting visible projects $envs = $this->getCurrentProject()->DNEnvironmentList()->filterByCallback(function ($item) { return $item->canBackup(); }); if (!$envs) { return $this->environment404Response(); } $items = []; $disabledEnvironments = []; foreach ($envs as $env) { $items[$env->ID] = $env->Title; if ($env->CurrentBuild() === false) { $items[$env->ID] = sprintf("%s - requires initial deployment", $env->Title); $disabledEnvironments[] = $env->ID; } } $envsField = DropdownField::create('EnvironmentID', 'Environment', $items)->setEmptyString('Select an environment'); $envsField->setDisabledItems($disabledEnvironments); $formAction = FormAction::create('doDataTransfer', 'Create')->addExtraClass('btn'); if (count($disabledEnvironments) === $envs->count()) { $formAction->setDisabled(true); } $form = Form::create($this, 'DataTransferForm', FieldList::create(HiddenField::create('Direction', null, 'get'), $envsField, DropdownField::create('Mode', 'Transfer', DNDataArchive::get_mode_map())), FieldList::create($formAction)); $form->setFormAction($this->getRequest()->getURL() . '/DataTransferForm'); return $form; }