Ejemplo n.º 1
0
 /**
  * Render the <base> element and some useful <link> elements.
  *
  * @param \Sitegear\View\ViewInterface $view
  * @param \Symfony\Component\HttpFoundation\Request $request
  */
 public function baseLinksComponent(ViewInterface $view, Request $request)
 {
     LoggerRegistry::debug('ContentModule::baseLinksComponent()');
     $view['base-url'] = UrlUtilities::absoluteUrl('/', $request);
     // TODO Canonicalise me
     $view['canonical-url'] = $request->getUri();
     $view['favicon-url'] = UrlUtilities::absoluteUrl('/favicon.ico', $request);
 }
Ejemplo n.º 2
0
 /**
  * Handles a form submission.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *
  * @throws \RuntimeException
  * @throws \OutOfBoundsException
  */
 public function formController(Request $request)
 {
     LoggerRegistry::debug('FormsModule::formController()');
     // Get the form and submission details
     $formKey = $request->attributes->get('slug');
     $values = $request->getMethod() === 'GET' ? $request->query->all() : $request->request->all();
     $this->registry()->setValues($formKey, array_merge($this->registry()->getValues($formKey), $values));
     $form = $this->registry()->getForm($formKey, $request);
     $targetUrl = null;
     $response = null;
     $currentStep = $this->registry()->getCurrentStep($formKey);
     $availableSteps = $this->registry()->getAvailableSteps($formKey);
     /** @var StepInterface $step Incorrect warning mark in PhpStorm 6.0 */
     $step = $form->getStep($currentStep);
     $fields = $step->getReferencedFields();
     $errors = null;
     $back = isset($values['back']) ? $values['back'] : false;
     unset($values['back']);
     // Set the values into the session so they can be displayed after redirecting.  Merge in with existing values
     // (e.g. from preceding steps).
     if ($back) {
         // The "back" button was clicked, try to go back a step.  No validation is necessary.
         $nextStep = $currentStep - 1;
         // Check that the previous step is not a one-way blocker.
         if (!in_array($nextStep, $availableSteps)) {
             throw new \OutOfBoundsException(sprintf('FormsModule cannot go to step %d in form "%s": step not available', $nextStep, $formKey));
         }
     } else {
         // The regular submit button was clicked, try to go to the next step; run validation and processors.
         $nextStep = $currentStep + 1;
         // Validation also sets the values and errors into the session.
         $errors = $this->registry()->validateForm($formKey, $fields, $values);
         if (empty($errors)) {
             // No errors, so execute processors.  Pass in all the values including those from previous steps.
             $response = $this->executeProcessors($step, $request, $this->registry()->getValues($formKey));
             // Reset the 'available steps' list if this is a one-way step.
             if ($step->isOneWay()) {
                 $availableSteps = array($nextStep);
             }
         }
     }
     // Validation passed (or was skipped) and all processors executed successfully (or were skipped).
     if (empty($errors)) {
         if ($nextStep >= $form->getStepsCount()) {
             // We're at the end of the form, and all the processors of the last step have run.  Reset the form and
             // redirect to the final target URL.
             $this->registry()->resetForm($formKey);
             if (!is_null($form->getTargetUrl())) {
                 $targetUrl = UrlUtilities::absoluteUrl($form->getTargetUrl(), $request);
             }
         } else {
             // The form is not yet complete, so update the session.
             if (!in_array($nextStep, $availableSteps)) {
                 $availableSteps[] = $nextStep;
             }
             $this->registry()->setAvailableSteps($formKey, $availableSteps);
             $this->registry()->setCurrentStep($formKey, $nextStep);
         }
     }
     // Return any of the following in order of preference: response returned by a processor method; redirection to
     // the target URL; redirection to the return URL extracted from the form URL; the form URL; the home page.
     if (!$response instanceof Response) {
         $response = new RedirectResponse($targetUrl ?: UrlUtilities::getReturnUrl($request, 'form-url'));
     }
     return $response;
 }
Ejemplo n.º 3
0
 /**
  * Handle the quantity update from the trolley details page.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function modifyTrolleyItemController(Request $request)
 {
     LoggerRegistry::debug('CustomerModule::modifyTrolleyItemController()');
     // Update the stored trolley data.
     $this->trolley()->modifyItem(intval($request->request->get('index')), intval($request->request->get('quantity')));
     // Go back to the page where the submission was made.
     return new RedirectResponse(UrlUtilities::absoluteUrl($this->getRouteUrl('trolley'), $request));
 }