Dynamic default values in WebForm Drupal 8.x
You can place a webform anywhere in code, examples are a controller, a block or a preprocess hook in a theme. Put the dynamic default values in #default_data:

/src/Controller/WebformController.php

&lt;?php

namespace Drupal\mymodule\Controller;

use Drupal\Core\Controller\ControllerBase;

/**
 * A webform controller.
 */
class WebformController extends ControllerBase {

  /**
   * {@inheritdoc}
   */
  public function webform() {

    // generate dynamic default values
    $name = 'John Doe';
    $message = 'This content is generated dynamically.';

    // add this to a webform
    $build['form']  = [
      '#type' =&gt; 'webform',
      '#webform' =&gt; 'contact',
      '#default_data' =&gt; [
        'name' =&gt; $name,
        'message' =&gt; $message,
      ],
    ];

    return $build;
  }

}


mymodule.routing.yml

mymodule.webform:
  path: '/mywebform'
  defaults:
    _controller: '\Drupal\mymodule\Controller\WebformController:webform'
    _title: 'My Webform'
  requirements:
    _permission: 'access content'