You are here

public function WebformShareController::page in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_share/src/Controller/WebformShareController.php \Drupal\webform_share\Controller\WebformShareController::page()

Returns a webform to be shared as the page of an iframe.

Parameters

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

string|null $library: The iframe JavaScript library.

string|null $version: The iframe JavaScript library version.

Return value

array The webform rendered in a page template with only the content.

See also

\Drupal\webform_share\Theme\WebformShareThemeNegotiator

page--webform-share.html.twig

webform_share.libraries.yml

1 string reference to 'WebformShareController::page'
webform_share.routing.yml in modules/webform_share/webform_share.routing.yml
modules/webform_share/webform_share.routing.yml

File

modules/webform_share/src/Controller/WebformShareController.php, line 85

Class

WebformShareController
Provides route responses for webform share page, script, and embed.

Namespace

Drupal\webform_share\Controller

Code

public function page(Request $request, $library = NULL, $version = NULL) {
  $webform = $this->requestHandler
    ->getCurrentWebform();
  $source_entity = $this->requestHandler
    ->getCurrentSourceEntity([
    'webform',
  ]);
  $build = [];

  // Webform.
  $build['webform'] = [
    '#type' => 'webform',
    '#webform' => $webform,
    '#source_entity' => $source_entity,
    '#prefix' => '<div class="webform-share-submission-form">',
    '#suffix' => '</div>',
  ];

  // Attachments.
  $build['#attached']['library'][] = 'webform_share/webform_share.page';
  if ($library && $version) {
    $build['#attached']['library'][] = "webform_share/libraries.{$library}.{$version}";
  }

  // Add setting notifying AjaxCommand that this page is shared via an
  // embeddded iframe.
  // @see Drupal.AjaxCommands.prototype.webformRefresh
  $build['#attached']['drupalSettings']['webform_share']['page'] = TRUE;
  return $build;
}