Remove unnecessary fields from form

@param array $requestData
@param Form $form
330312
private function cleanForm($requestData, Form $form)
    {
        $allowedField = array_keys($requestData);

        /** @var FormInterface[] $formFields */
        $formFields = $form->all();
        foreach ($formFields as $formField) {
            $fieldName = $formField->getName();

            if (!in_array($fieldName, $allowedField)) {
                $form->remove($fieldName);
            }
        }
    }
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);
            }
        }
    }
1209512
public function doNew($data, $form)
    {
        return $this->redirect(Controller::join_links($this->gridField->Link('item'), 'new'));
    }
682058
public function unsetData ($field = null)
		{
			if ($field) {
				unset($this->viewData[$field]);
			} else {
				$this->viewData = array();
			}

			return $this;
		}
1254580
protected function filterFields(&$data, $formKey = false) {
        $keys = array_keys($data);
        foreach ($keys as $key) {
            if ($formKey) {
                $key = $this->_fields[ $key ]['name'];
            }
            if (isset($this->_skips_[ $key ]) && $this->_skips_[ $key ]) {
                unset($data[ $key ]);
            }
        }
    }
673093
public static function delete_submission_for_context(assign_plugin_request_data $requestdata) {
        global $DB;

        \core_plagiarism\privacy\provider::delete_plagiarism_for_context($requestdata->get_context());

        $fs = get_file_storage();
        $fs->delete_area_files($requestdata->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA);

        // Delete records from assignsubmission_file table.
        $DB->delete_records('assignsubmission_file', ['assignment' => $requestdata->get_assign()->get_instance()->id]);
    }
302412
public function postRequireString($requestPath, array $postData)
    {
        $responseData = $this->post($requestPath, $postData);

        return self::requireString($responseData);
    }
828708
public synchronized void remove(int requestId)
   {
		if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "remove");
		
      if (!containsId(requestId))
      {
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) debugTraceTable("id ("+requestId+") not in table");
         throw new SIErrorException(nls.getFormattedMessage("REQIDTABLE_INTERNAL_SICJ0058", null, "REQIDTABLE_INTERNAL_SICJ0058")); // D226223
      }

      testReqIdTableEntry.requestId = requestId;
      table.remove(testReqIdTableEntry);

		if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "remove");
   }
621862
protected function removeReservedFields()
    {
        if (!$this->isMode(static::MODE_CREATE)) {
            return;
        }

        $reservedColumns = [
            $this->form->model()->getKeyName(),
            $this->form->model()->getCreatedAtColumn(),
            $this->form->model()->getUpdatedAtColumn(),
        ];

        $this->fields = $this->fields()->reject(function (Field $field) use ($reservedColumns) {
            return in_array($field->column(), $reservedColumns, true);
        });
    }
200215
public function delete($data, $form) {
		$className = $this->stat('tree_class');

		$record = DataObject::get_by_id($className, Convert::raw2sql($data['ID']));
		if($record && !$record->canDelete()) return Security::permissionFailure();
		if(!$record || !$record->ID) $this->httpError(404, "Bad record ID #" . (int)$data['ID']);
		$type = $record->ClassName;
		$record->delete();

		Session::set("FormInfo.Form_EditForm.formError.message", "Deleted $type");
		Session::set("FormInfo.Form_EditForm.formError.type", 'bad');

		$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.DELETED', 'Deleted.')));
		return $this->getResponseNegotiator()->respond(
			$this->request,
			array('currentform' => array($this, 'EmptyForm'))
		);
	}
129981
function clearSessionData($name = '', $clearErrors = true){
		if(!$name) $name = $this->owner->FormName();
		\Session::clear("FormInfo.{$name}.data");
		if($clearErrors) \Session::clear("FormInfo.{$name}.errors");
	}
532111
public function clearForm(BaseForm $form)
    {
        $formErrorInformation = $this->getSession()->getFormErrorInformation();

        $formClass = \get_class($form) . ':' . $form->getType();

        if (isset($formErrorInformation[$formClass])) {
            unset($formErrorInformation[$formClass]);
            $this->getSession()->setFormErrorInformation($formErrorInformation);
        }

        return $this;
    }
417491
public function removeAction(Request $request): Response
    {
        $isDraftForm = null !== $request->get(
            sprintf('version-remove-%s', VersionsTab::FORM_REMOVE_DRAFT)
        );

        $formName = $isDraftForm
            ? sprintf('version-remove-%s', VersionsTab::FORM_REMOVE_DRAFT)
            : sprintf('version-remove-%s', VersionsTab::FORM_REMOVE_ARCHIVED);

        $form = $this->formFactory->removeVersion(
            new VersionRemoveData(),
            $formName
        );
        $form->handleRequest($request);

        /** @var ContentInfo $contentInfo */
        $contentInfo = $form->getData()->getContentInfo();
        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (VersionRemoveData $data) {
                $contentInfo = $data->getContentInfo();

                foreach ($data->getVersions() as $versionNo => $selected) {
                    $versionInfo = $this->contentService->loadVersionInfo($contentInfo, $versionNo);
                    $this->contentService->deleteVersion($versionInfo);
                }

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Versions removed from '%name%' content.") */
                        'version.delete.success',
                        ['%name%' => $contentInfo->name],
                        'version'
                    )
                );

                return new RedirectResponse($this->generateUrl('_ezpublishLocation', [
                    'locationId' => $contentInfo->mainLocationId,
                    '_fragment' => VersionsTab::URI_FRAGMENT,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirect($this->generateUrl('_ezpublishLocation', [
            'locationId' => $contentInfo->mainLocationId,
            '_fragment' => VersionsTab::URI_FRAGMENT,
        ]));
    }
1316821
protected function processBodyOptions($requestData = [])
    {
        if (!empty($requestData['multipart'])) {
            $body = [];

            foreach ($requestData['multipart'] as $key => $value) {
                // Hack to cast FALSE to '0' instead of empty string.
                if (is_bool($value)) {
                    $value = (int) $value;
                }

                if (is_array($value)) {
                    foreach ($value as $_item) {
                        $body[] = [
                            'name' => $key . '[]',
                            'contents' => (string) $_item,
                        ];
                    }
                }
                else {
                    $body[] = [
                        'name' => $key,
                        'contents' => $value,
                    ];
                }
            }

            $requestData['multipart'] = $body;
        }

      return $requestData;
    }
442990
public function postRequireArray($requestPath, array $postData)
    {
        $responseData = $this->post($requestPath, $postData);

        return self::requireArray($responseData);
    }
1165605
public function createSubscription(Create\RequestData $requestData)
    {
        $request = new Create\Request($requestData);

        return $this->sendRequest($request, Create\ApiResponse::class);
    }
889558
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) {
        global $DB;

        $fs = new \file_storage();
        $fs->delete_area_files($requestdata->get_context()->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT,
            ASSIGNFEEDBACK_COMMENTS_FILEAREA, $requestdata->get_pluginobject()->id);

        $DB->delete_records('assignfeedback_comments', ['assignment' => $requestdata->get_assignid(),
                'grade' => $requestdata->get_pluginobject()->id]);
    }