You are here

public function WebformShareController::preview 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::preview()

Returns a preview of a webform to be shared.

Parameters

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

Return value

array A render array containing a review of the webform to be shared.

1 string reference to 'WebformShareController::preview'
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 162

Class

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

Namespace

Drupal\webform_share\Controller

Code

public function preview(Request $request) {
  $webform = $this->requestHandler
    ->getCurrentWebform();
  $source_entity = $this->requestHandler
    ->getCurrentSourceEntity([
    'webform',
  ]);
  $build = [];
  if ($this
    ->currentUser()
    ->isAuthenticated()) {
    $build['message'] = [
      '#type' => 'webform_message',
      '#message_message' => [
        'message' => [
          '#markup' => $this
            ->t('To test anonymous user access to the below embedded webform, please log out or open the below link in a new private or incognito window.'),
          '#suffix' => '<br/>',
        ],
        'link' => [
          '#type' => 'link',
          '#url' => Url::fromRoute('<current>'),
          '#title' => Url::fromRoute('<current>')
            ->setAbsolute()
            ->toString(),
        ],
      ],
      '#message_type' => 'info',
      '#message_close' => TRUE,
      '#message_storage' => WebformMessage::STORAGE_SESSION,
    ];
  }
  $build['preview'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'webform-share-iframe-container',
      ],
    ],
  ];
  $build['preview']['iframe'] = [
    '#type' => 'webform_share_iframe',
    '#webform' => $webform,
    '#source_entity' => $source_entity,
    '#javascript' => TRUE,
    '#options' => [
      'log' => TRUE,
    ],
    '#query' => $request->query
      ->all(),
  ];
  $build['#attached']['library'][] = 'webform_share/webform_share.admin';
  return $build;
}