function webform_page_attachments in Webform 6.x
Same name and namespace in other branches
- 8.5 webform.module \webform_page_attachments()
Implements hook_page_attachments().
File
- ./
webform.module, line 561 - Enables the creation of webforms and questionnaires.
Code
function webform_page_attachments(array &$attachments) {
$route_name = \Drupal::routeMatch()
->getRouteName();
// Attach global libraries only to webform specific pages and module list.
if (preg_match('/^(webform\\.|^entity\\.([^.]+\\.)?webform)/', $route_name) || $route_name === 'system.modules_list') {
_webform_page_attachments($attachments);
}
// Attach codemirror and select2 library to block admin to ensure that the
// library is loaded by the webform block is placed using Ajax.
if (strpos($route_name, 'block.admin_display') === 0) {
$attachments['#attached']['library'][] = 'webform/webform.block';
}
// Attach webform dialog library and options to every page.
if (\Drupal::config('webform.settings')
->get('settings.dialog')) {
$attachments['#attached']['library'][] = 'webform/webform.dialog';
$attachments['#attached']['drupalSettings']['webform']['dialog']['options'] = \Drupal::config('webform.settings')
->get('settings.dialog_options');
/** @var \Drupal\webform\WebformRequestInterface $request_handler */
$request_handler = \Drupal::service('webform.request');
if ($source_entity = $request_handler
->getCurrentSourceEntity()) {
$attachments['#attached']['drupalSettings']['webform']['dialog']['entity_type'] = $source_entity
->getEntityTypeId();
$attachments['#attached']['drupalSettings']['webform']['dialog']['entity_id'] = $source_entity
->id();
}
}
// Attach webform more element to token token help.
// @see webform_token_info_alter()
if ($route_name === 'help.page' && \Drupal::routeMatch()
->getRawParameter('name') === 'token') {
$attachments['#attached']['library'][] = 'webform/webform.token';
}
}