You are here

function sitewide_js_preprocess_html in Open Social 8.2

Same name and namespace in other branches
  1. 8.9 modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  2. 8 modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  3. 8.3 modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  4. 8.4 modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  5. 8.5 modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  6. 8.6 modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  7. 8.7 modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  8. 8.8 modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  9. 10.3.x modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  10. 10.0.x modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  11. 10.1.x modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()
  12. 10.2.x modules/custom/sitewide_js/sitewide_js.module \sitewide_js_preprocess_html()

Implements hook_preprocess_html().

File

modules/custom/sitewide_js/sitewide_js.module, line 38
The sitewide_js module file.

Code

function sitewide_js_preprocess_html(&$variables) {

  // Get settings.
  $config = Drupal::config('sitewide_js.settings');

  // Check if it's enabled.
  if ($config
    ->get('swjs_enabled') === 1) {

    // Check if it should be placed in the footer.
    if ($config
      ->get('swjs_location') === '1' && !empty($config
      ->get('swjs_footer_region'))) {

      // Attach the JS.
      $variables[$config
        ->get('swjs_footer_region')][9999] = [
        '#type' => 'inline_template',
        '#template' => '{{ js|raw }}',
        '#context' => [
          'js' => '<script>' . $config
            ->get('swjs_javascript') . '</script>',
        ],
      ];
    }
  }
}