Need to update the edit form AFTER it's been transformed to read only so that the workflow stuff is still
allowed to be added with 'write' permissions

@param Form $form
514536
public function updateEditForm(Form $form)
    {
        Requirements::javascript('symbiote/silverstripe-advancedworkflow:client/dist/js/advancedworkflow.js');
        /** @var WorkflowService $service */
        $service = singleton(WorkflowService::class);
        /** @var DataObject|WorkflowApplicable $record */
        $record = $form->getRecord();
        $active = $service->getWorkflowFor($record);

        if ($active) {
            $fields = $form->Fields();
            $current = $active->CurrentAction();
            $wfFields = $active->getWorkflowFields();

            $allowed = array_keys($wfFields->saveableFields());
            $data = [];
            foreach ($allowed as $fieldName) {
                $data[$fieldName] = $current->$fieldName;
            }

            $fields->findOrMakeTab(
                'Root.WorkflowActions',
                _t('Workflow.WorkflowActionsTabTitle', 'Workflow Actions')
            );
            $fields->addFieldsToTab('Root.WorkflowActions', $wfFields);

            $form->loadDataFrom($data);

            // Set the form to readonly if the current user doesn't have permission to edit the record, and/or it
            // is in a state that requires review
            if (!$record->canEditWorkflow() && !$fields->isReadonly()) {
                $fields->makeReadonly();
            }

            $this->owner->extend('updateWorkflowEditForm', $form);
        }
    }
523137
public function saveTransversalSubmit(array &$form, FormStateInterface $form_state)
    {
        if ($this->manager->getSiteContext()->isTemporary()) {
            $this->manager->getSiteContext()->commit();

            drupal_set_message(t("Changed have been saved"));

            $form_state->setRedirect(
                current_path(),
                ['query' => drupal_get_query_parameters(null, ['q', ContextManager::PARAM_SITE_TOKEN])]
            );
        }
    }
181944
public function success(Form $form) : void
    {
        if ($this->presenter->isAjax())
        {
            $values = $form->getValues();

            try
            {
                $this->onPageManager->savePrimary($this->activePage, $values->title, $values->description, $values->indexingType, $values->isCanonical);

                $this->presenter->notificationAjax(
                    'On-Page faktory',
                    'On-Page faktory byly úspěšně upraveny.',
                    'success',
                    FALSE
                );

                $this->onSave();
            }
            catch (DatabaseException $exception)
            {
                $this->presenter->notificationAjax(
                    'Chyba',
                    $exception->getMessage(),
                    'error'
                );
            }
        }
    }
654394
public function updateEditForm($form)
    {
        if ($doadd = Config::inst()->get('ModelAdmin', 'addbetterimporters')) {
            $modelclass = $this->owner->modelClass;
            $grid = $form->Fields()->fieldByName($modelclass);
            $config =  $grid->getConfig();

            //don't proceed if there is already an importer
            if ($config->getComponentByType("GridFieldImporter")) {
                return;
            }
            //don't proceed if can't create
            if (!singleton($modelclass)->canCreate(Member::currentUser())) {
                return;
            }
            //allow config to avoid adding when there are existing importers
            $importerClasses = $this->owner->stat('model_importers');
            if (
                $doadd === "scaffolded" &&
                !is_null($importerClasses) &&
                isset($importerClasses[$modelclass])
            ) {
                return;
            }
            
            //add the component
            $config->addComponent(new GridFieldImporter('before'));
        }
    }
1237080
public function editFormSucceeded(Form $form, ArrayHash $values): void
	{
		try {
			$this->currentUser->setUsername($values->username);
		} catch (UniqueConstraintViolationException $ex) {
			$form->addError('cms.user.duplicityUsername');
			return;
		} catch (InvalidArgumentException $ex) {
			$form->addError('cms.user.invalidUsername');
			return;
		}

		try {
			$this->currentUser->setEmail($values->email);
		} catch (UniqueConstraintViolationException $ex) {
			$form->addError('cms.user.duplicityEmail');
			return;
		} catch (InvalidArgumentException $ex) {
			$form->addError('cms.user.invalidUsername');
			return;
		}

		try {
			$this->currentUser->setPhone($values->phone ?: null);
		} catch (InvalidArgumentException $ex) {
			$form->addError('cms.user.invalidPhone');
			return;
		}

		$this->currentUser->firstName = $values->firstName;
		$this->currentUser->surname = $values->surname;
		$this->currentUser->roles->set($values->roles);

		$language = $this->localeService->getById($values->language);
		$this->currentUser->language = $language === null ? null : $language->name;

		$this->orm->persistAndFlush($this->currentUser);

		$this->flashNotifier->success('cms.user.dataSaved');
		$this->restoreBacklink();
	}
565823
public function doSave($data, $form)
    {
        $recordType = $this->getRecordType();
        $record = $recordType::create();
        $form->saveInto($record);
        $record->write();
        $this->redirect($this->Link());
    }
424004
protected function setDisabledForm(Form $form, bool $disabled = TRUE) : void
    {
        foreach ($form->getComponents() as $component)
        {
            $component->setDisabled($disabled);
        }
    }
56754
function handlePermissionUpdate() {
            permissionArea.find("form").submit(function (e) {
                e.preventDefault();
                //console.log(e);
                var form = e.currentTarget;
                appendFormFields(form);
                Rocket.Util.submitFormAsync(form, function (responseData) {
                    //console.log(responseData);
                    if (responseData && responseData.status && responseData.status == "success") {
                        location.reload();
                    }
                });
            });
        }
518862
public function passwordFormSucceeded(Form $form, ArrayHash $values): void
	{
		try {
			$this->profile->setPassword($values->password, $values->oldPassword);
			$this->orm->persistAndFlush($this->profile);
			$this->flashNotifier->success('cms.user.passwordChanged');
		} catch (AuthenticationException $e) {
			$form->addError('cms.user.incorrectPassword');
		}
		if ($this->isAjax()) {
			$this->redrawControl('passwordForm');
		}
	}
771963
public function setForm($form)
    {
        foreach ($this->fields as $field) {
            $field->setForm($form);
        }
        
        return parent::setForm($form);
    }
277768
public function done($data, $form) {
		if (!$this->data()->canEdit()) {
			return Security::permissionFailure($this);
		}
		// save stuff then reuse the edit action
		$this->savePage($this->data(), $form);

		return $this->redirect($this->data()->Link() . '?stage=Stage');
	}
517669
public function save(Form $form)
    {
        $this->em->persist($form);
        $this->em->flush();

        return $form;
    }
1006090
public function doAddNew($data, $form)
    {
        $obj = Object::create($this->addNewClass);
        if (!$obj->canCreate()) {
            return Security::permissionFailure(Controller::curr(), "You don't have permission to create this object");
        }
        $form->saveInto($obj);

        try {
            $obj->write();
        } catch (Exception $e) {
            $form->setMessage($e->getMessage(), 'error');
            return $form->forTemplate();
        }

        $callback = $this->sourceCallback;
        $items = $callback($obj);
        $this->owner->setSource($items);

        // if this field is a multiselect field, we add the new Object ID to the existing
        // options that are selected on the field then set that as the value
        // otherwise we just set the new Object ID as the value
        if (isset($data['existing'])) {
            $existing = $data['existing'];
            $value = explode(',', $existing);
            $value[] = $obj->ID;
        } else {
            $value = $obj->ID;
        }

        $this->owner->setValue($value);
        // NOTE(Jake): Below line causes cyclic issues, I assume it's not necessary.
        //$this->owner->setForm($form);
        return $this->owner->FieldHolder();
    }
1066097
public function updateSearchForm(Form $form)
    {
        if ($this->isVersioned()) {
            
            // Obtain Field List:
            
            $fields = $form->Fields();
            
            // Create Filter Field:
            
            $filter = DropdownField::create(
                'q[FilterClass]',
                $this->owner->getStatusFieldTitle(),
                $this->getFilterClassOptions(),
                $this->getFilterClass()
            )->setForm($form);
            
            // Add Filter Field to Form:
            
            if ($this->owner->StatusFieldBefore) {
                $fields->insertBefore(sprintf('q[%s]', $this->owner->StatusFieldBefore), $filter);
            } elseif ($this->owner->StatusFieldAfter) {
                $fields->insertAfter(sprintf('q[%s]', $this->owner->StatusFieldAfter), $filter);
            } else {
                $fields->push($filter);
            }
            
        }
    }
720471
function startForm(&$form){
        global $PAGE;
        $this->_reqHTML = $form->getReqHTML();
        $this->_elementTemplates = str_replace('{req}', $this->_reqHTML, $this->_elementTemplates);
        $this->_advancedHTML = $form->getAdvancedHTML();
        $this->_collapseButtons = '';
        $formid = $form->getAttribute('id');
        parent::startForm($form);
        if ($form->isFrozen()){
            $this->_formTemplate = "\n<div id=\"$formid\" class=\"mform frozen\">\n{collapsebtns}\n{content}\n</div>";
        } else {
            $this->_formTemplate = "\n<form{attributes}>\n\t<div style=\"display: none;\">{hidden}</div>\n{collapsebtns}\n{content}\n</form>";
            $this->_hiddenHtml .= $form->_pageparams;
        }

        if ($form->is_form_change_checker_enabled()) {
            $PAGE->requires->yui_module('moodle-core-formchangechecker',
                    'M.core_formchangechecker.init',
                    array(array(
                        'formid' => $formid
                    ))
            );
            $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
        }
        if (!empty($this->_collapsibleElements)) {
            if (count($this->_collapsibleElements) > 1) {
                $this->_collapseButtons = $this->_collapseButtonsTemplate;
                $this->_collapseButtons = str_replace('{strexpandall}', get_string('expandall'), $this->_collapseButtons);
                $PAGE->requires->strings_for_js(array('collapseall', 'expandall'), 'moodle');
            }
            $PAGE->requires->yui_module('moodle-form-shortforms', 'M.form.shortforms', array(array('formid' => $formid)));
        }
        if (!empty($this->_advancedElements)){
            $PAGE->requires->js_call_amd('core_form/showadvanced', 'init', [$formid]);
        }
    }
1056069
public function restorePasswordFormSucceeded(Form $form, ArrayHash $values): void
	{
		$session = $this->getSession('cms/restorePassword');
		$email = $session->{$values->hash};
		$session->remove();

		$user = $this->orm->users->getByEmail($email);
		if ($user) {
			$user->setPassword($values->password);
			$this->orm->persistAndFlush($user);
			$this->flashNotifier->success('cms.user.passwordChanged');
		} else {
			$this->flashNotifier->error('cms.permissions.accessDenied');
		}
		$this->redirect(":{$this->module}:Sign:in");
	}
656857
protected function populatePreviousData(Form $form) {
		$prepops = EventAttendee::config()->prepopulated_fields;
		if (!$prepops) {
			return;
		}
		$latestattendee = $this->registration->Attendees()
			->sort("LastEdited", "DESC")->first();
		if($latestattendee){
			$form->loadDataFrom($latestattendee, Form::MERGE_DEFAULT, $prepops);	
		}
	}