You are here

public function YamlFormTestController::testForm in YAML Form 8

Returns a form to add a new test submission to a form.

Parameters

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

Return value

array The form submission form.

2 string references to 'YamlFormTestController::testForm'
yamlform.routing.yml in ./yamlform.routing.yml
yamlform.routing.yml
yamlform_node.routing.yml in modules/yamlform_node/yamlform_node.routing.yml
modules/yamlform_node/yamlform_node.routing.yml

File

src/Controller/YamlFormTestController.php, line 64

Class

YamlFormTestController
Provides route responses for form testing.

Namespace

Drupal\yamlform\Controller

Code

public function testForm(Request $request) {

  /** @var \Drupal\yamlform\YamlFormInterface $yamlform */

  /** @var \Drupal\Core\Entity\EntityInterface $source_entity */
  list($yamlform, $source_entity) = $this->requestHandler
    ->getYamlFormEntities();
  $values = [];

  // Set source entity type and id.
  if ($source_entity) {
    $values['entity_type'] = $source_entity
      ->getEntityTypeId();
    $values['entity_id'] = $source_entity
      ->id();
  }
  if ($request->query
    ->get('yamlform_id') == $yamlform
    ->id()) {
    return $yamlform
      ->getSubmissionForm($values);
  }

  // Generate date.
  $values['data'] = $this->generate
    ->getData($yamlform);
  return $yamlform
    ->getSubmissionForm($values);
}