首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么cweagans/composer补丁不为drupal/slick安装我的自定义修补程序?

为什么cweagans/composer补丁不为drupal/slick安装我的自定义修补程序?
EN

Drupal用户
提问于 2022-12-23 14:44:57
回答 2查看 663关注 0票数 4

基本上,我已经安装了精巧的模块和定制的代码,并使用"git“命令创建了一个补丁文件。光滑的模块文件路径是modules/contrib/slick/目录。下面是我在composser.json文件中编写的代码。

代码语言:javascript
复制
"require": {
        "drupal/slick": "^2.7",
}

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

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

但是在运行composer安装时,它只是从“模块/cont肋骨/ slick”中移除这个光滑的包,而不重新安装或添加修补程序。

如果我从composer.json中删除"Slick定制更改“:”修补程序/ slick /slick.补丁“并执行composer.json,那么它将安装slick模块。

如何避免删除此包并应用修补程序?

git apply >“修补程序/slick/slick.补丁”成功执行并应用补丁。但是composer安装无法应用修补程序。

已经安装了“cweagans/composer-修补程序”。

下面是补丁代码

代码语言:javascript
复制
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 @@
             {{ item.caption.alt }}
           {% endif %}
 
+          {% if item.caption.caption_img %}
+            {{ item.caption.caption_img }}
+          {% endif %}
+
+          {% if item.caption.caption_p_cta_url %}
+            
+              {{ item.caption.caption_p_cta }}
+            
+          {% endif %}
+
+          {% if item.caption.caption_s_cta_url %}
+            
+              {{ item.caption.caption_s_cta }}
+            
+          {% endif %}
+
           {% if item.caption.data %}
             {{ item.caption.data }}
           {% 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代码

代码语言:javascript
复制
{
    "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"
}

如何为.install文件应用修补程序?以下是.install文件的修补程序代码

代码语言:javascript
复制
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'),

当我发布暂存代码时,它显示了错误的"Drupal\Core\Database\DatabaseExceptionWrapper. SQLSTATE(42502):基本表或未找到的视图: 1146表'www.image_field_caption‘。剂量存在:从Drupal\image_field_caption\ImageCaptionStorage->list()(line 425 of module/contrib/image_field_caption/src/ImageCaptionStorage.php)“中的”image_field_caption“’ifc‘.数组()中选择”entity_type“作为”entity_type“。

下面是ImageCaptionStorage.php代码,它显示了函数“公共函数列表(){. ->execute() .}”的错误

代码语言:javascript
复制
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];
  }

}
EN

回答 2

Drupal用户

发布于 2022-12-23 17:33:06

有几件事要事先知道:

  1. Composer修补程序具有patch-levels的概念。它们对应于patch命令的D4选项(git apply也是如此)。如果您不熟悉该选项,它基本上会告诉patch需要去掉多少部分文件路径才能找到正在修补的文件。换句话说,应该从路径字符串的开头移除多少个正斜杠及其前面的字符串。
  2. 包(模块)的S路径用作应用修补程序的工作目录(而不是项目根目录)。
  3. 默认情况下,该插件将按以下顺序尝试应用修补程序,直到它们都耗尽为止,它一直在默默地失败:
    • -p1
    • -p0
    • -p2
    • -p4

这些大概是最常见的。

如果您查看修补程序中的路径:

代码语言:javascript
复制
diff --git a/docroot/modules/contrib/slick/css/layout/slick.module.css b/docroot/modules/contrib/slick/css/layout/slick.module.css

应用上面的规则,您需要删除5个斜杠以获得正确的路径(而不是1、0、2或4),因此默认情况失败。

有两种方法可以修复:

  1. 将补丁文件中的路径更改为,例如diff --git a/css/layout/slick.module.css /css/layout/slick.module.css将满足-p1,您也可以更改它以匹配不同的级别。
  2. 手动为项目设置patchLevel:“composer.json”:{."patchLevel":{。"drupal/slick:"-p5“}

如果您使用第二个选项,请记住,它将应用于您为该模块使用的任何修补程序,因此将本地补丁与来自drupal.org的修补程序混合使用是行不通的。第一种选择对可预见性来说可能是最好的。

对于将来的参考,您可以使用git选项创建具有-p1兼容性的修补程序:

代码语言:javascript
复制
git -C path/to/modified/module diff --relative

这将使您获得与上面的第一个修复相同的结果:

代码语言:javascript
复制
diff --git a/css/layout/slick.module.css b/css/layout/slick.module.css
票数 3
EN

Drupal用户

发布于 2023-01-13 09:30:19

如前所述,如果Drupal根目录中有修补程序文件夹,则应该是./patches/

此外,我看到您使用的是一个已修复的dev版本,因此无法更新

代码语言:javascript
复制
"cweagans/composer-patches": "1.x-dev#4f3414441522dfeecff697f061ce27412a2b677b",

相反,它应该是

代码语言:javascript
复制
"cweagans/composer-patches": "^1.7",

以下几点也是如此:

  1. 删除补丁代码部分,"drupal/ Slick ":{ "MTE-8015 -光滑滑块更改1":“./修补程序/slick/slick.修补程序”}
  2. 删除composer remove cweagans/composer-patches
  3. 重新添加composer require cweagans/composer-patches
    • 这应该安装1.7版本。如果没有,请执行composer require cweagans/composer-patches:^1.7

  4. 重新添加#1中的修补程序代码
  5. 删除模块文件夹sudo rm -rf web/modules/contrib/slick/

不知道是不是只有我,但我可以发誓第五步是不必要的!我两天前才做过这个例行公事。仅更新修补程序部分就足够了。但出于某种原因它今天对我不起作用。我想一定有什么奇怪的事情在某处发生.或者我记错了。

  1. 运行composer update --lock,它应该应用您的修补程序
票数 0
EN
页面原文内容由Drupal提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://drupal.stackexchange.com/questions/314142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档