Account created on 8 August 2022, over 2 years ago
#

Merge Requests

Recent comments

🇮🇳India nikhil_dawar

Hi abramm, here I have removed the dead code from the patch

🇮🇳India nikhil_dawar

I've completed the patch that enables the import/export of embedded images through SCS as per above-mentioned request.
Thank you

🇮🇳India nikhil_dawar

1. Usage of Preprocess Image Hook:

Implemented a preprocess image hook to address a specific issue.

2. Call to removeAllQueryParameter Function:

Within the preprocess image hook, called the removeAllQueryParameter function to remove all query parameters from the URL.

3. Extension Check and Update:

Checked the file extension by extracting it from the modified URL.
4. Condition for SVG Files:

Added a condition to check if the file extension is 'svg'.

5. Modification of srcset Attribute:

If the file is an SVG (Scalable Vector Graphics), updated the value of the srcset attribute with the src attribute.

In summary, the preprocess image hook is utilized to manipulate image URLs. The removeAllQueryParameter function is employed to eliminate all query parameters. Subsequently, the file extension is checked, and if it is an SVG file, the srcset attribute is adjusted to match the src attribute.

I have applied code in the .theme file

function removeAllQueryParameters($url) {
  // Parse the URL into its components.
  $urlParts = parse_url($url);

  // Check if there are query parameters.
  if (isset($urlParts['query'])) {
      // Remove all query parameters.
      $urlParts['query'] = '';

      // Rebuild the full URL.
      $url = $urlParts['scheme'] . '://' . $urlParts['host'] . $urlParts['path'];
      if (!empty($urlParts['fragment'])) {
          $url .= '#' . $urlParts['fragment'];
      }
  }

  return $url;
}

function hook_preprocess_image(&$variables) {
  $modifiedUrl = removeAllQueryParameters($variables['uri']);
  $modified_file_extension = pathinfo($modifiedUrl, PATHINFO_EXTENSION);
  if ($modified_file_extension == 'svg') {
    $variables['attributes']['srcset'] = $variables['attributes']['src'];
  }
}
Production build 0.71.5 2024