You are here

vendor_stream_wrapper.module in Vendor Stream Wrapper 8

Holds hooks and API functions for the Vendor Stream Wrapper module.

This module creates a vendor:// read-only stream wrapper for files in the vendor directory.

File

vendor_stream_wrapper.module
View source
<?php

/**
 * @file
 * Holds hooks and API functions for the Vendor Stream Wrapper module.
 *
 * This module creates a vendor:// read-only stream wrapper for files in the
 * vendor directory.
 */

/**
 * Implements hook_library_info_alter().
 */
function vendor_stream_wrapper_library_info_alter(&$libraries, $extension) {
  foreach ($libraries as $library_key => $library) {
    if (isset($library['js'])) {
      foreach (array_keys($library['js']) as $path) {
        if (strpos($path, 'vendor://') === 0) {
          $libraries[$library_key]['js'][vendor_stream_wrapper_create_url($path)] = $library['js'][$path];
          unset($libraries[$library_key]['js'][$path]);
        }
      }
    }
    if (isset($library['css'])) {
      foreach (array_keys($library['css']) as $css_level) {
        foreach (array_keys($library['css'][$css_level]) as $path) {
          if (strpos($path, 'vendor://') === 0) {
            $libraries[$library_key]['css'][$css_level][vendor_stream_wrapper_create_url($path)] = $library['css'][$css_level][$path];
            unset($libraries[$library_key]['css'][$css_level][$path]);
          }
        }
      }
    }
  }
}

/**
 * Helper function to create public URLs from vendor:// stream wrapper URIs.
 */
function vendor_stream_wrapper_create_url($uri) {
  return Drupal::service('vendor_stream_wrapper.service')
    ->creatUrlFromUri($uri);
}

Functions

Namesort descending Description
vendor_stream_wrapper_create_url Helper function to create public URLs from vendor:// stream wrapper URIs.
vendor_stream_wrapper_library_info_alter Implements hook_library_info_alter().