Score:4

Why doesn't cweagans/composer-patches install my custom patch for drupal/slick?

ug flag

Basically, I have installed slick module and customised code and created a patch file using "git diff" command. Slick module file path is modules/contrib/slick/ directory. Below is the code that i have written in the composser.json file.

"require": {
        "drupal/slick": "^2.7",
}

----------------------------------

"patches": {
  "drupal/slick": {
  "Slick custom changes": "patches/slick/slick.patch"
},

But when running composer install, it just removes this slick package from "modules/contrib/slick, but does not reinstall or add the patch.

If i remove "Slick custom changes": "patches/slick/slick.patch" from composer.json and execute composer install cmd then it install slick module.

How to avoid removing this package and applying the patch?

git apply > "patches/slick/slick.patch" executes successfully and apply patches. But composer install fails to apply patch.

"cweagans/composer-patches" is already installed.

Below is the patch code

diff --git a/docroot/modules/contrib/slick/css/layout/slick.module.css b/docroot/modules/contrib/slick/css/layout/slick.module.css
index 88b0d639f..3f4b10398 100644
--- a/docroot/modules/contrib/slick/css/layout/slick.module.css
+++ b/docroot/modules/contrib/slick/css/layout/slick.module.css
@@ -17,14 +17,15 @@
   .slide__caption {
     left: 0;
     padding: 20px;
-    top: 10%;
+    top: 0%;
   }
 
   .slide--caption--center .slide__caption,
   .slide--caption--center-top .slide__caption,
   .slide--caption--left .slide__caption,
   .slide--caption--right .slide__caption {
-    width: 42%;
+    width: 50%;
+    height: 100%;
   }
 
   .slide--caption--center .slide__caption {
diff --git a/docroot/modules/contrib/slick/css/theme/slick.theme.css b/docroot/modules/contrib/slick/css/theme/slick.theme.css
index 79db65f87..0313802ba 100644
--- a/docroot/modules/contrib/slick/css/theme/slick.theme.css
+++ b/docroot/modules/contrib/slick/css/theme/slick.theme.css
@@ -116,12 +116,24 @@
 .slide__title {
   margin: 10px 0 5px;
   line-height: 1.2;
+  font-size: 3em; 
+  font-weight: 600;
+  color: #fff;
 }
 
 .slide__link {
   margin: 30px auto;
 }
 
+.slide__description{
+  font-size: 1.652rem;
+    line-height: 1.2em;
+    font-weight: 400;
+    font-family: "Open Sans",sans-serif;
+    color: #fff;
+    opacity: 1;
+}
+
 /* Overrides .slick-slider to make caption text selectable. */
 .slide__caption {
   cursor: text;
@@ -130,7 +142,11 @@
   -o-user-select: text;
   -webkit-user-select: text;
   user-select: text;
-  width: 100%;
+  width: 50%;
+  background: #0b172e8a;;
+  margin-top: auto;
+  margin-bottom: auto;
+  margin-left: 0px;
 }
 
 /* Only display when JS is ready. */
@@ -206,13 +222,14 @@
 }
 
 .slick-arrow::before {
-  color: #ff6d2c;
+  color: #eb0000;
   font-size: 36px;
   font-size: 2.25rem;
+  opacity: 1;
 }
 
 .slick-arrow:hover::before {
-  color: #37465b;
+  color: #8c0c0c;
 }
 
 /**
@@ -249,6 +266,7 @@ img[data-lazy] {
 .slide__media {
   overflow: hidden;
   position: relative;
+  opacity:0.75
 }
 
 /* Center the image to reduce gap at RHS with smaller image, larger container */
@@ -274,3 +292,8 @@ img[data-lazy] {
 .slick--less .draggable {
   cursor: default;
 }
+
+.slick-dots
+{
+    bottom: -25px;
+}
diff --git a/docroot/modules/contrib/slick/templates/slick-slide.html.twig b/docroot/modules/contrib/slick/templates/slick-slide.html.twig
index 987a6c471..6e368485a 100644
--- a/docroot/modules/contrib/slick/templates/slick-slide.html.twig
+++ b/docroot/modules/contrib/slick/templates/slick-slide.html.twig
@@ -73,6 +73,22 @@
             <p class="slide__description">{{ item.caption.alt }}</p>
           {% endif %}
 
+          {% if item.caption.caption_img %}
+            <p class="slide__description" >{{ item.caption.caption_img }}</p>
+          {% endif %}
+
+          {% if item.caption.caption_p_cta_url %}
+            <a class="primaryCta__button primaryCta__button--" href={{ item.caption.caption_p_cta_url }} aria-label="button" type="button">
+              {{ item.caption.caption_p_cta }}
+            </a>
+          {% endif %}
+
+          {% if item.caption.caption_s_cta_url %}
+            <a class="secondaryCta__button secondaryCta__button--" href={{ item.caption.caption_s_cta_url }} aria-label="button" type="button">
+              {{ item.caption.caption_s_cta }}
+            </a>
+          {% endif %}
+
           {% if item.caption.data %}
             <div class="slide__description">{{ item.caption.data }}</div>
           {% endif %}
diff --git a/docroot/modules/contrib/slick/templates/slick.theme.inc b/docroot/modules/contrib/slick/templates/slick.theme.inc
index b0bf8f512..6afe4f92c 100644
--- a/docroot/modules/contrib/slick/templates/slick.theme.inc
+++ b/docroot/modules/contrib/slick/templates/slick.theme.inc
@@ -10,6 +10,9 @@
 use Drupal\blazy\Blazy;
 use Drupal\slick\SlickDefault;
 use Drupal\slick\Entity\Slick;
+use Drupal\image_field_caption\ImageCaptionStorage;
+use Drupal\image_field_caption\ImageCaptionItem;
+use Drupal\image_field_caption\ImageFieldCaption;
 
 /**
  * Prepares variables for slick.html.twig templates.
@@ -100,6 +103,7 @@ function template_preprocess_slick(&$variables) {
 
   // Process individual item.
   $variables['items'] = [];
+  $i=0;
   foreach ($element['#items'] as $delta => $item) {
     $item_settings = array_merge($settings, (array) ($item['settings'] ?? []));
     $item_attrs = (array) ($item['attributes'] ?? []);
@@ -116,9 +120,15 @@ function template_preprocess_slick(&$variables) {
       '#settings' => $item_settings,
       '#attributes' => $item_attrs,
       '#content_attributes' => $content_attrs,
+      '#caption_img' => $variables['element']['#items'][$i]['item']->caption,
+      '#caption_p_cta' => $variables['element']['#items'][$i]['item']->primary_cta,
+      '#caption_p_cta_url' => $variables['element']['#items'][$i]['item']->primary_cta_url,
+      '#caption_s_cta' => $variables['element']['#items'][$i]['item']->secondary_cta,
+      '#caption_s_cta_url' => $variables['element']['#items'][$i]['item']->secondary_cta_url,
     ];
     $variables['items'][$delta] = $slide;
     unset($slide);
+    $i++;
   }
 }
 
@@ -136,7 +146,7 @@ function template_preprocess_slick_wrapper(&$variables) {
  */
 function _slick_preprocess_slick_item(&$variables) {
   $element = $variables['element'];
-  foreach (['attributes', 'content_attributes', 'delta', 'item', 'settings'] as $key) {
+  foreach (['attributes', 'content_attributes', 'delta', 'item', 'settings', 'caption_img', 'caption_p_cta', 'caption_p_cta_url', 'caption_s_cta', 'caption_s_cta_url'] as $key) {
     $default = $key == 'delta' ? NULL : [];
     $variables[$key] = $element["#$key"] ?? $default;
   }
@@ -168,8 +178,20 @@ function template_preprocess_slick_slide(&$variables) {
   _slick_preprocess_slick_item($variables);
 
   // All slide types -- main, thumbnail, grid, overlay -- may have captions.
-  foreach (['alt', 'data', 'link', 'overlay', 'title'] as $key) {
-    $variables['item']['caption'][$key] = $variables['item']['caption'][$key] ?? [];
+  foreach (['alt', 'data', 'link', 'overlay', 'title', 'caption_img', 'caption_p_cta', 'caption_p_cta_url', 'caption_s_cta', 'caption_s_cta_url'] as $key) {
+    if($key =='caption_img'){
+      $variables['item']['caption'][$key] = $variables['caption_img'] ?? [];
+    } else if ($key == 'caption_p_cta') {
+      $variables['item']['caption'][$key] = $variables['caption_p_cta'] ?? [];
+    } else if ($key == 'caption_p_cta_url') {
+      $variables['item']['caption'][$key] = $variables['caption_p_cta_url'] ?? [];
+    } else if ($key == 'caption_s_cta') {
+      $variables['item']['caption'][$key] = $variables['caption_s_cta'] ?? [];
+    } else if ($key == 'caption_s_cta_url') {
+      $variables['item']['caption'][$key] = $variables['caption_s_cta_url'] ?? [];
+    } else  {
+      $variables['item']['caption'][$key] = $variables['item']['caption'][$key] ?? [];
+    }
   }
 
   $item = &$variables['item'];
@@ -183,7 +205,7 @@ function template_preprocess_slick_slide(&$variables) {
   $item['slide']     = $item['slide'] ?? [];
   $item['caption']   = array_filter($item['caption']);
   $sets['split']     = !empty($item) && (!empty($sets['caption']) || !empty($sets['title']));
-  $sets['data']      = !empty($item['caption']['alt']) || !empty($item['caption']['title']) || !empty($item['caption']['data']);
+  $sets['data']      = !empty($item['caption']['alt']) || !empty($item['caption']['title']) || !empty($item['caption']['data']) || !empty($item['caption']['image_field_caption']);
   $sets['fullwidth'] = !empty($sets['skin']) && strpos($sets['skin'], 'full') !== FALSE;
   $sets['grid']      = empty($sets['grid']) ? FALSE : $sets['grid'];
   $sets['detroy']    = $sets['current_item'] == 'main' && !empty($sets['grid']) && !empty($sets['unslick']);

composer.json code

{
    "name": "******",
    "description": "*******",
    "license": "proprietary",
    "authors": [
        {
            "name": "**********",
            "email": "********"
        }
    ],
    "type": "project",
    "minimum-stability": "dev",
    "prefer-stable": true,
    "require-dev": {
        "behat/behat": "3.6.1",
        "behat/mink-extension": "^2.3",
        "behat/mink-goutte-driver": "^1.2",
        "composer/composer": "^2",
        "consolidation/config": "1.2.1",
        "deployer/dist": "^6.8",
        "deployer/recipes": "^6.2",
        "dmore/behat-chrome-extension": "^1.3",
        "dmore/chrome-mink-driver": "2.7.0",
        "drupal/coder": "8.3.8",
        "drupal/drupal-extension": "^4.1",
        "drush/drush": "^10.6",
        "kint-php/kint": "^3.3",
        "mglaman/drupal-check": "^1.2",
        "mikey179/vfsstream": "1.6.8",
        "mouf/nodejs-installer": "1.0.14",
        "phpunit/phpunit": "^9.5",
        "symfony/css-selector": "^3.0",
        "symfony/phpunit-bridge": "^5.2",
        "widgetsburritos/drupal-patch-checker": "^2.0"
    },
    "require": {
        "algolia/places": "1.19.0",
        "choices/choices": "9.0.1",
        "ckeditor/autogrow": "4.16.2",
        "ckeditor/codemirror": "v1.17.12",
        "ckeditor/fakeobjects": "4.16.2",
        "ckeditor/image": "4.16.2",
        "ckeditor/link": "4.16.2",
        "codemirror/codemirror": "5.57.0",
        "composer/installers": "^1.9",
        "cweagans/composer-patches": "1.x-dev#4f3414441522dfeecff697f061ce27412a2b677b",
        "drupal/advban": "^1.3",
        "drupal/akamai": "^4.0",
        "drupal/auditfiles": "^3.0",
        "drupal/autoban": "^1.6",
        "drupal/better_exposed_filters": "^5.0",
        "drupal/blazy": "^2.13",
        "drupal/captcha": "^1.0",
        "drupal/google_tag": "^1.3",
        "drupal/image_field_caption": "^1.2",
        "drupal/lazy": "^3.2",
        "drupal/lb_settings_report": "1.0.x-dev",
        "drupal/libraries": "3.x-dev#3b7ae61a8e68ce37638b313eaccf4febaa48e3fa",
        "drupal/path_redirect_import": "^1.0",
        "drupal/pathauto": "^1.8",
        "drupal/slick": "^2.7",
        "drupal/slick_extras": "^1.0@RC",
        "drupal/slick_views": "^2.6",
        "drupal/smtp": "^1.0",
        "drupal/stage_file_proxy": "^1.0",
        "drupal/textfield_counter": "^2.0",
        "drupal/tmgmt": "^1.10",
        "drupal/tmgmt_smartling": "^4.8",
        "drupal/token": "1.x-dev#195fca31519225d63f5b543a4e6b039931bfc6ef",
        "drupal/token_custom": "^1.0"
       
    },
    "repositories": {
        "0": {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        "1": {
            "type": "composer",
            "url": "https://asset-packagist.org"
        },
        "ckeditor.image": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "ckeditor/image",
                "version": "4.16.2",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "ckeditor.image"
                },
                "dist": {
                    "url": "https://download.ckeditor.com/image/releases/image_4.16.2.zip",
                    "type": "zip"
                }
            }
        },
        "jquery.inputmask": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/inputmask",
                "version": "5.0.5",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.inputmask"
                },
                "dist": {
                    "url": "https://github.com/RobinHerbots/jquery.inputmask/archive/5.0.5.zip",
                    "type": "zip"
                }
            }
        },
        "signature_pad": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "signature_pad/signature_pad",
                "version": "2.3.0",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "signature_pad"
                },
                "dist": {
                    "url": "https://github.com/szimek/signature_pad/archive/v2.3.0.zip",
                    "type": "zip"
                }
            }
        }
    },
    "scripts": {
        "post-install-cmd": [
            "Composer\\Config::disableProcessTimeout",
            "scripts/post-install.sh",
            "npm ci"
        ],
        "post-update-cmd": [
            "Composer\\Config::disableProcessTimeout",
            "scripts/post-install.sh",
            "npm install"
        ],
        "npm": [
            "npm"
        ],
        "check:patch": [
            "WidgetsBurritos\\DrupalPatchChecker\\DrupalPatchChecker::checkComposerFile"
        ]
    },
    "config": {
        "bin-dir": "bin/",
        "sort-packages": true,
        "platform": {
            "php": "7.3"
        },
        "allow-plugins": {
            "composer/installers": true,
            "cweagans/composer-patches": true,
            "drupal/core-composer-scaffold": true,
            "oomphinc/composer-installers-extender": true,
            "mouf/nodejs-installer": true,
            "widgetsburritos/drupal-patch-checker": true
        }
      
    },
    "extra": {
        "composer-patches-skip-reporting": true,
        "drupal-scaffold": {
            "locations": {
                "web-root": "docroot"
            },
            "file-mapping": {
                "[web-root]/robots.txt": false,
                "[web-root]/sites/development.services.yml": false,
                "[web-root]/sites/example.settings.local.php": false,
                "[web-root]/sites/example.sites.php": false,
                "[web-root]/web.config": false
            }
        },
        "drush": {
            "services": {
                "drush.services.yml": "^9"
            }
        },
        "installer-types": [
            "rs-library",
            "npm-asset"
        ],
        "installer-paths": {
            "docroot/core": [
                "type:drupal-core"
            ],
            "docroot/libraries/{$name}": [
                "type:drupal-library",
                "type:npm-asset"
            ],
            "docroot/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "docroot/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ]
        },
        "mouf": {
            "nodejs": {
                "version": "14.10.1",
                "forceLocal": true,
                "includeBinInPath": true
            }
        },
        "enable-patching": true,
        "composer-exit-on-patch-failure": true,
        "patches": {
            "dmore/chrome-mink-driver": {
                "https://github.com/acquia/blt/issues/3224": "patches/drupal-extension/chrome-mink-driver.patch"
            },
            "drupal/core": {
                "3114365 - Vocabulary name not shown in View for Anonymous Users": "patches/core/taxonomy_vocabulary_view_permission-3114365.patch",
                "3190265 - guessMimeType declaration not compatible with Symfony interface": "patches/core/3190265-2.patch",
                "3114467 - 'Negate' form value for condition plugins should be cast to boolean in validation.": "patches/core/3114467-16.patch"
            },
            "drupal/advanced_text_formatter": {
                "3072029 - Untrimmed text before normalizing can return empty spaces in the event that no html tags are allowed": "patches/advanced_text_formatter/advanced-text-formatter-3072029.patch",
                "3068628 - Drupal 9 Deprecated Code Report": "patches/advanced_text_formatter/3068628-11.patch"
            },
            "drupal/entity_embed": {
                "3069448 - Array to string conversion for Media Image": "patches/entity_embed/entity-embed-array-to-string--3069448-19.patch"
            },
            "drupal/yoast_seo": {
                "3119603 - Drupal 9 readiness": "patches/yoast_seo/3119603-14.patch"
            },
            "drush/drush": {
                "3572 - `drush cex` doesn't remove `language` directory when it should": "patches/drush/drush-ops_drush-3572.patch"
            },
            "drupal/slick": {
                "MTE-8015 - Slick slider changes 1": "patches/slick/slick.patch"
            }
        }
    },
    "version": "9.2.43"
}

How to apply patch for .install file? Here is the patch code for .install file

diff --git a/image_field_caption/image_field_caption.install b/image_field_caption/image_field_caption.install
index b339c7a87..25a098b4f 100644
--- a/image_field_caption/image_field_caption.install
+++ b/image_field_caption/image_field_caption.install
@@ -70,6 +70,34 @@ function image_field_caption_schema() {
         'length' => 255,
         'not null' => FALSE,
       ),
+      'primary_cta' => array(
+        'description' => 'The primary cta.',
+        'type' => 'text',
+        'length' => 25,
+        'not null' => TRUE,
+        'default' => 'PCTA',
+      ),
+      'primary_cta_url' => array(
+        'description' => 'The primary cta url.',
+        'type' => 'text',
+        'length' => 250,
+        'not null' => TRUE,
+        'default' => 'PCTA',
+      ),
+      'secondary_cta' => array(
+        'description' => 'The secondary cta.',
+        'type' => 'text',
+        'length' => 25,
+        'not null' => TRUE,
+        'default' => 'PCTA',
+      ),
+      'secondary_cta_url' => array(
+        'description' => 'The secondary cta url.',
+        'type' => 'text',
+        'length' => 25,
+        'not null' => TRUE,
+        'default' => 'PCTA',
+      ),
     ),
     'indexes' => array(
       'entity_type' => array('entity_type'),
@@ -148,6 +176,34 @@ function image_field_caption_schema() {
         'length' => 255,
         'not null' => FALSE,
       ),
+      'primary_cta' => array(
+        'description' => 'The primary cta.',
+        'type' => 'text',
+        'length' => 25,
+        'not null' => TRUE,
+        'default' => 'PCTA',
+      ),
+      'primary_cta_url' => array(
+        'description' => 'The primary cta url.',
+        'type' => 'text',
+        'length' => 250,
+        'not null' => TRUE,
+        'default' => 'PCTA',
+      ),
+      'secondary_cta' => array(
+        'description' => 'The secondary cta.',
+        'type' => 'text',
+        'length' => 25,
+        'not null' => TRUE,
+        'default' => 'PCTA',
+      ),
+      'secondary_cta_url' => array(
+        'description' => 'The secondary cta url.',
+        'type' => 'text',
+        'length' => 25,
+        'not null' => TRUE,
+        'default' => 'PCTA',
+      ),
     ),
     'indexes' => array(
       'entity_type' => array('entity_type'),

When i release code to staging it shows error "Drupal\Core\Database\DatabaseExceptionWrapper. SQLSTATE(42502):Base table or view not found: 1146 Table 'www.image_field_caption'. dosent exist: SELECT Distinct 'ifc'.'entity_type' AS 'entity_type' FROM 'image_field_caption' 'ifc'.Array() in Drupal\image_field_caption\ImageCaptionStorage->list()(line 425 of module/contrib/image_field_caption/src/ImageCaptionStorage.php)"

below is the ImageCaptionStorage.php code its shows error for function "public function list(){ ... ->execute() ...}"

<?php

/**
 * @file
 * Contains \Drupal\image_field_caption\ImageCaptionStorage.
 */

namespace Drupal\image_field_caption;

use Drupal\Core\Database\Connection;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheTagsInvalidator;

class ImageCaptionStorage {

  protected $cacheBackend;
  protected $cacheTagsInvalidator;
  protected $database;
  protected $tableData = 'image_field_caption';
  protected $tableRevision = 'image_field_caption_revision';
  public function __construct(
        CacheBackendInterface $cacheBackend,
        CacheTagsInvalidator $cacheTagsInvalidator,
        Connection $database
    ) {
    $this->cacheBackend = $cacheBackend;
    $this->cacheTagsInvalidator = $cacheTagsInvalidator;
    $this->database = $database;
  }

  
  public function isCaption($entity_type, $bundle, $field_name, $entity_id, $revision_id, $language, $delta, $primary_cta, $primary_cta_url, $secondary_cta, $secondary_cta_url) {
    return (!empty(self::getCaption($entity_type, $bundle, $field_name, $entity_id, $revision_id, $language, $delta, $primary_cta, $primary_cta_url, $secondary_cta, $secondary_cta_url))) ? TRUE : FALSE;
  }

  
  public function getCaption($entity_type, $bundle, $field_name, $entity_id, $revision_id, $language, $delta, $primary_cta, $primary_cta_url, $secondary_cta, $secondary_cta_url) {
    $captions = &drupal_static(__FUNCTION__);

    $cacheKey = $this->getCacheKey($entity_type, $entity_id, $revision_id, $language, $field_name, $delta, $primary_cta, $primary_cta_url, $secondary_cta, $secondary_cta_url);

    if (isset($captions[$cacheKey])) {
      $caption = $captions[$cacheKey];
    }
    elseif ($cached = $this->cacheBackend->get($cacheKey)) {
      $caption = $cached->data;
    }
    else {
      // Query.
      $query = $this->database->select($this->tableData, 'ifc');
      $result = $query
              ->fields('ifc', array('caption', 'caption_format', 'primary_cta', 'primary_cta_url', 'secondary_cta', 'secondary_cta_url'))
              ->condition('entity_type', $entity_type, '=')
              ->condition('bundle', $bundle, '=')
              ->condition('field_name', $field_name, '=')
              ->condition('entity_id', $entity_id, '=')
              ->condition('revision_id', $revision_id, '=')
              ->condition('language', $language, '=')
              ->condition('delta', $delta, '=')
              ->execute()
              ->fetchAssoc();

      // Caption array.
      $caption = array();
      if (!empty($result)) {
        $caption = $result;
      }

      // Let the cache depends on the entity.
      // TODO: Use getCacheTags() to get the default list.
      $this->cacheBackend->set(
            $cacheKey,
            $caption,
            Cache::PERMANENT,
            [
              $field_name,
              'image_field_caption',
            ]
        );
    }

    return $caption;
  }

  
  public function insertCaption($entity_type, $bundle, $field_name, $entity_id, $revision_id, $language, $delta, $caption, $caption_format, $primary_cta, $primary_cta_url, $secondary_cta, $secondary_cta_url) {

    $query = $this->database->insert($this->tableData);
    $query
          ->fields(array(
            'entity_type' => $entity_type,
            'bundle' => $bundle,
            'field_name' => $field_name,
            'entity_id' => $entity_id,
            'revision_id' => $revision_id,
            'language' => $language,
            'delta' => $delta,
            'caption' => $caption,
            'caption_format' => $caption_format,
            'primary_cta' => $primary_cta,
            'primary_cta_url' => $primary_cta_url,
            'secondary_cta' => $secondary_cta,
            'secondary_cta_url' => $secondary_cta_url,
          ))
      ->execute();
    $this->clearCache($field_name);
  }

  
  public function insertCaptionRevision($entity_type, $bundle, $field_name, $entity_id, $revision_id, $language, $delta, $caption, $caption_format, $primary_cta, $primary_cta_url, $secondary_cta, $secondary_cta_url) {
    $query = $this->database->insert($this->tableRevision);
    $query
          ->fields(array(
            'entity_type' => $entity_type,
            'bundle' => $bundle,
            'field_name' => $field_name,
            'entity_id' => $entity_id,
            'revision_id' => $revision_id,
            'language' => $language,
            'delta' => $delta,
            'caption' => $caption,
            'caption_format' => $caption_format,
            'primary_cta' => $primary_cta,
            'primary_cta_url' => $primary_cta_url,
            'secondary_cta' => $secondary_cta,
            'secondary_cta_url' => $secondary_cta_url,
          ))
      ->execute();
    $this->clearCache($field_name);
  }

  
  public function deleteCaption($entity_type, $bundle, $field_name, $entity_id, $language) {
    $query = $this->database->delete($this->tableData);
    $query
          ->condition('entity_type', $entity_type, '=')
          ->condition('bundle', $bundle, '=')
          ->condition('field_name', $field_name, '=')
          ->condition('entity_id', $entity_id, '=')
          ->condition('language', $language, '=')
          ->execute();
    $this->clearCache($field_name);
    // @todo Try to return the count of the affected rows.
  }

  
  public function deleteCaptionRevision($entity_type, $bundle, $field_name, $entity_id, $revision_id, $language) {
    $query = $this->database->delete($this->tableRevision);
    $query
      ->condition('entity_type', $entity_type, '=')
      ->condition('bundle', $bundle, '=')
      ->condition('field_name', $field_name, '=')
      ->condition('entity_id', $entity_id, '=')
      ->condition('revision_id', $revision_id, '=')
      ->condition('language', $language, '=')
      ->execute();
    $this->clearCache($field_name);
    // @todo Try to return the count of the affected rows.
  }

 
  public function deleteCaptionRevisions($entity_type, $bundle, $field_name, $entity_id, $language) {
    $query = $this->database->delete($this->tableRevision);
    $query
      ->condition('entity_type', $entity_type, '=')
      ->condition('bundle', $bundle, '=')
      ->condition('field_name', $field_name, '=')
      ->condition('entity_id', $entity_id, '=')
      ->condition('language', $language, '=')
      ->execute();
    $this->clearCache($field_name);
    // @todo Try to return the count of the affected rows.
  }

  
  public function deleteCaptionRevisionsByRevisionId($revision_id) {
    $query = $this->database->delete($this->tableRevision);
    $query
      ->condition('revision_id', $revision_id, '=')
      ->execute();
  }

  
  public function clearCache($field_name) {
    $this->cacheTagsInvalidator->invalidateTags([
      $field_name,
      'image_field_caption',
    ]);
  }

  
  public function getCacheKey($entity_type, $entity_id, $revision_id, $language, $field_name, $delta, $primary_cta, $primary_cta_url, $secondary_cta, $secondary_cta_url) {
    return implode(
        ":",
        [
          'caption',
          $entity_type,
          $entity_id,
          $revision_id,
          $language,
          $field_name,
          $delta,
          $primary_cta,
          $primary_cta_url,
          $secondary_cta,
          $secondary_cta_url,
        ]
    );
  }
  
  public function list($key = 'entity_type') {
      $list = &drupal_static(__FUNCTION__);
    
      if (!isset($list[$key])) {
          // Query.
          $query = $this->database->select($this->tableData, 'ifc');
          $result = $query
              ->fields('ifc', array($key))
              ->distinct()
              ->execute()
              ->fetchAll();
    
          $list[$key] = [];
          foreach ($result as $row) {
              $list[$key][] = $row->{$key};
          }
      }
      
      return $list[$key];
  }

}
leymannx avatar
ne flag
We need to see the patch. And you don't get any error message?
id flag
Provide a minimal but working composer.json and the patch file to illustrate the issue.
liquidcms avatar
us flag
Try ./patches as your path.
Jaypan avatar
de flag
And show your actual terminal output that is failing
user109436 avatar
ug flag
it don’t show any error, output: Deprecation Notice: Creation of dynamic property cweagans\Composer\Patches::$installedPatches is deprecated in /Users/vina3139/www-bt3/vendor/cweagans/composer-patches/src/Patches.php:63 Gathering patches for root package. Removing package drupal/slick so that it can be re-installed and re-patched. - Removing drupal/slick (2.7.0) Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on current platform. Nothing to install, update or remove Deleting docroot/modules/contrib/slick - deleted
user109436 avatar
ug flag
Tried ./patches but still the same issue
Score:3
cn flag

A few things to know up-front:

  1. Composer patches has the concept of patch-levels. These correspond to the [-p strip-count] option of the patch command (and same for git apply).

    If you're not familiar with that option, it basically tells patch how many portions of the file path to strip off to find the files being patched. Or in other words, how many forward slashes and their preceding strings should be removed from the start of the path string.

  2. The package (module)'s path is used as the working directory for applying a patch (not the project root).

  3. By default, the plugin will make different attempts to apply the patch, in this order, failing silently until they're all exhausted:

    • -p1
    • -p0
    • -p2
    • -p4

    These are presumably the most common.

If you look at the paths in your patch:

diff --git a/docroot/modules/contrib/slick/css/layout/slick.module.css b/docroot/modules/contrib/slick/css/layout/slick.module.css

And apply the rules above, you need to remove 5 slashes to get the correct path (not 1, 0, 2, or 4), so the default fails.

There are two ways to fix:

  1. Change the paths in the patch file to, e.g.

    diff --git a/css/layout/slick.module.css b/css/layout/slick.module.css
    

    Above will satisfy -p1, you could also change it to match a different level

  2. Set the patchLevel manually for the project in composer.json:

    "extra": {
      ...
      "patchLevel": {
        ...
        "drupal/slick: "-p5"
      }
    }
    

If you use the second option, keep in mind it will apply to any patch you use for that module, so mixing local patches with ones from drupal.org won't work. The first option is probably best for predictability.

For future reference, you can create your patches with -p1 compatibility by using git options:

git -C path/to/modified/module diff --relative

This would get you the same as the first fix above:

diff --git a/css/layout/slick.module.css b/css/layout/slick.module.css
user109436 avatar
ug flag
Tried editing the patch file with the relative path but still it shows the output in composer as "Nothing to install, update or remove Deleting docroot/modules/contrib/slick - deleted" Edited Patch file: diff --git a/css/layout/slick.module.css b/css/layout/slick.module.css index 88b0d639f..3f4b10398 100644 --- a/css/layout/slick.module.css +++ b/css/layout/slick.module.css @@ -17,14 +17,15 @@
cn flag
You’ll need to run `composer update drupal/slick -W` after fixing the patch file. If that doesn’t work your generated files might be out of whack, so you may need to delete composer.lock, vendor, Drupal/core, etc, and run `composer install`. Be aware that would update any other packages without a fixed version number in composer.json
user109436 avatar
ug flag
Tried running "composer update drupal/slick -W" still the same issue and also deleted composer.lock, vender, core etc and executed "composer install" but still the same issue.
cn flag
I’m not sure what to tell you, there must be something non-standard about your installation or config, patching works fine for me
user109436 avatar
ug flag
diff --git a/modules/contrib/slick/css/layout/slick.module.css b/modules/contrib/slick/css/layout/slick.module.css This path works perfectly in local env but the same patch not adding patches in staging environment
user109436 avatar
ug flag
How to add patch for .install file ? I have added the code and the error I am getting in the above question. Can you help me to fix it.
Score:0
ua flag

As already pointed out, it should be ./patches/ if you have the patches folder in the Drupal root directory.

Furthermore, I see you're using a dev version that is fixed so it cannot be updated

"cweagans/composer-patches": "1.x-dev#4f3414441522dfeecff697f061ce27412a2b677b",

Instead, it should be

"cweagans/composer-patches": "^1.7",

So do the following:

  1. Remove the patch code part

            ,
            "drupal/slick": {
                "MTE-8015 - Slick slider changes 1": "./patches/slick/slick.patch"
            }
    
  2. Remove composer remove cweagans/composer-patches

  3. Re-add composer require cweagans/composer-patches

    • This should install 1.7 version. If not, do composer require cweagans/composer-patches:^1.7
  4. Re-add the patch code from #1

  5. Delete the module folder sudo rm -rf web/modules/contrib/slick/

Not sure if it's just me, but I could've sworn step #5 wasn't necessary! I just did this routine 2 days ago.. Updating the patches section alone should be good enough. But for some reason it's not working for me today. I think something funky must be going on somewhere... or I'm just not remembering correctly.

  1. Run composer update --lock and it should apply your patch
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.