Skip to content
Snippets Groups Projects

Issue #3288910 by Project Update Bot: Replace file_url_transform_relative with...

Issue #3288910 by Project Update Bot: Replace file_url_transform_relative with...

Issue #3288910 by Project Update Bot: Replace file_url_transform_relative with file_url_generator service

Closes #3354946

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
9 9 use Psr\Log\LoggerInterface;
10 10 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11 11 use Symfony\Component\HttpKernel\KernelEvents;
12 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
12 use Symfony\Component\HttpKernel\Event\RequestEvent;
13 13 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14 use Drupal\Core\File\FileUrlGeneratorInterface;
15 use Symfony\Component\HttpFoundation\RequestStack;
14 16
17 /**
18 * Class to provide functionality for MissingAsset.
  • 51 * The file URL generator.
    46 52 *
    53 * @var \Drupal\Core\File\FileUrlGeneratorInterface
    47 54 */
    48 public function __construct(LoggerInterface $logger, FileSystemInterface $file_system, Connection $database, EventDispatcherInterface $event_dispatcher) {
    55 protected $fileUrlGenerator;
    56
    57 /**
    58 * The request stack.
    59 *
    60 * @var \Symfony\Component\HttpFoundation\RequestStack
    61 */
    62 protected $requestStack;
    63
    64 /**
    65 * Construct a MissingAsset object.
  • 47 54 */
    48 public function __construct(LoggerInterface $logger, FileSystemInterface $file_system, Connection $database, EventDispatcherInterface $event_dispatcher) {
    55 protected $fileUrlGenerator;
    56
    57 /**
    58 * The request stack.
    59 *
    60 * @var \Symfony\Component\HttpFoundation\RequestStack
    61 */
    62 protected $requestStack;
    63
    64 /**
    65 * Construct a MissingAsset object.
    66 *
    67 * @param \Psr\Log\LoggerInterface $logger
    68 * A logger instance.
  • 55 protected $fileUrlGenerator;
    56
    57 /**
    58 * The request stack.
    59 *
    60 * @var \Symfony\Component\HttpFoundation\RequestStack
    61 */
    62 protected $requestStack;
    63
    64 /**
    65 * Construct a MissingAsset object.
    66 *
    67 * @param \Psr\Log\LoggerInterface $logger
    68 * A logger instance.
    69 * @param \Drupal\Core\File\FileSystemInterface $file_system
    70 * The file handler.
  • 59 *
    60 * @var \Symfony\Component\HttpFoundation\RequestStack
    61 */
    62 protected $requestStack;
    63
    64 /**
    65 * Construct a MissingAsset object.
    66 *
    67 * @param \Psr\Log\LoggerInterface $logger
    68 * A logger instance.
    69 * @param \Drupal\Core\File\FileSystemInterface $file_system
    70 * The file handler.
    71 * @param \Drupal\Core\Database\Connection $database
    72 * The database connection.
    73 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
    74 * The Event Dispatcher Interface.
  • 76 * The file URL generator.
    77 * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
    78 * The request stack used to retrieve the current request.
    79 */
    80 public function __construct(LoggerInterface $logger, FileSystemInterface $file_system, Connection $database, EventDispatcherInterface $event_dispatcher, FileUrlGeneratorInterface $fileUrlGenerator, RequestStack $requestStack) {
    49 81 $this->logger = $logger;
    50 82 $this->fileSystem = $file_system;
    51 83 $this->database = $database;
    52 84 $this->eventDispatcher = $event_dispatcher;
    85 $this->fileUrlGenerator = $fileUrlGenerator;
    86 $this->requestStack = $requestStack;
    53 87 }
    54 88
    55 public function findAndWrite(GetResponseEvent $event) {
    89 /**
    90 * Function of findAndWrite with event argument.
  • 6 6 use Drupal\amp\Asset\AmpCssCollectionRenderer as BaseAmpCssCollectionRenderer;
    7 7
    8 8 /**
    9 * Wrapper around amp's AmpCssCollectionRendered that ensure needed css files are present on disk upfront.
    9 * Wrapper around amp's AmpCssCollectionRendered that.
    10 *
    11 * Ensure needed css files are present on disk upfront.
  • 20 22 return $elements;
    21 23 }
    22 24
    23 foreach ($elements as $key => $element) {
    25 foreach ($elements as $element) {
    24 26 if ($element['#tag'] == 'style' && array_key_exists('#value', $element)) {
    25 $urls = preg_match_all('/@import url\("(.+)\?/', $element['#value'], $matches);
    26 $all_css = [];
    27 27 foreach ($matches[1] as $url) {
    28 //$css = file_get_contents(DRUPAL_ROOT . $url);
    28 // $css = file_get_contents(DRUPAL_ROOT . $url);
  • 17 'data' => $data,
    18 'timestamp' => REQUEST_TIME,
    19 ])
    20 ->execute();
    19 $connection
    20 ->insert('optimized_assets_proxy')
    21 ->fields([
    22 'file' => basename($uri),
    23 'data' => $data,
    24 'timestamp' => \Drupal::time()->getRequestTime(),
    25 ])
    26 ->execute();
    27 }
    28 catch (\Exception $exception) {
    29 \Drupal::logger('optimized_assets_proxy')->error($exception->getMessage());
    30 }
  • 1 1 name: CSS/JS Optimized Assets Proxy
    2 2 type: module
    3 3 description: Stores generated css/js optimized assets to the database, and recovers them to disk when missing.
    4 core: 8.x
    5 core_version_requirement: ^8 || ^9
    4 core_version_requirement: ^9.3 || ^10
  • 1 1 <?php
    2 2
    3 /**
    4 * @file
    5 * Install file to import config during module instalation.
  • Nitin Lama added 21 commits

    added 21 commits

    Compare with previous version

  • 11 11 use Symfony\Component\HttpKernel\KernelEvents;
    12 12 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
    13 13 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    14 use Drupal\Core\File\FileUrlGeneratorInterface;
    15 use Symfony\Component\HttpFoundation\RequestStack;
    14 16
    17 /**
    18 * Event subscriber class for Optimized Assets Proxy.
  • 59 *
    60 * @var \Symfony\Component\HttpFoundation\RequestStack
    61 */
    62 protected $requestStack;
    63
    64 /**
    65 * Construct a new \Drupal\optimized_assets_proxy\EventSubscriber\MissingAsset object.
    66 *
    67 * @param \Psr\Log\LoggerInterface $logger
    68 * The logger.
    69 * @param \Drupal\Core\File\FileSystemInterface $file_system
    70 * The file system service.
    71 * @param \Drupal\Core\Database\Connection $database
    72 * The database connection.
    73 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
    74 * An event dispatcher instance.
  • 58 //$assets_path = file_url_transform_relative(file_create_url('assets://'));
    59 // Check if core patch https://www.drupal.org/project/drupal/issues/3027639 is applied.
    98 // Check if core patch
    99 // https://www.drupal.org/project/drupal/issues/3027639 is applied.
    60 100 if (in_array('assets', stream_get_wrappers())) {
    61 101 $stream_wrapper_uri = 'assets://';
    62 102 }
    63 103 else {
    64 104 $stream_wrapper_uri = 'public://';
    65 105 }
    66 $assets_path = file_url_transform_relative(file_create_url($stream_wrapper_uri));
    106 $assets_path = $this->fileUrlGenerator->generateString($stream_wrapper_uri);
    67 107
    68 108 $matches = [];
    69 if (preg_match("@^$assets_path(css)/css_|(js)/js_@", $request_path, $matches)) {
    109 if (preg_match("@^$assets_path(css|js)(/optimized)?/(css|js)_@", $request_path, $matches)) {
  • 18 return $uri;
    19 }
    20
    21 try {
    22 $connection = \Drupal::database();
    23 $connection
    24 ->insert('optimized_assets_proxy')
    25 ->fields([
    26 'file' => basename($uri),
    27 'data' => $data,
    28 'timestamp' => \Drupal::time()->getRequestTime(),
    29 ])
    30 ->execute();
    31 }
    32 catch (\Exception $exception) {
    33 \Drupal::logger('optimized_assets_proxy')->error($exception->getMessage());
  • 18 return $uri;
    19 }
    20
    21 try {
    22 $connection = \Drupal::database();
    23 $connection
    24 ->insert('optimized_assets_proxy')
    25 ->fields([
    26 'file' => basename($uri),
    27 'data' => $data,
    28 'timestamp' => \Drupal::time()->getRequestTime(),
    29 ])
    30 ->execute();
    31 }
    32 catch (\Exception $exception) {
    33 \Drupal::logger('optimized_assets_proxy')->error($exception->getMessage());
  • 4 4
    5 5 use Drupal\Core\Asset\AssetDumper as CoreAssetDumper;
    6 6
    7 /**
    8 * Extend AssetDumper to additionally store data in DB for later.
  • 13 21 ],
    14 22 'file' => [
    15 23 'type' => 'varchar_ascii',
    16 'length' => '64',
    24 'length' => '256',
  • 1 1 <?php
    2 2
    3 /**
    4 * @file
    5 * Module file to addon feature into module.
    • The usual description is Hook implementations for the [module name] module. where [module name] is the module name used in the .info.yml file. Module file to add features to the module. (which I assume is what the description is supposed to be) does not make much sense. (File containing the module code that adds features to the module. ???)

      Edited by Alberto Paderno
    • Please register or sign in to reply
  • Shashank S added 1 commit

    added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Please register or sign in to reply
    Loading