PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 19, 2022

[FIXED] Issue applying patch with Composer and Drupal

 February 19, 2022     composer-php, drupal-8     No comments   

Issue

Some clarification is needed since I wasn't thorough enough.

I have contrib module Lazyloader.

  • I'm applying this patch: https://www.drupal.org/files/issues/2018-11-29/lazyloader-LQIP-2905310-6.patch from this issue https://www.drupal.org/project/lazyloader/issues/2905310

This patch created random SVG images which we don't like. So we wanted to update the code and create a Grey SVG placeholder image. Using the code from the Patch I made some updates and I want to basically do the following:

Install Lazyloader

  • Patch with https://www.drupal.org/files/issues/2018-11-29/lazyloader-LQIP-2905310-6.patch
  • Patch with my own custom code, which requires the previous patch.

When I apply a self-made patch, 3 new directories are created,but this shouldn't happen:

  • modules/contrib/lazyloader/b/
  • modules/contrib/lazyloader/contrib/
  • modules/contrib/lazyloader/modules/

The module is already installed under modules/contrib/lazyloader and the only directory that should be created is modules/contrib/lazyloader/css and the file name.css

I tried no prefix (can't apply patch if I use this)

git diff --staged > name.patchhttps://www.drupal.org/project/lazyloader/issues/2905310

I apply patch with ...

lando composer update drupal/lazyload

... but it creates a new directory that I didn't include in the patch.

I found this issue but I'm not sure if this is affecting my issue.

I believe it's an issue with patch level and cweagans/composer-patches.

This is my Patch

diff --git a/modules/contrib/lazyloader/css/grey_svg.css b/modules/contrib/lazyloader/css/grey_svg.css
new file mode 100644
index 000000000..573a3bb74
--- /dev/null
+++ b/modules/contrib/lazyloader/css/grey_svg.css
@@ -0,0 +1,3 @@
+.lazyload {
+  background-color: lightgrey;
+}
diff --git a/modules/contrib/lazyloader/lazyloader.libraries.yml b/modules/contrib/lazyloader/lazyloader.libraries.yml
index 99e023f00..ef4d1c6ff 100644
--- a/modules/contrib/lazyloader/lazyloader.libraries.yml
+++ b/modules/contrib/lazyloader/lazyloader.libraries.yml
@@ -15,3 +15,8 @@ lazysizes-min.cdn:
     gpl-compatible: true
   js:
     https://cdnjs.cloudflare.com/ajax/libs/lazysizes/2.0.0/lazysizes.min.js: { type: external, minified: true }
+
+udesa-grey-svg:
+  css:
+    theme:
+      css/grey_svg.css: {}
diff --git a/modules/contrib/lazyloader/lazyloader.module b/modules/contrib/lazyloader/lazyloader.module
index 24998ed18..dc872356f 100644
--- a/modules/contrib/lazyloader/lazyloader.module
+++ b/modules/contrib/lazyloader/lazyloader.module
@@ -118,3 +118,10 @@ function lazyloader_libraries_info() {

   return $libraries;
 }
+
+/**
+ * Implements hook_libraries_info().
+ */
+function lazyloader_page_attachments(array &$page) {
+  $page['#attached']['library'][] = 'lazyloader/udesa-grey-svg';
+}

Also this is my composer.json Patches

    "drupal/lazyloader": {
        "Provide option to use a image style as the placeholder image": "https://www.drupal.org/files/issues/2018-11-29/lazyloader-LQIP-2905310-6.patch",
        "Create black SVG as placeholder image": "patches/lazyloader/lazyloader-create-black-svg.patch"
    }

Patch name is not the issue, I've been toying with several of them

SOLUTIO > I what what the solution informed

1- Install module with --prefer source with the Patch I wanted from drupal.org 2- Went into modules/contrib/lazyloader 3- I was in detached head branch with the changes from the patch 4- made my own changes since I needed the patch from drupal.org in the first palce 5- created my own patch with my changes

Working perfectly!


Solution

Your patch should be local to the module git repo. The paths have to look something like this:

diff --git a/lazyloader/css/grey_svg.css b/lazyloader/css/grey_svg.css

Instead of:

diff --git a/modules/contrib/lazyloader/css/grey_svg.css b/modules/contrib/lazyloader/css/grey_svg.css

The path to the contrib module is taken from your composer.json (drupal/lazyloader)

Make sure you're using the contrib module git repo to create the patch (not drupal core). https://www.drupal.org/node/707484

Starting from scratch, the process should be something like this:

  1. From your project root folder, install lazyloader from source using composer:
composer require 'drupal/lazyloader:^1.0' --prefer-source
  1. Make your changes to the code using your favorite IDE.
  2. Create the patch:
cd web/modules/contrib/lazyloader
git diff --staged > name.patch
mv name.patch ../../../../patches/lazyloader/lazyloader-create-black-svg.patch
  1. Your composer.json looks good. Next time you run composer install or composer update your patch will be installed.


Answered By - sam711
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing