From 92fbd150b5ee0925d8d8ffe38c1ee79f91b4f43e Mon Sep 17 00:00:00 2001
From: skaught <38603-SKAUGHT@users.noreply.drupalcode.org>
Date: Mon, 8 Jul 2024 16:13:15 +0000
Subject: [PATCH] Issue #3447620: Declare compatibility with Drupal 11

---
 .gitlab-ci.yml                                | 25 +++++++++++++++++++
 composer.json                                 |  2 +-
 crop.info.yml                                 |  2 +-
 crop.module                                   |  7 +++---
 .../crop_media_entity.info.yml                |  2 +-
 src/CropInterface.php                         |  3 +++
 src/CropTypeListBuilder.php                   | 10 ++++----
 src/Entity/Crop.php                           |  5 ++--
 src/EntityProviderBase.php                    |  2 +-
 src/Events/AutomaticCrop.php                  |  7 ++++--
 src/Form/CropTypeDeleteForm.php               |  1 -
 src/Form/CropTypeForm.php                     |  2 +-
 src/Plugin/ImageEffect/CropEffect.php         | 12 ++++-----
 ...pectRatioValidationConstraintValidator.php |  7 ------
 ...chineNameValidationConstraintValidator.php |  7 ------
 tests/src/Functional/CropFunctionalTest.php   |  9 ++-----
 tests/src/Kernel/CropCRUDTest.php             |  2 +-
 tests/src/Kernel/CropEffectTest.php           |  4 +--
 tests/src/Kernel/CropUnitTestBase.php         |  2 +-
 19 files changed, 61 insertions(+), 50 deletions(-)
 create mode 100644 .gitlab-ci.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..da927e0
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,25 @@
+include:
+  ################
+  # DrupalCI includes:
+  # As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
+  # View these include files at https://git.drupalcode.org/project/gitlab_templates/
+  ################
+  - project: $_GITLAB_TEMPLATES_REPO
+    ref: $_GITLAB_TEMPLATES_REF
+    file:
+      - '/includes/include.drupalci.main.yml'
+      - '/includes/include.drupalci.variables.yml'
+      - '/includes/include.drupalci.workflows.yml'
+
+################
+# Pipeline configuration variables
+#
+# These are the variables provided to the Run Pipeline form that a user may want to override.
+#
+# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml
+################
+variables:
+  OPT_IN_TEST_PREVIOUS_MAJOR: 1
+  OPT_IN_TEST_PREVIOUS_MINOR: 1
+  OPT_IN_TEST_NEXT_MINOR: 1
+  OPT_IN_TEST_NEXT_MAJOR: 1
diff --git a/composer.json b/composer.json
index bf249d2..a8292bb 100644
--- a/composer.json
+++ b/composer.json
@@ -8,6 +8,6 @@
   },
   "license": "GPL-2.0-or-later",
   "require": {
-    "drupal/core": "^9.3 || ^10"
+    "drupal/core": "^9.3 || ^10 || ^11"
   }
 }
diff --git a/crop.info.yml b/crop.info.yml
index 774f869..0269e73 100644
--- a/crop.info.yml
+++ b/crop.info.yml
@@ -1,6 +1,6 @@
 name: Crop API
 description: 'Provides storage and API for image crops.'
-core_version_requirement: '^9.3 || ^10'
+core_version_requirement: '^9.3 || ^10 || ^11'
 package: Media
 type: module
 dependencies:
diff --git a/crop.module b/crop.module
index aa7d5f8..6ce1395 100644
--- a/crop.module
+++ b/crop.module
@@ -9,13 +9,12 @@
 
 use Drupal\Component\Utility\UrlHelper;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\StreamWrapper\StreamWrapperManager;
 use Drupal\crop\Entity\Crop;
-use Drupal\image\Entity\ImageStyle;
+use Drupal\file\FileInterface;
 use Drupal\media\MediaSourceInterface;
 use Drupal\media\MediaTypeInterface;
-use Drupal\file\FileInterface;
-use Drupal\Core\Routing\RouteMatchInterface;
-use Drupal\Core\StreamWrapper\StreamWrapperManager;
 
 /**
  * Implements hook_theme().
diff --git a/modules/crop_media_entity/crop_media_entity.info.yml b/modules/crop_media_entity/crop_media_entity.info.yml
index 70abdbf..49b0d91 100644
--- a/modules/crop_media_entity/crop_media_entity.info.yml
+++ b/modules/crop_media_entity/crop_media_entity.info.yml
@@ -1,6 +1,6 @@
 name: Media entity crop
 description: 'Deprecated.'
-core_version_requirement: '^9.3 || ^10'
+core_version_requirement: '^9.3 || ^10 || ^11'
 package: Media
 type: module
 hidden: true
diff --git a/src/CropInterface.php b/src/CropInterface.php
index f37c872..78c185e 100644
--- a/src/CropInterface.php
+++ b/src/CropInterface.php
@@ -7,6 +7,9 @@ use Drupal\image\ImageStyleInterface;
 
 /**
  * Provides an interface defining the crop entity.
+ *
+ * @phpcs:disable Drupal.Commenting.Deprecated.DeprecatedMissingSeeTag
+ * @phpcs:disable Drupal.Commenting.Deprecated.IncorrectTextLayout
  */
 interface CropInterface extends ContentEntityInterface {
 
diff --git a/src/CropTypeListBuilder.php b/src/CropTypeListBuilder.php
index 8c845ee..60b4bab 100644
--- a/src/CropTypeListBuilder.php
+++ b/src/CropTypeListBuilder.php
@@ -2,15 +2,15 @@
 
 namespace Drupal\crop;
 
+use Drupal\Component\Utility\Xss;
 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
-use Drupal\Core\Entity\EntityTypeManagerInterface;
-use Drupal\Core\Entity\EntityTypeInterface;
-use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Routing\UrlGeneratorInterface;
-use Drupal\Core\Entity\EntityInterface;
-use Drupal\Component\Utility\Xss;
 use Drupal\image\Entity\ImageStyle;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Defines a class to build a listing of crop type entities.
diff --git a/src/Entity/Crop.php b/src/Entity/Crop.php
index 9266d13..6bd6b7f 100644
--- a/src/Entity/Crop.php
+++ b/src/Entity/Crop.php
@@ -151,6 +151,7 @@ class Crop extends ContentEntityBase implements CropInterface {
    * {@inheritdoc}
    */
   public static function getCropFromImageStyle($uri, ImageStyleInterface $image_style) {
+    //phpcs:ignore Drupal.Semantics.FunctionTriggerError.TriggerErrorTextLayoutRelaxed
     @trigger_error('Crop::getCropFromImageStyle() is deprecated, use Crop::getCropFromImageStyleId() instead.', E_USER_DEPRECATED);
     return static::getCropFromImageStyleId($uri, $image_style->id());
   }
@@ -321,8 +322,8 @@ class Crop extends ContentEntityBase implements CropInterface {
 
     // Denormalized information, which is calculated in storage plugin for a
     // given entity type. Saved here for performance reasons in image effects.
-    // ---
-    // TODO - we are not enforcing uniqueness on this as we want to support more
+    // ---.
+    // @todo we are not enforcing uniqueness on this as we want to support more
     // crops per same image/image_style combination. However, image effect
     // operates with image URI only, which means we have no mechanism to
     // distinguish between multiple crops in there. If we really want to
diff --git a/src/EntityProviderBase.php b/src/EntityProviderBase.php
index 0a379a1..114a84b 100644
--- a/src/EntityProviderBase.php
+++ b/src/EntityProviderBase.php
@@ -14,7 +14,7 @@ abstract class EntityProviderBase extends PluginBase implements EntityProviderIn
    * {@inheritdoc}
    */
   public function label() {
-    $this->pluginDefinition['label'];
+    return $this->pluginDefinition['label'];
   }
 
   /**
diff --git a/src/Events/AutomaticCrop.php b/src/Events/AutomaticCrop.php
index c0ed875..db42d57 100644
--- a/src/Events/AutomaticCrop.php
+++ b/src/Events/AutomaticCrop.php
@@ -2,10 +2,10 @@
 
 namespace Drupal\crop\Events;
 
+use Drupal\Component\EventDispatcher\Event;
 use Drupal\Core\Image\ImageInterface;
 use Drupal\crop\CropInterface;
 use Drupal\crop\Entity\CropType;
-use Drupal\Component\EventDispatcher\Event;
 
 /**
  * Represents automatic crop action as event.
@@ -45,8 +45,11 @@ class AutomaticCrop extends Event {
    * Constructs a EntitySelectionEvent object.
    *
    * @param \Drupal\Core\Image\ImageInterface $image
+   *   An image object.
    * @param \Drupal\crop\Entity\CropType $cropType
-   * @param $configuration
+   *   A crop_type object.
+   * @param array $configuration
+   *   An array of configurations.
    */
   public function __construct(ImageInterface $image, CropType $cropType, array $configuration) {
     $this->image = $image;
diff --git a/src/Form/CropTypeDeleteForm.php b/src/Form/CropTypeDeleteForm.php
index 7ad44de..8a79d7a 100644
--- a/src/Form/CropTypeDeleteForm.php
+++ b/src/Form/CropTypeDeleteForm.php
@@ -3,7 +3,6 @@
 namespace Drupal\crop\Form;
 
 use Drupal\Core\Entity\EntityConfirmFormBase;
-use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\StringTranslation\TranslationInterface;
 use Drupal\Core\Url;
diff --git a/src/Form/CropTypeForm.php b/src/Form/CropTypeForm.php
index be8db52..34309ae 100644
--- a/src/Form/CropTypeForm.php
+++ b/src/Form/CropTypeForm.php
@@ -179,7 +179,7 @@ class CropTypeForm extends EntityForm {
       $this->logger('crop')->notice('Added crop type %name.', $context);
     }
 
-    $form_state->setRedirect('crop.overview_types');
+    return $form_state->setRedirect('crop.overview_types');
   }
 
 }
diff --git a/src/Plugin/ImageEffect/CropEffect.php b/src/Plugin/ImageEffect/CropEffect.php
index af27c8c..770664f 100644
--- a/src/Plugin/ImageEffect/CropEffect.php
+++ b/src/Plugin/ImageEffect/CropEffect.php
@@ -118,12 +118,12 @@ class CropEffect extends ConfigurableImageEffectBase implements ContainerFactory
 
     if (!$image->crop($anchor['x'], $anchor['y'], $size['width'], $size['height'])) {
       $this->logger->error('Manual image crop failed using the %toolkit toolkit on %path (%mimetype, %width x %height)', [
-          '%toolkit' => $image->getToolkitId(),
-          '%path' => $image->getSource(),
-          '%mimetype' => $image->getMimeType(),
-          '%width' => $image->getWidth(),
-          '%height' => $image->getHeight(),
-        ]
+        '%toolkit' => $image->getToolkitId(),
+        '%path' => $image->getSource(),
+        '%mimetype' => $image->getMimeType(),
+        '%width' => $image->getWidth(),
+        '%height' => $image->getHeight(),
+      ]
       );
       return FALSE;
     }
diff --git a/src/Plugin/Validation/Constraint/CropTypeAspectRatioValidationConstraintValidator.php b/src/Plugin/Validation/Constraint/CropTypeAspectRatioValidationConstraintValidator.php
index 4de8d00..3221789 100644
--- a/src/Plugin/Validation/Constraint/CropTypeAspectRatioValidationConstraintValidator.php
+++ b/src/Plugin/Validation/Constraint/CropTypeAspectRatioValidationConstraintValidator.php
@@ -10,13 +10,6 @@ use Symfony\Component\Validator\ConstraintValidator;
  */
 class CropTypeAspectRatioValidationConstraintValidator extends ConstraintValidator {
 
-  /**
-   * Validator 2.5 and upwards compatible execution context.
-   *
-   * @var \Symfony\Component\Validator\Context\ExecutionContextInterface
-   */
-  protected $context;
-
   /**
    * {@inheritdoc}
    */
diff --git a/src/Plugin/Validation/Constraint/CropTypeMachineNameValidationConstraintValidator.php b/src/Plugin/Validation/Constraint/CropTypeMachineNameValidationConstraintValidator.php
index 977155d..29fb524 100644
--- a/src/Plugin/Validation/Constraint/CropTypeMachineNameValidationConstraintValidator.php
+++ b/src/Plugin/Validation/Constraint/CropTypeMachineNameValidationConstraintValidator.php
@@ -10,13 +10,6 @@ use Symfony\Component\Validator\ConstraintValidator;
  */
 class CropTypeMachineNameValidationConstraintValidator extends ConstraintValidator {
 
-  /**
-   * Validator 2.5 and upwards compatible execution context.
-   *
-   * @var \Symfony\Component\Validator\Context\ExecutionContextInterface
-   */
-  protected $context;
-
   /**
    * {@inheritdoc}
    */
diff --git a/tests/src/Functional/CropFunctionalTest.php b/tests/src/Functional/CropFunctionalTest.php
index 677c5de..06ecfd4 100644
--- a/tests/src/Functional/CropFunctionalTest.php
+++ b/tests/src/Functional/CropFunctionalTest.php
@@ -6,8 +6,8 @@ use Drupal\Core\StreamWrapper\PublicStream;
 use Drupal\crop\Entity\Crop;
 use Drupal\crop\Entity\CropType;
 use Drupal\file\Entity\File;
-use Drupal\Tests\BrowserTestBase;
 use Drupal\file\FileInterface;
+use Drupal\Tests\BrowserTestBase;
 
 /**
  * Functional tests for crop API.
@@ -77,7 +77,6 @@ class CropFunctionalTest extends BrowserTestBase {
     $this->drupalGet('admin/config/media/crop/add');
     $this->assertSession()->statusCodeEquals(403);
 
-
     // Can access pages if logged in and no crop types exist.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('admin/config/media/crop');
@@ -90,13 +89,12 @@ class CropFunctionalTest extends BrowserTestBase {
     $this->assertSession()->statusCodeEquals(200);
     $this->assertSession()->addressEquals('admin/config/media/crop/add');
 
-
     // Create crop type.
     $crop_type_id = strtolower($this->randomMachineName());
     $edit = [
       'id' => $crop_type_id,
       'label' => $this->randomMachineName(),
-      'description' => $this->randomGenerator->sentences(10),
+      'description' => $this->getRandomGenerator()->word(10),
     ];
     $this->drupalGet('admin/config/media/crop/add');
     $this->submitForm($edit, 'Save crop type');
@@ -107,7 +105,6 @@ class CropFunctionalTest extends BrowserTestBase {
     self::assertTrue(strpos($label[0]->getText(), $edit['label']) !== FALSE, 'Crop type label found on listing page.');
     $this->assertSession()->pageTextContains($edit['description']);
 
-
     // Check edit form.
     $this->clickLink(t('Edit'));
     $this->assertSession()->pageTextContains(t('Edit @name crop type', ['@name' => $edit['label']]));
@@ -116,7 +113,6 @@ class CropFunctionalTest extends BrowserTestBase {
     $this->assertSession()->fieldExists('edit-label');
     $this->assertSession()->responseContains($edit['description']);
 
-
     // See if crop type appears on image effect configuration form.
     $this->drupalGet('admin/config/media/image-styles/manage/' . $this->testStyle->id() . '/add/crop_crop');
     $option = $this->xpath("//select[@id='edit-data-crop-type']/option");
@@ -145,7 +141,6 @@ class CropFunctionalTest extends BrowserTestBase {
     $this->submitForm($edit, 'Save crop type');
     $this->assertSession()->pageTextContains(t('The machine-readable name is already in use. It must be unique.'));
 
-
     // Delete crop type.
     $this->drupalGet('admin/config/media/crop');
     $this->assertSession()->linkExists('Test image style');
diff --git a/tests/src/Kernel/CropCRUDTest.php b/tests/src/Kernel/CropCRUDTest.php
index aa69839..2d2f7bb 100644
--- a/tests/src/Kernel/CropCRUDTest.php
+++ b/tests/src/Kernel/CropCRUDTest.php
@@ -26,7 +26,7 @@ class CropCRUDTest extends CropUnitTestBase {
     $values = [
       'id' => $this->randomMachineName(),
       'label' => $this->randomString(),
-      'description' => $this->randomGenerator->sentences(8),
+      'description' => $this->getRandomGenerator()->word(8),
     ];
     $crop_type = $this->cropTypeStorage->create($values);
 
diff --git a/tests/src/Kernel/CropEffectTest.php b/tests/src/Kernel/CropEffectTest.php
index fca6575..702071e 100644
--- a/tests/src/Kernel/CropEffectTest.php
+++ b/tests/src/Kernel/CropEffectTest.php
@@ -65,7 +65,7 @@ class CropEffectTest extends CropUnitTestBase {
   /**
    * Test image crop effect dimensions.
    */
-  public function testCropDimenssions() {
+  public function testCropDimensions() {
     // Create image to be cropped.
     $file = $this->getTestFile();
     $file->save();
@@ -88,7 +88,7 @@ class CropEffectTest extends CropUnitTestBase {
     $crop = $this->container->get('entity_type.manager')->getStorage('crop')->create($values);
     $crop->save();
 
-    /** @var $effect \Drupal\crop\Plugin\ImageEffect\CropEffect */
+    /** @var \Drupal\crop\Plugin\ImageEffect\CropEffect $effect */
     $effect = $this->imageEffectManager->createInstance('crop_crop', ['data' => ['crop_type' => $this->cropType->id()]]);
     $effect->transformDimensions($dimensions, $file_uri);
 
diff --git a/tests/src/Kernel/CropUnitTestBase.php b/tests/src/Kernel/CropUnitTestBase.php
index 82487a3..7ceb824 100644
--- a/tests/src/Kernel/CropUnitTestBase.php
+++ b/tests/src/Kernel/CropUnitTestBase.php
@@ -3,8 +3,8 @@
 namespace Drupal\Tests\crop\Kernel;
 
 use Drupal\Core\StreamWrapper\PublicStream;
-use Drupal\KernelTests\KernelTestBase;
 use Drupal\file\FileInterface;
+use Drupal\KernelTests\KernelTestBase;
 
 /**
  * Tests the crop entity CRUD operations.
-- 
GitLab