Persists the document using the given information.

@param Request $request
@param $formType
@param $document
@param $language

@throws InvalidFormException
@throws MissingParameterException
765666
private function persistDocument(Request $request, $formType, $document, $language)
    {
        $data = $request->request->all();

        if ($request->query->has('parentId')) {
            $data['parent'] = $request->query->get('parentId');
        }

        $form = $this->createForm(
            $formType,
            $document,
            [
                // disable csrf protection, since we can't produce a token, because the form is cached on the client
                'csrf_protection' => false,
                'webspace_key' => $this->getWebspace($request),
            ]
        );
        $form->submit($data, false);

        if (array_key_exists('author', $data) && null === $data['author']) {
            $document->setAuthor(null);
        }

        if (!$form->isValid()) {
            throw new InvalidFormException($form);
        }

        $this->getDocumentManager()->persist(
            $document,
            $language,
            [
                'user' => $this->getUser()->getId(),
                'clear_missing_content' => false,
            ]
        );
    }
817267
public function setFormFieldTypeRangedFrom($formFieldTypeRangedFrom)
    {
        if (!is_string($formFieldTypeRangedFrom) || empty($formFieldTypeRangedFrom)) {
            throw new InvalidArgumentException('"Form field type ranged from" argument must be string and must not be empty.');
        }

        $this->formFieldTypeRangedFrom = $formFieldTypeRangedFrom;

        return $this;
    }
507396
public function changeFieldTypeAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw $this->createAccessDeniedException();
        }

        $type = $request->get('type');
        $fieldType = $this->fieldManager->getFieldTypeByCode($type);

        $formName = $request->get('formPath');

        $formPath = $this->getFormPath($formName);
        // Extract first item to create named builder
        $rootPath = array_shift($formPath);
        $formChildren = $formPath;
        $rootFormBuilder = $this->formFactory->createNamedBuilder($rootPath, FormType::class, null, ['translation_domain' => 'AdvancedContentBundle']);
        // Create formBuilder recursively, according to formName
        $formBuilder = $this->createEmbeddedForm($formPath, $rootFormBuilder);
        $formBuilder->add('options', FormType::class);

        $fieldType->addFieldOptions($formBuilder);

        $form = $rootFormBuilder->getForm();
        foreach ($formChildren as $child) {
            $form = $form->get($child);
        }
        $formView = $form->createView();

        $response = [
            'success' => 1,
            'optionHtml'    => $this->renderView('@SherlockodeAdvancedContent/ContentType/field_options_render.html.twig', [
                'options' => $formView['options'],
            ]),
            'layoutHtml'    => $this->renderView('@SherlockodeAdvancedContent/ContentType/field_layout.html.twig', [
                'form' => $formView,
            ])
        ];

        return new JsonResponse($response);
    }
1038252
public function edit(Request $request, FormBuilder $formBuilder, $page)
    {
        // Set roles that have access
        $request->user()->authorizeRoles(['admin', 'editor']);

        $page = Page::withTrashed()->findOrFail($page);

        // Get pagetype, or fail..
        $pagetype = PageType::where('model', $page->pagetype_model)->first();

        // Get form fields
        $fields = $pagetype->fields ?: [];

        // Get content
        $content = $page->content;

        // Build the form content[body]
        $form = $formBuilder->createByArray($fields, [
            'method' => 'PUT',
            'url' => route('admin.pages.page.update', $page),
            'name' => 'content',
            'model' => $content
        ]);

        return view('page::pages.edit', [
            'page' => $page,
            'pagetype' => $pagetype,
            'form' => $form
        ]);
    }
396638
public function handleRequest(Request $request, Language $language)
    {
        $uri   = $this->getRequestedPath($request, $language);
        $route = $this->repository->getByPath($uri, $language->code);

        if (empty($route) || $route->getRoutable() === null) {
            throw new NotFoundHttpException();
        }

        if (!$this->routeCanBeShown($route)) {
            throw new NotFoundHttpException();
        }

        event(new RouteMatched($route, $request));

        return $route->getRoutable()->handle($language);
    }
1142444
protected function processActionFormCreate(Request $request, ActionMapping $mapping) {
        $formClass = $mapping->getFormClassName();
        if (!$formClass)
            return null;

        /** @var ActionForm $form */
        $form = null;

        // if the form has "session" scope try to find an existing form in the session
        if ($mapping->isSessionScope())
            $form = $request->getSession()->getAttribute($formClass);       // implicitely starts a session

        // if none was found create a new instance
        /** @var ActionForm $form */
        if (!$form) $form = new $formClass($request);

        // if a DispatchAction is used read the action key
        $actionClass = $mapping->getActionClassName();
        if (is_subclass_of($actionClass, DispatchAction::class))
            $form->initActionKey($request);

        // populate the form
        $form->populate($request);

        // store the ActionForm in the request
        $request->setAttribute(ACTION_FORM_KEY, $form);

        // if the form has "session" scope also store it in the session
        if ($mapping->isSessionScope())
            $request->getSession()->setAttribute($formClass, $form);

        return $form;
    }
551713
private function handleRequest(FormTypeInterface $type, Request $request)
    {
        $image = new Image();

        $form = $this->createForm($type, $image, [
            'method' => 'POST',
        ]);

        $form->handleRequest($request);

        if (!$form->isValid()) {
            throw $this->createNotFoundException('Invalid request' . $form->getErrorsAsString());
        }

        $em = $this->getDoctrine()->getManager();
        $em->persist($image);
        $em->flush();

        return new Response($this->get('serializer')->serialize(['image' => $image], $request->attributes->get('_format')));
    }
741848
protected function generateSchemaForForm($formName, HTTPRequest $request)
    {
        switch ($formName) {
            // Get schema for history form
            case self::FORM_NAME_VERSION:
                $form = $this->getVersionForm([
                    'RecordClass' => $request->getVar('RecordClass'),
                    'RecordID' => $request->getVar('RecordID'),
                    'RecordVersion' => $request->getVar('RecordVersion'),
                ]);
                break;
            case self::FORM_NAME_COMPARE:
                $form = $this->getCompareForm([
                    'RecordClass' => $request->getVar('RecordClass'),
                    'RecordID' => $request->getVar('RecordID'),
                    'RecordVersionFrom' => $request->getVar('RecordVersionFrom'),
                    'RecordVersionTo' => $request->getVar('RecordVersionTo'),
                ]);
                break;
            default:
                throw new InvalidArgumentException('Invalid form name passed to generate schema: ' . $formName);
        }

        // Respond with this schema
        $response = $this->getResponse();
        $response->addHeader('Content-Type', 'application/json');
        $schemaID = $this->getRequest()->getURL();

        return $this->getSchemaResponse($schemaID, $form);
    }
934117
public function setDocumentType(\Core\Entity\DocumentType $documentType = null) {
        $this->documentType = $documentType;

        return $this;
    }
1287830
public function update(Request $request, FormBuilder $formBuilder, $page)
    {
        // Set roles that have access
        $request->user()->authorizeRoles(['admin', 'editor']);

        // Get page
        $page = Page::withTrashed()->findOrFail($page);

        // Get pagetype, or fail..
        $pagetype = PageType::where('model', $page->pagetype_model)->first();

        // Get fields
        $fields = $pagetype->fields ?: [];

        // Build the form
        $form = $formBuilder->createByArray($fields, [
            'method' => 'POST',
            'url' => route('admin.pages.page.store'),
            'name' => 'content'
        ]);

        // It will automatically use current request, get the rules, and do the validation
        if (!$form->isValid()) {
            return redirect()->back()->withErrors($form->getErrors())->withInput();
        }

        // Page data
        $page->title = $request->input('title');
        $page->content = $request->input('content');
        $page->status = $request->input('status') ? 2 : 1;

        $page->update();

        flash('The page was successfully updated')->success();

        return redirect()->route('admin.pages.index');
    }
540941
public function store(ImageFormRequest $request, Page $page): void
    {
        $page->addMediaFromRequest('file')
             ->sanitizingFileName(function ($fileName) {
                 return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION);
             })
             ->toMediaCollection('default', config('cortex.pages.media.disk'));
    }
446382
public function onPreSetData(FormEvent $event)
    {
        $contentInfo = null;
        $contentLanguages = [];
        $form = $event->getForm();
        $data = $event->getData();
        $location = $data->getLocation();

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

        $this->addLanguageFields($form, $contentLanguages, $contentInfo);
    }
294771
public function store(Request $request, FormBuilder $formBuilder)
    {
        // Set roles that have access
        $request->user()->authorizeRoles(['admin', 'editor']);

        // Get pagetype, or fail..
        $pagetype = PageType::where('model', $request->pagetype_model)->first();

        // Get form fields
        $fields = $pagetype->fields ?: [];

        // Build the form
        $form = $formBuilder->createByArray($fields, [
            'method' => 'POST',
            'url' => route('admin.pages.page.store'),
            'name' => 'content'
        ]);

        // Validate required page fields (title, slug, status etc)
        $request->validate([
            'title' => 'bail|required|min:2|max:255',
            // 'slug' => 'required|unique',
        ]);


        // Validate custom form fields
        if (!$form->isValid()) {
            return redirect()->back()->withErrors($form->getErrors())->withInput();
        }

        // Store the post
        $page = new Page;

        // Page data
        $page->uuid = (string) Str::uuid();
        $page->title = $request->input('title');
        $page->pagetype_model = $request->input('pagetype_model');
        $page->content = $request->input('content');
        $page->status = $request->input('status') ? 2 : 1;
        $page->lang_id = 1;
        $page->user_id = 1;

        $page->save();

        flash('The page was successfully saved')->success();

        return redirect()->route('admin.pages.index');
    }
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();
        }
    }
190204
public function setDocumentType($documentType)
    {
    	if (!in_array($documentType, self::getDocumentTypeValues())) {
    		throw new \InvalidArgumentException(
				sprintf('Invalid value for document.documentType : %s.', $documentType)
    		);
    	}
    	
        $this->documentType = $documentType;
    
        return $this;
    }
933915
public function postAction(Request $request)
    {
        $document = $this->documentManager->create(Structure::TYPE_SNIPPET);
        $form = $this->processForm($request, $document);

        return $this->handleView($form->getData());
    }
711401
public function create(LanguageListener $listener, Request $request)
    {
        if ($request->isMethod('post')) {
            $form = $this->presenter->form();
            if (!$form->isValid()) {
                return $listener->createFailed($form->getMessageBag());
            }
            try {
                $data = $form->getData();
                $this->languageRepository->insert($data);
            } catch (Exception $ex) {
                Log::warning($e);
                return $listener->createFailed($ex->getMessage());
            }
            return $listener->createSucceed();
        }
        return $this->presenter->create();
    }