You are here

function webform_library_info_build in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.libraries.inc \webform_library_info_build()

Implements hook_library_info_build().

File

includes/webform.libraries.inc, line 15
Webform libraries.

Code

function webform_library_info_build() {
  $base_path = base_path();
  $default_query_string = \Drupal::state()
    ->get('system.css_js_query_string') ?: '0';

  /** @var \Drupal\webform\WebformInterface[] $webforms */
  $webforms = Webform::loadMultiple();
  $libraries = [];
  foreach ($webforms as $webform_id => $webform) {
    $assets = array_filter($webform
      ->getAssets());
    foreach ($assets as $type => $value) {

      // Note:
      // Set 'type' to 'external' and manually build the CSS/JS file path
      // to prevent JS from being parsed by locale_js_alter()
      // @see locale_js_alter()
      // @see https://www.drupal.org/node/1803330
      $settings = [
        'type' => 'external',
        'preprocess' => FALSE,
        'minified' => FALSE,
      ];
      if ($type === 'css') {
        $libraries["webform.css.{$webform_id}"] = [
          'css' => [
            'theme' => [
              "{$base_path}webform/css/{$webform_id}?{$default_query_string}" => $settings,
            ],
          ],
        ];
      }
      else {
        $libraries["webform.javascript.{$webform_id}"] = [
          'js' => [
            "{$base_path}webform/javascript/{$webform_id}?{$default_query_string}" => $settings,
          ],
        ];
      }
    }
  }
  return $libraries;
}