You are here

public function YamlFormTestRemotePostController::index in YAML Form 8

Returns a form confirmation page.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

string $type: Type of remote post request (insert, update, or delete)

Return value

\Symfony\Component\HttpFoundation\JsonResponse A JSON response with request status and message.

1 string reference to 'YamlFormTestRemotePostController::index'
yamlform_test.routing.yml in tests/modules/yamlform_test/yamlform_test.routing.yml
tests/modules/yamlform_test/yamlform_test.routing.yml

File

tests/modules/yamlform_test/src/Controller/YamlFormTestRemotePostController.php, line 25

Class

YamlFormTestRemotePostController
Provides route responses for remote post tests.

Namespace

Drupal\yamlform_test\Controller

Code

public function index(Request $request, $type) {
  $post_data = $request->request
    ->all();
  if (strpos(print_r($post_data, TRUE), 'FAIL') !== FALSE) {
    $json = [
      'status' => 'fail',
      'message' => (string) $this
        ->t('Failed to process @type request.', [
        '@type' => $type,
      ]),
    ];
    return new JsonResponse($json, 500);
  }
  else {
    $json = [
      'status' => 'success',
      'message' => (string) $this
        ->t('Processed @type request.', [
        '@type' => $type,
      ]),
    ];
    return new JsonResponse($json, 200);
  }
}