Handles the event form submission.

@param string $formdata The event form data in a URI encoded param string
@return array The created or modified event
@throws moodle_exception
354566
public static function submit_create_update_form($formdata) {
        global $USER, $PAGE, $CFG;
        require_once($CFG->libdir."/filelib.php");

        // Parameter validation.
        $params = self::validate_parameters(self::submit_create_update_form_parameters(), ['formdata' => $formdata]);
        $context = \context_user::instance($USER->id);
        $data = [];

        self::validate_context($context);
        parse_str($params['formdata'], $data);

        $eventtype = isset($data['eventtype']) ? $data['eventtype'] : null;
        $coursekey = ($eventtype == 'group') ? 'groupcourseid' : 'courseid';
        $courseid = (!empty($data[$coursekey])) ? $data[$coursekey] : null;
        $editoroptions = \core_calendar\local\event\forms\create::build_editor_options($context);
        $formoptions = ['editoroptions' => $editoroptions, 'courseid' => $courseid];
        if ($courseid) {
            require_once($CFG->libdir . '/grouplib.php');
            $groupcoursedata = groups_get_course_data($courseid);
            if (!empty($groupcoursedata->groups)) {
                $formoptions['groups'] = [];
                foreach ($groupcoursedata->groups as $groupid => $groupdata) {
                    $formoptions['groups'][$groupid] = $groupdata->name;
                }
            }
        }

        if (!empty($data['id'])) {
            $eventid = clean_param($data['id'], PARAM_INT);
            $legacyevent = calendar_event::load($eventid);
            $legacyevent->count_repeats();
            $formoptions['event'] = $legacyevent;
            $mform = new update_event_form(null, $formoptions, 'post', '', null, true, $data);
        } else {
            $legacyevent = null;
            $mform = new create_event_form(null, $formoptions, 'post', '', null, true, $data);
        }

        if ($validateddata = $mform->get_data()) {
            $formmapper = new create_update_form_mapper();
            $properties = $formmapper->from_data_to_event_properties($validateddata);

            if (is_null($legacyevent)) {
                $legacyevent = new \calendar_event($properties);
                // Need to do this in order to initialise the description
                // property which then triggers the update function below
                // to set the appropriate default properties on the event.
                $properties = $legacyevent->properties(true);
            }

            if (!calendar_edit_event_allowed($legacyevent, true)) {
                print_error('nopermissiontoupdatecalendar');
            }

            $legacyevent->update($properties);
            $eventcontext = $legacyevent->context;

            file_remove_editor_orphaned_files($validateddata->description);

            // Take any files added to the description draft file area and
            // convert them into the proper event description file area. Also
            // parse the description text and replace the URLs to the draft files
            // with the @@PLUGIN_FILE@@ placeholder to be persisted in the DB.
            $description = file_save_draft_area_files(
                $validateddata->description['itemid'],
                $eventcontext->id,
                'calendar',
                'event_description',
                $legacyevent->id,
                create_event_form::build_editor_options($eventcontext),
                $validateddata->description['text']
            );

            // If draft files were found then we need to save the new
            // description value.
            if ($description != $validateddata->description['text']) {
                $properties->id = $legacyevent->id;
                $properties->description = $description;
                $legacyevent->update($properties);
            }

            $eventmapper = event_container::get_event_mapper();
            $event = $eventmapper->from_legacy_event_to_event($legacyevent);
            $cache = new events_related_objects_cache([$event]);
            $relatedobjects = [
                'context' => $cache->get_context($event),
                'course' => $cache->get_course($event),
            ];
            $exporter = new event_exporter($event, $relatedobjects);
            $renderer = $PAGE->get_renderer('core_calendar');

            return [ 'event' => $exporter->export($renderer) ];
        } else {
            return [ 'validationerror' => true ];
        }
    }
70780
public function preSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $form->getData();

        if (is_array($event->getData())) {
            $order = array_flip(array_keys($event->getData()));
            if (is_null($data)) {
                $data = array();
            }

            if ($data instanceof Collection) {
                $dataClone = $data->toArray();
                $data->clear();
                foreach ($order as $key => $value) {
                    $data->set($key, array_key_exists($key, $dataClone) ? $dataClone[$key] : null);
                }
            } elseif (is_array($data)) {
                $oldData = array_merge(array(), $data);
                $data = array();
                foreach ($order as $key => $value) {
                    $data[$key] = array_key_exists($key, $oldData) ? $oldData[$key] : null;
                }

            }
            $form->setData($data);
        }
    }
524314
public static function submit_tags_form($questionid, $contextid, $formdata) {
        global $DB, $CFG;

        $data = [];
        $result = ['status' => false];

        // Parameter validation.
        $params = self::validate_parameters(self::submit_tags_form_parameters(), [
            'questionid' => $questionid,
            'contextid' => $contextid,
            'formdata' => $formdata
        ]);

        $editingcontext = \context::instance_by_id($contextid);
        self::validate_context($editingcontext);
        parse_str($params['formdata'], $data);

        if (!$question = $DB->get_record_sql('
                SELECT q.*, qc.contextid
                FROM {question} q
                JOIN {question_categories} qc ON qc.id = q.category
                WHERE q.id = ?', [$questionid])) {
            print_error('questiondoesnotexist', 'question');
        }

        require_once($CFG->libdir . '/questionlib.php');
        require_once($CFG->dirroot . '/question/type/tags_form.php');

        $cantag = question_has_capability_on($question, 'tag');
        $questioncontext = \context::instance_by_id($question->contextid);
        $contexts = new \question_edit_contexts($editingcontext);

        $formoptions = [
            'editingcontext' => $editingcontext,
            'questioncontext' => $questioncontext,
            'contexts' => $contexts->all()
        ];

        $mform = new \core_question\form\tags(null, $formoptions, 'post', '', null, $cantag, $data);

        if ($validateddata = $mform->get_data()) {
            if ($cantag) {
                if (isset($validateddata->tags)) {
                    // Due to a mform bug, if there's no tags set on the tag element, it submits the name as the value.
                    // The only way to discover is checking if the tag element is an array.
                    $tags = is_array($validateddata->tags) ? $validateddata->tags : [];

                    core_tag_tag::set_item_tags('core_question', 'question', $validateddata->id,
                        $questioncontext, $tags);

                    $result['status'] = true;
                }

                if (isset($validateddata->coursetags)) {
                    $coursetags = is_array($validateddata->coursetags) ? $validateddata->coursetags : [];
                    core_tag_tag::set_item_tags('core_question', 'question', $validateddata->id,
                        $editingcontext->get_course_context(false), $coursetags);

                    $result['status'] = true;
                }
            }
        }

        return $result;
    }
673426
protected function getUpdateEvent($formData)
    {
        $event = new IndexEngineDriverConfigurationEvent();

        $event->setId($formData["id"]);
        $event->setTitle($formData["title"]);

        return $event;
    }
1030164
public function postSetData(FormEvent $event)
    {
        if ($event->getForm()->isRoot()) {
            // Collect basic information about each form
            $this->dataCollector->collectConfiguration($event->getForm());

            // Collect the default data
            $this->dataCollector->collectDefaultData($event->getForm());
        }
    }
1105328
public function onFormSuccess(FormEvent $event)
    {
        $form = $event->getForm();

        $result = $this->createResult($form);

        if ($form->getStoreResults()) {
            $this->storeResult($form, $result);
        }

        if ($form->getSendMail()) {
            $this->sendMail($form, $result);
        }

        $successUrl = $form->getSuccessUrl();

        if ($successUrl != null) {
            $redirectResponse = new RedirectResponse($successUrl);
            $redirectResponse->send();
        }
    }
888972
public function postSubmit(FormEvent $event)
    {
        $data = $event->getData();

        if ($this->itemDataClass !== null) {
            $itemMetadata = $this->getClassMetadata($this->itemDataClass);
            if ($itemMetadata !== null) {
                $this->cleanupCollection($data, $itemMetadata);
            }
        }
    }
640641
function process_form($formdata) {
        global $USER;

        $this->columns = array();
        if (!empty($formdata->itemids)) {
            if ($formdata->itemids=='-1') {
                //user deselected all items
            } else {
                foreach ($formdata->itemids as $itemid=>$selected) {
                    if ($selected and array_key_exists($itemid, $this->grade_items)) {
                        $this->columns[$itemid] =& $this->grade_items[$itemid];
                    }
                }
            }
        } else {
            foreach ($this->grade_items as $itemid=>$unused) {
                $this->columns[$itemid] =& $this->grade_items[$itemid];
            }
        }

        if (isset($formdata->key)) {
            if ($formdata->key == 1 && isset($formdata->iprestriction) && isset($formdata->validuntil)) {
                // Create a new key
                $formdata->key = create_user_key('grade/export', $USER->id, $this->course->id, $formdata->iprestriction, $formdata->validuntil);
            }
            $this->userkey = $formdata->key;
        }

        if (isset($formdata->decimals)) {
            $this->decimalpoints = $formdata->decimals;
        }

        if (isset($formdata->export_letters)) {
            $this->export_letters = $formdata->export_letters;
        }

        if (isset($formdata->export_feedback)) {
            $this->export_feedback = $formdata->export_feedback;
        }

        if (isset($formdata->export_onlyactive)) {
            $this->onlyactive = $formdata->export_onlyactive;
        }

        if (isset($formdata->previewrows)) {
            $this->previewrows = $formdata->previewrows;
        }

        if (isset($formdata->display)) {
            $this->displaytype = $formdata->display;

            // Used by grade exports which accept multiple display types.
            // If the checkbox value is 0 (unchecked) then remove it.
            if (is_array($formdata->display)) {
                $this->displaytype = array_filter($formdata->display);
            }
        }

        if (isset($formdata->updatedgradesonly)) {
            $this->updatedgradesonly = $formdata->updatedgradesonly;
        }
    }
271110
public function onPreSubmit(FormEvent $event)
    {
        $contentInfo = null;
        $contentLanguages = [];
        $form = $event->getForm();
        $data = $event->getData();

        if (isset($data['location'])) {
            try {
                $location = $this->locationService->loadLocation($data['location']);
            } catch (NotFoundException $e) {
                $location = null;
            }

            if (null !== $location) {
                $contentInfo = $location->getContentInfo();
                $versionInfo = $this->contentService->loadVersionInfo($contentInfo);
                $contentLanguages = $versionInfo->languageCodes;
            }
        }

        $this->addLanguageFields($form, $contentLanguages, $contentInfo);
    }
289992
public function handle_form_submission(local\forms\editstep &$mform, \stdClass $data) {
        $this->set_title($data->title);
        $this->set_content($data->content);
        $this->set_targettype($data->targettype);

        $this->set_targetvalue($this->get_target()->get_value_from_form($data));

        foreach (self::get_config_keys() as $key) {
            if (!$this->get_target()->is_setting_forced($key)) {
                if (isset($data->$key)) {
                    $value = $data->$key;
                } else {
                    $value = configuration::TOURDEFAULT;
                }
                if ($value === configuration::TOURDEFAULT) {
                    $this->set_config($key, null);
                } else {
                    $this->set_config($key, $value);
                }
            }
        }

        $this->persist();

        return $this;
    }
374360
public function preSubmit(FormEvent $event)
    {
        $data = $event->getData();
        $entity = $event->getForm()->getParent()->getConfig()->getDataClass();

        //if the remove checkbox is checked, clear the data
        if (isset($data[FileType::REMOVE_FIELDNAME]) &&  $data[FileType::REMOVE_FIELDNAME] === '1') {
            $event->setData(null);
            $data = null;
            return;
        }

        if (null !== ($file = $this->getUploadedFile($data))) {
            $this->validateFile($file, $event);
        } else {
            // nothing uploaded
            $hash = $data[FileType::HASH_FIELDNAME];
            $filename = $data[FileType::FILENAME_FIELDNAME];

            // check if there was a purgatory file (and the file is not tampered with)
            if (!empty($hash) && !empty($filename)
                && PurgatoryHelper::makeHash($event->getForm()->getPropertyPath(), $filename) === $hash
            ) {
                $path = $this->getPurgatoryFileManager()->getFilePath(
                    $entity,
                    $this->field,
                    $filename
                );

                $this->prepareData($data, $path, $event->getForm()->getPropertyPath());
                $event->setData($data);

                //use the original form data, so the field isn't empty
            } elseif ($event->getForm()->getData() !== null) {

                unset($data[FileType::HASH_FIELDNAME]);
                unset($data[FileType::FILENAME_FIELDNAME]);

                $originalFormData = $event->getForm()->getData();
                $path = $this->fileManager->getFilePath($entity, $this->field, $originalFormData);

                try {
                    $file = new File($path);
                    $data[FileType::UPLOAD_FIELDNAME] = $file;
                    $event->setData($data);
                } catch (FileNotFoundException $e) {
                    //do nothing
                }
            }
        }
    }
359312
public function check_data($formdata) {
        $field    = $this->_name;
        $operator = $field.'_op';

        if (array_key_exists($field, $formdata) and !empty($formdata->$operator)) {
            return array('operator' => (int)$formdata->$operator,
                         'value'    => (string)$formdata->$field);
        }

        return false;
    }
455324
public function createEmailEventType(array $eventData)
    {
        if ($this->findEmailEventType($eventData)) {
            throw new Exception("Email event type {$eventData['EVENT_NAME']} already exists");
        }
        $et = new CEventType;
        $res = $et->add($eventData);
        if (!$res) {
            throw new Exception("Can't create email event type {$eventData['EVENT_NAME']}: {$et->LAST_ERROR}");
        }

        return ["Email event type {$eventData['EVENT_NAME']}({$res}) created"];
    }
807060
public function postSubmit(FormEvent $event)
    {
        if ($event->getForm()->isRoot()) {
            // Collect the submitted data of each form
            $this->dataCollector->collectSubmittedData($event->getForm());

            // Assemble a form tree
            // This is done again after the view is built, but we need it here as the view is not always created.
            $this->dataCollector->buildPreliminaryFormTree($event->getForm());
        }
    }
781681
public function index(FormData $formData, $properties)
    {
        $id = $this->persistenceManager->getIdentifierByObject($formData);
        $formValues = json_decode($formData->getFormValues(), true);
        $formValues['_date'] = $formData->getDate();
        $data = $this->parseData($formValues, $properties);
        $index = $this->getIndex();
        $type = $this->getType($index, $formData->getFormIdentifier(), $properties);
        $document = new Document($type, $data, $id);
        $document->store();
    }
95885
public function submit(FormEvent $event)
    {
        $entity = $event->getData();
        
        if ($entity instanceof FileInterface && null === $entity->getId() && null === $entity->getHash()){
            $event->setData(null);
        }
    }
480591
protected function getCreationEvent($formData)
    {
        $brandCreateEvent = new BrandCreateEvent();

        $brandCreateEvent
            ->setLocale($formData['locale'])
            ->setTitle($formData['title'])
            ->setVisible($formData['visible'])
        ;

        return $brandCreateEvent;
    }