function template_preprocess_html__webform_share in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_share/webform_share.module \template_preprocess_html__webform_share()
Prepares variables for the webform share page HTML templates.
File
- modules/
webform_share/ webform_share.module, line 210 - Allows webforms to be shared on other websites using an iframe.
Code
function template_preprocess_html__webform_share(&$variables) {
// Make sure the variables are preprocessed.
// @see template_preprocess_page()
if (!isset($variables['page'])) {
template_preprocess_html($variables);
}
/** @var \Drupal\webform\WebformInterface $webform */
$webform = \Drupal::routeMatch()
->getParameter('webform');
// Add html.webform-share-page-html class.
$variables['html_attributes']
->addClass('webform-share-page-html');
// Add body.webform-share-page-body class.
// @see webform_share.page.css
$variables['attributes'] += [
'class' => [],
];
$variables['attributes']['class'][] = 'webform-share-page-body';
// Add custom page body attributes.
$body_attributes = $webform
->getSetting('share_page_body_attributes');
if (isset($body_attributes['class'])) {
$variables['attributes']['class'] = array_merge($variables['attributes']['class'], $body_attributes['class']);
unset($body_attributes['class']);
}
$variables['attributes'] = $body_attributes + $variables['attributes'];
// Remove toolbar.module body classes.
// @see toolbar_preprocess_html()
if (\Drupal::currentUser()
->hasPermission('access toolbar')) {
foreach ($variables['attributes']['class'] as $index => $class_name) {
if (strpos($class_name, 'toolbar-') === 0) {
unset($variables['attributes']['class'][$index]);
}
}
$variables['attributes']['class'] = array_values($variables['attributes']['class']);
}
// Prepend page title to the content because all blocks are hidden.
// @see webform_share_block_access()
// @see https://drupal.stackexchange.com/questions/112757/how-can-i-get-the-page-title/112758
if ($webform
->getSetting('share_title')) {
$request = \Drupal::request();
$route_match = \Drupal::routeMatch();
$title = \Drupal::service('title_resolver')
->getTitle($request, $route_match
->getRouteObject());
$variables['page']['content']['page_title'] = [
'#type' => 'page_title',
'#title' => $title,
// Move page title before the message block (weight: 1000)
// @see \Drupal\block\Plugin\DisplayVariant\BlockPageVariant::build
'#weight' => -1001,
];
}
}