public static function WebformShareScript::preRenderWebformShareScript in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_share/src/Element/WebformShareScript.php \Drupal\webform_share\Element\WebformShareScript::preRenderWebformShareScript()
Webform share iframe element pre render callback.
File
- modules/
webform_share/ src/ Element/ WebformShareScript.php, line 36
Class
- WebformShareScript
- Provides a render element that creates a <script> tag to share a webform.
Namespace
Drupal\webform_share\ElementCode
public static function preRenderWebformShareScript($element) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $element['#webform'];
/** @var \Drupal\Core\Entity\EntityInterface $source_entity */
$source_entity = $element['#source_entity'];
$route_name = 'entity.webform.share_script';
$route_parameters = [
'webform' => $webform
->id(),
];
$route_options = QueryStringWebformSourceEntity::getRouteOptionsQuery($source_entity);
// Append prepopulate and variant query to route options.
if ($element['#query']) {
$route_options += [
'query' => [],
];
$route_options['query'] += $element['#query'];
}
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
$script = preg_replace('#^https?:#', '', $url
->setAbsolute()
->toString());
$element['#script'] = $script;
return $element;
}