From 03390f7786238d6aa1bb8efb1ee656ba440aafc4 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 11:54:43 +0000 Subject: [PATCH 01/54] Add Drupal core 11 to composer.json. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 896a335..43c3182 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "drupal-module", "license": "GPL-2.0-or-later", "require": { - "drupal/core": "~8 || ~9 || ~10", + "drupal/core": "~8 || ~9 || ~10 || ~11", "drupal/entity_browser": "^2 || ^1", "drupal/dropzonejs": "^2", "drupal/embed": "^1", -- GitLab From a8e52f32abef7f8b996f8f3081848e4e386a09fd Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 11:59:30 +0000 Subject: [PATCH 02/54] Add .gitlab-ci.yml. Update composer.json and info.yml with Drupal 11 compatibility. --- .gitlab-ci.yml | 53 +++++++++++++++++++++++++++++++++++++++++++ composer.json | 4 ++-- file_browser.info.yml | 3 +-- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..41da1f6 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,53 @@ +################ +# DrupalCI GitLabCI template +# +# Gitlab-ci.yml to replicate DrupalCI testing for Contrib +# +# With thanks to: +# * The GitLab Acceleration Initiative participants +# * DrupalSpoons +################ + +################ +# Guidelines +# +# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained. +# +# However, you can modify this template if you have additional needs for your project. +################ + +################ +# Includes +# +# Additional configuration can be provided through includes. +# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include. +# +# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml +# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values +################ + +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' + # EXPERIMENTAL: For Drupal 7, remove the above line and uncomment the below. + # - '/includes/include.drupalci.main-d7.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: + # Convenient, and we have no secrets. + _SHOW_ENVIRONMENT_VARIABLES: 1 diff --git a/composer.json b/composer.json index 43c3182..6b7e157 100644 --- a/composer.json +++ b/composer.json @@ -4,10 +4,10 @@ "type": "drupal-module", "license": "GPL-2.0-or-later", "require": { - "drupal/core": "~8 || ~9 || ~10 || ~11", - "drupal/entity_browser": "^2 || ^1", + "drupal/core": ">=8", "drupal/dropzonejs": "^2", "drupal/embed": "^1", + "drupal/entity_browser": "^2 || ^1", "drupal/entity_embed": "^1" }, "require-dev": { diff --git a/file_browser.info.yml b/file_browser.info.yml index 576b4a5..09588d7 100644 --- a/file_browser.info.yml +++ b/file_browser.info.yml @@ -1,8 +1,7 @@ name: File Browser description: 'Provides a default Entity Browser for files, using Masonry and Imagesloaded.' type: module -core: 8.x -core_version_requirement: ^8 || ^9 || ^10 +core_version_requirement: ^10 || ^11 dependencies: - entity_browser:entity_browser - entity_embed:entity_embed -- GitLab From 267486e0377a54ad8eead5208d72ee9d322f0554 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 12:19:39 +0000 Subject: [PATCH 03/54] Change reference to stable to stable9 in InstallTest.php --- tests/src/Functional/InstallTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Functional/InstallTest.php b/tests/src/Functional/InstallTest.php index e18add8..f5ed50a 100644 --- a/tests/src/Functional/InstallTest.php +++ b/tests/src/Functional/InstallTest.php @@ -22,7 +22,7 @@ class InstallTest extends BrowserTestBase { /** * {@inheritdoc} */ - protected $defaultTheme = 'stable'; + protected $defaultTheme = 'stable9'; /** * {@inheritdoc} -- GitLab From df257a23800a244f2d61925296729bfe14be22dd Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 12:51:03 +0000 Subject: [PATCH 04/54] Change isset()s to null coalesce operators. Use short array syntax in FileBrowserPreview.php --- src/Plugin/Block/ImageEmbedBlock.php | 7 ++++--- src/Plugin/views/field/FileBrowserPreview.php | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Plugin/Block/ImageEmbedBlock.php b/src/Plugin/Block/ImageEmbedBlock.php index d55a4bf..c79613b 100644 --- a/src/Plugin/Block/ImageEmbedBlock.php +++ b/src/Plugin/Block/ImageEmbedBlock.php @@ -45,7 +45,8 @@ class ImageEmbedBlock extends BlockBase { ], []); $files = []; foreach ($entities as $entity) { - $settings = isset($table[$entity->id()]) ? $table[$entity->id()] : []; + $settings = $table[$entity->id()]) ?? $table[$entity->id()]; + $settings = $table[$entity->id()]) ?? []; $settings['fid'] = $entity->id(); $files[] = $settings; } @@ -148,7 +149,7 @@ class ImageEmbedBlock extends BlockBase { 'alt' => [ '#type' => 'textfield', '#title' => $this->t('Alternative text'), - '#default_value' => isset($info['settings']['alt']) ? $info['settings']['alt'] : '', + '#default_value' => $info['settings']['alt']) ?? '', '#size' => 45, '#maxlength' => 512, '#description' => $this->t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'), @@ -229,7 +230,7 @@ class ImageEmbedBlock extends BlockBase { '#theme' => 'image', '#width' => $width, '#height' => $height, - '#alt' => isset($info['settings']['alt']) ? $info['settings']['alt'] : '', + '#alt' => $info['settings']['alt']) ?? '', '#uri' => $uri, ]; diff --git a/src/Plugin/views/field/FileBrowserPreview.php b/src/Plugin/views/field/FileBrowserPreview.php index 51a8716..3325ee8 100644 --- a/src/Plugin/views/field/FileBrowserPreview.php +++ b/src/Plugin/views/field/FileBrowserPreview.php @@ -69,7 +69,8 @@ class FileBrowserPreview extends FieldPluginBase { // Loading large files is slow, make sure it is an image mime type before // doing that. - list($type,) = explode('/', $file->getMimeType(), 2); + [$type] = explode('/', $file->getMimeType(), 2); + if ($type == 'image' && ($image = $image_factory->get($file->getFileUri())) && $image->isValid()) { // Fake an ImageItem object. $item = new \stdClass(); -- GitLab From f7daa345a3ebe05a80d108eeb5ef5a64ecd142f8 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 13:02:21 +0000 Subject: [PATCH 05/54] Fix malformed null coalesce in ImageEmbedBlock.php --- src/Plugin/Block/ImageEmbedBlock.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Plugin/Block/ImageEmbedBlock.php b/src/Plugin/Block/ImageEmbedBlock.php index c79613b..4564ba5 100644 --- a/src/Plugin/Block/ImageEmbedBlock.php +++ b/src/Plugin/Block/ImageEmbedBlock.php @@ -45,7 +45,6 @@ class ImageEmbedBlock extends BlockBase { ], []); $files = []; foreach ($entities as $entity) { - $settings = $table[$entity->id()]) ?? $table[$entity->id()]; $settings = $table[$entity->id()]) ?? []; $settings['fid'] = $entity->id(); $files[] = $settings; -- GitLab From 7c4046be3745033d846d24fb825e35ad149e0e3d Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 13:07:47 +0000 Subject: [PATCH 06/54] Fix null coalesce error on line 49 of ImageEmbedBlock.php --- src/Plugin/Block/ImageEmbedBlock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/Block/ImageEmbedBlock.php b/src/Plugin/Block/ImageEmbedBlock.php index 4564ba5..6dae2b3 100644 --- a/src/Plugin/Block/ImageEmbedBlock.php +++ b/src/Plugin/Block/ImageEmbedBlock.php @@ -45,7 +45,7 @@ class ImageEmbedBlock extends BlockBase { ], []); $files = []; foreach ($entities as $entity) { - $settings = $table[$entity->id()]) ?? []; + $settings = $table[$entity->id()] ?? []; $settings['fid'] = $entity->id(); $files[] = $settings; } -- GitLab From 3a6fe944105931ec3c3f849bceec7a5f41f0b1c0 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 13:11:43 +0000 Subject: [PATCH 07/54] Fix another null coalesce issue. --- src/Plugin/Block/ImageEmbedBlock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugin/Block/ImageEmbedBlock.php b/src/Plugin/Block/ImageEmbedBlock.php index 6dae2b3..4776b01 100644 --- a/src/Plugin/Block/ImageEmbedBlock.php +++ b/src/Plugin/Block/ImageEmbedBlock.php @@ -148,7 +148,7 @@ class ImageEmbedBlock extends BlockBase { 'alt' => [ '#type' => 'textfield', '#title' => $this->t('Alternative text'), - '#default_value' => $info['settings']['alt']) ?? '', + '#default_value' => $info['settings']['alt'] ?? '', '#size' => 45, '#maxlength' => 512, '#description' => $this->t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'), @@ -229,7 +229,7 @@ class ImageEmbedBlock extends BlockBase { '#theme' => 'image', '#width' => $width, '#height' => $height, - '#alt' => $info['settings']['alt']) ?? '', + '#alt' => $info['settings']['alt'] ?? '', '#uri' => $uri, ]; -- GitLab From fb32400bf18234aac4889e194b626e6f19cadd5a Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 13:23:28 +0000 Subject: [PATCH 08/54] Add dropzonejs to modules protected static variable. --- tests/src/Functional/InstallTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Functional/InstallTest.php b/tests/src/Functional/InstallTest.php index f5ed50a..1771f30 100644 --- a/tests/src/Functional/InstallTest.php +++ b/tests/src/Functional/InstallTest.php @@ -27,7 +27,7 @@ class InstallTest extends BrowserTestBase { /** * {@inheritdoc} */ - protected static $modules = ['file_browser']; + protected static $modules = ['file_browser', 'dropzonejs']; /** * Tests if the module can be installed during a config sync. -- GitLab From 0896eb10c8686b5122d365a95568b56ccff4c8cd Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 13:32:41 +0000 Subject: [PATCH 09/54] Add dropzonejs to pretected static $modules variable in FileBrowserTest.php as well. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 2a670bb..34fee0e 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -16,6 +16,7 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { */ protected static $modules = [ 'file_browser', + 'dropzonejs', ]; /** -- GitLab From 3adab904c9b910a1c2b91983b120fddb9cc52c7d Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 16:59:04 +0000 Subject: [PATCH 10/54] Add before_script in gitlab-ci which pulls in dropzone library so it's available for test runner. --- .gitlab-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 41da1f6..97314ee 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,3 +51,7 @@ include: variables: # Convenient, and we have no secrets. _SHOW_ENVIRONMENT_VARIABLES: 1 + +before_script: + - mkdir -p web/libraries/dropzone + - curl -L https://raw.githubusercontent.com/dropzone/dropzone/main/src/dropzone.js -o web/libraries/dropzone/dropzone.min.js -- GitLab From 44a4d3397360c2a955484fa2b099237802d8baf5 Mon Sep 17 00:00:00 2001 From: Lucas Hedding <24691-lucashedding@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 17:55:16 +0000 Subject: [PATCH 11/54] Update .gitlab-ci.yml file --- .gitlab-ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 97314ee..a68c959 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,6 +52,7 @@ variables: # Convenient, and we have no secrets. _SHOW_ENVIRONMENT_VARIABLES: 1 -before_script: - - mkdir -p web/libraries/dropzone - - curl -L https://raw.githubusercontent.com/dropzone/dropzone/main/src/dropzone.js -o web/libraries/dropzone/dropzone.min.js +phpunit: + before_script: + - mkdir -p web/libraries/dropzone + - curl -L https://raw.githubusercontent.com/dropzone/dropzone/main/src/dropzone.js -o web/libraries/dropzone/dropzone.min.js -- GitLab From db525c866b56c84a1eb4bd4dd9786bd0c92b51ce Mon Sep 17 00:00:00 2001 From: Lucas Hedding <24691-lucashedding@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 17:59:31 +0000 Subject: [PATCH 12/54] Edit composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6b7e157..c19272f 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "drupal-module", "license": "GPL-2.0-or-later", "require": { - "drupal/core": ">=8", + "drupal/core": "~8 || ~9 || ~10 || ~11", "drupal/dropzonejs": "^2", "drupal/embed": "^1", "drupal/entity_browser": "^2 || ^1", -- GitLab From 758754dc3bf2353f99849d2c88dbafbfd67e39e4 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 18:23:09 +0000 Subject: [PATCH 13/54] Replace instances of libraries_get_path() with a Drupal service. --- file_browser.install | 4 ++-- file_browser.module | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/file_browser.install b/file_browser.install index c8e2e63..fb2aefd 100644 --- a/file_browser.install +++ b/file_browser.install @@ -47,8 +47,8 @@ function file_browser_requirements($phase) { // Optionally use the Libraries module to determine our library paths. if (\Drupal::moduleHandler()->moduleExists('libraries')) { - $imagesloaded_path = libraries_get_path('imagesloaded') . '/imagesloaded.pkgd.min.js'; - $masonry_path = libraries_get_path('masonry') . '/dist/masonry.pkgd.min.js'; + $imagesloaded_path = \Drupal::service('extension.path.resolver')->getPath('library', 'imagesloaded') . '/imagesloaded.pkgd.min.js'; + $masonry_path = \Drupal::service('extension.path.resolver')->getPath('library', 'masonry') . '/dist/masonry.pkgd.min.js'; } else { $imagesloaded_path = DRUPAL_ROOT . '/libraries/imagesloaded/imagesloaded.pkgd.min.js'; diff --git a/file_browser.module b/file_browser.module index 3cc240a..e6b0110 100644 --- a/file_browser.module +++ b/file_browser.module @@ -71,8 +71,8 @@ function file_browser_preprocess_details(&$variables) { function file_browser_library_info_alter(&$libraries, $extension) { // Optionally use the Libraries module to determine our library paths. if ($extension == 'file_browser' && \Drupal::moduleHandler()->moduleExists('libraries')) { - $imagesloaded_path = libraries_get_path('imagesloaded') . '/imagesloaded.pkgd.min.js'; - $masonry_path = libraries_get_path('masonry') . '/dist/masonry.pkgd.min.js'; + $imagesloaded_path = \Drupal::service('extension.path.resolver')->getPath('library', 'imagesloaded') . '/imagesloaded.pkgd.min.js'; + $masonry_path = \Drupal::service('extension.path.resolver')->getPath('library', 'masonry') . '/dist/masonry.pkgd.min.js'; $libraries['imagesloaded']['js'] = ['/' . $imagesloaded_path => ['minified' => 'true']]; $libraries['masonry']['js'] = ['/' . $masonry_path => ['minified' => 'true']]; -- GitLab From 0e2fe7a49b7144197353c665aa6ba8a13986684b Mon Sep 17 00:00:00 2001 From: Lucas Hedding <24691-lucashedding@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 19:07:30 +0000 Subject: [PATCH 14/54] Edit .gitlab-ci.yml --- .gitlab-ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a68c959..50dc00b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,8 +51,12 @@ include: variables: # Convenient, and we have no secrets. _SHOW_ENVIRONMENT_VARIABLES: 1 + DROPZONE_VERSION: v6.0.0-beta.2 phpunit: before_script: - - mkdir -p web/libraries/dropzone - - curl -L https://raw.githubusercontent.com/dropzone/dropzone/main/src/dropzone.js -o web/libraries/dropzone/dropzone.min.js + - mkdir $_WEB_ROOT/libraries + - cd $_WEB_ROOT/libraries + - curl -L https://github.com/dropzone/dropzone/releases/download/$DROPZONE_VERSION/dist.zip -o dropzone.zip --silent + - unzip dropzone.zip + - mv dist dropzone -- GitLab From a99f6aa512280d2fca8ccd09cd3389bee46f09a2 Mon Sep 17 00:00:00 2001 From: Lucas Hedding <24691-lucashedding@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 19:13:41 +0000 Subject: [PATCH 15/54] Edit .gitlab-ci.yml --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 50dc00b..9b9b6ab 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -53,8 +53,8 @@ variables: _SHOW_ENVIRONMENT_VARIABLES: 1 DROPZONE_VERSION: v6.0.0-beta.2 -phpunit: - before_script: +.composer-base: + after_script: - mkdir $_WEB_ROOT/libraries - cd $_WEB_ROOT/libraries - curl -L https://github.com/dropzone/dropzone/releases/download/$DROPZONE_VERSION/dist.zip -o dropzone.zip --silent -- GitLab From da8c7cda5f2238a440bbab7b10f6d6aaf91935f9 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 20:51:02 +0000 Subject: [PATCH 16/54] Add imagesloaded library to the libraries directory in the gitlab ci test runner. --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9b9b6ab..e214cdc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,3 +60,4 @@ variables: - curl -L https://github.com/dropzone/dropzone/releases/download/$DROPZONE_VERSION/dist.zip -o dropzone.zip --silent - unzip dropzone.zip - mv dist dropzone + - curl -L https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.4/imagesloaded.pkgd.min.js -o imagesloaded/imagesloaded.pkgd.min.js -- GitLab From 4736958627c29cad5003a00fe69b2dd09eb153f1 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 21:00:59 +0000 Subject: [PATCH 17/54] Edit .gitlab-ci.yml to ensure imagesloaded directory is created in libraries directory. --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e214cdc..90e1eee 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,4 +60,5 @@ variables: - curl -L https://github.com/dropzone/dropzone/releases/download/$DROPZONE_VERSION/dist.zip -o dropzone.zip --silent - unzip dropzone.zip - mv dist dropzone + - mkdir imagesloaded - curl -L https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.4/imagesloaded.pkgd.min.js -o imagesloaded/imagesloaded.pkgd.min.js -- GitLab From 4a5a50b36562a313313089d7fa2213cb282fcb8b Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 21:13:48 +0000 Subject: [PATCH 18/54] Add masonry to gitlab ci runner as well. --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 90e1eee..1ba6db9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -62,3 +62,5 @@ variables: - mv dist dropzone - mkdir imagesloaded - curl -L https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.4/imagesloaded.pkgd.min.js -o imagesloaded/imagesloaded.pkgd.min.js + - mkdir masonry + - curl -L https://cdnjs.cloudflare.com/ajax/libs/masonry/4.2.2/masonry.pkgd.min.js -o masonry/masonry.pkgd.min.js -- GitLab From 1c6ed9e09d818c390b18f87ee2cdbbbf957f87e1 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Wed, 5 Feb 2025 21:22:45 +0000 Subject: [PATCH 19/54] Change source for masonry in gitlab-ci. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1ba6db9..aef0542 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,4 +63,4 @@ variables: - mkdir imagesloaded - curl -L https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.4/imagesloaded.pkgd.min.js -o imagesloaded/imagesloaded.pkgd.min.js - mkdir masonry - - curl -L https://cdnjs.cloudflare.com/ajax/libs/masonry/4.2.2/masonry.pkgd.min.js -o masonry/masonry.pkgd.min.js + - curl -L https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js -o masonry/masonry.pkgd.min.js -- GitLab From e566eb01d0946dee7b4f4835bfbfa363103a9b61 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Thu, 6 Feb 2025 08:48:13 +0000 Subject: [PATCH 20/54] Edit .gitlab-ci.yml to ensure masonry is unpacked into a dist directory inside of the masonry directory. --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aef0542..2407511 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -62,5 +62,5 @@ variables: - mv dist dropzone - mkdir imagesloaded - curl -L https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.4/imagesloaded.pkgd.min.js -o imagesloaded/imagesloaded.pkgd.min.js - - mkdir masonry - - curl -L https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js -o masonry/masonry.pkgd.min.js + - mkdir -p masonry/dist + - curl -L https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js -o masonry/dist/masonry.pkgd.min.js -- GitLab From f7f177655f6939e54091d75af095eb0dcd445fe0 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Thu, 6 Feb 2025 09:49:45 +0000 Subject: [PATCH 21/54] Replace button text 'Use selected' with 'Select entities' in the FileBrowserTest as this is the default text on the button. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 34fee0e..628e9f7 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -57,7 +57,7 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->getSession()->getPage()->clickLink('Files listing'); $this->clickViewEntity('file:' . $image->id()); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->getSession()->getPage()->pressButton('Use selected'); + $this->getSession()->getPage()->pressButton('Select entities'); // Switch back to the main page and assert that the file was selected. $this->getSession()->switchToIFrame(); -- GitLab From e93634cecdbb06b4e1a9a9a89fcda2f6574c1d7e Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Thu, 6 Feb 2025 10:06:30 +0000 Subject: [PATCH 22/54] Attempt pressButton in FileBrowserTest using the name value of the input instead. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 628e9f7..e56586f 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -57,7 +57,7 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->getSession()->getPage()->clickLink('Files listing'); $this->clickViewEntity('file:' . $image->id()); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->getSession()->getPage()->pressButton('Select entities'); + $this->getSession()->getPage()->pressButton('use_selected'); // Switch back to the main page and assert that the file was selected. $this->getSession()->switchToIFrame(); -- GitLab From ca0e16b1d8cfa6296edc55abf6c6e2b4c2875134 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Thu, 6 Feb 2025 10:38:26 +0000 Subject: [PATCH 23/54] Put 'Use selected' back as it was and replace EXISTS_REPLACE with FileExists:REPLACE in install file. --- file_browser.install | 6 +++++- tests/src/FunctionalJavascript/FileBrowserTest.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/file_browser.install b/file_browser.install index fb2aefd..27d26d3 100644 --- a/file_browser.install +++ b/file_browser.install @@ -1,5 +1,7 @@ <?php +use Drupal\Core\File\FileExists; + /** * @file * Defines library requirements and install routines for File Browser. @@ -18,7 +20,9 @@ function file_browser_install() { if (!\Drupal::isConfigSyncing()) { $data = file_get_contents(dirname(__FILE__) . '/file_browser_icon.png'); /** @var \Drupal\file\FileInterface $file */ - $file = \Drupal::service('file.repository')->writeData($data, 'public://file_browser_icon.png', FileSystemInterface::EXISTS_REPLACE); + $file = \Drupal::service('file.repository')->writeData($data, 'public://file_browser_icon.png', FileExists::REPLACE); + + if ($file) { // Set file uuid same as default config. $uuid = Yaml::decode(file_get_contents(dirname(__FILE__) . '/config/install/embed.button.file_browser.yml'))['icon_uuid']; diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index e56586f..34fee0e 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -57,7 +57,7 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->getSession()->getPage()->clickLink('Files listing'); $this->clickViewEntity('file:' . $image->id()); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->getSession()->getPage()->pressButton('use_selected'); + $this->getSession()->getPage()->pressButton('Use selected'); // Switch back to the main page and assert that the file was selected. $this->getSession()->switchToIFrame(); -- GitLab From 02c4494b9cba36cef654aa310c4e6f0142943b8a Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Thu, 6 Feb 2025 10:42:12 +0000 Subject: [PATCH 24/54] Make protected static $modules variable public static $modules. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 34fee0e..31be6ec 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -14,7 +14,7 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { /** * {@inheritdoc} */ - protected static $modules = [ + public static $modules = [ 'file_browser', 'dropzonejs', ]; -- GitLab From a35810cb490ef4824f01f3a9230617b5fd4ca4fb Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Thu, 6 Feb 2025 10:49:19 +0000 Subject: [PATCH 25/54] Revert replacement of FileSystemInterface::EXISTS_REPLACE due to new failures in tests. --- file_browser.install | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/file_browser.install b/file_browser.install index 27d26d3..fb2aefd 100644 --- a/file_browser.install +++ b/file_browser.install @@ -1,7 +1,5 @@ <?php -use Drupal\Core\File\FileExists; - /** * @file * Defines library requirements and install routines for File Browser. @@ -20,9 +18,7 @@ function file_browser_install() { if (!\Drupal::isConfigSyncing()) { $data = file_get_contents(dirname(__FILE__) . '/file_browser_icon.png'); /** @var \Drupal\file\FileInterface $file */ - $file = \Drupal::service('file.repository')->writeData($data, 'public://file_browser_icon.png', FileExists::REPLACE); - - + $file = \Drupal::service('file.repository')->writeData($data, 'public://file_browser_icon.png', FileSystemInterface::EXISTS_REPLACE); if ($file) { // Set file uuid same as default config. $uuid = Yaml::decode(file_get_contents(dirname(__FILE__) . '/config/install/embed.button.file_browser.yml'))['icon_uuid']; -- GitLab From a1ffea710af5f7e754a5dc266863bec6746c4648 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 09:28:12 +0000 Subject: [PATCH 26/54] Add some debug steps in attempt to debug pressButton error. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 31be6ec..b6efee8 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -57,6 +57,13 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->getSession()->getPage()->clickLink('Files listing'); $this->clickViewEntity('file:' . $image->id()); $this->assertSession()->assertWaitOnAjaxRequest(); + + // Check for entity browser and debug next step failing. + $this->assertSession()->pageTextContains('Files listing'); + $this->assertSession()->elementExists('xpath', '//input[@name="entity_browser_select[file:' . $image->id() . ']"]'); + $this->htmlOutput(); + // End check. + $this->getSession()->getPage()->pressButton('Use selected'); // Switch back to the main page and assert that the file was selected. -- GitLab From eaec9bd6c4fd1860a5904ccf9c4eb767f3727781 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 10:02:09 +0000 Subject: [PATCH 27/54] Click the apply button and show the html output. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index b6efee8..ff76550 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -58,9 +58,9 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->clickViewEntity('file:' . $image->id()); $this->assertSession()->assertWaitOnAjaxRequest(); - // Check for entity browser and debug next step failing. - $this->assertSession()->pageTextContains('Files listing'); - $this->assertSession()->elementExists('xpath', '//input[@name="entity_browser_select[file:' . $image->id() . ']"]'); + // Check output to determine why next step failing. + $this->htmlOutput(); + $this->getSession()->getPage()->pressButton('Apply'); $this->htmlOutput(); // End check. -- GitLab From 1d172db84385c7bf74d2a5782596828c55a311d7 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 10:14:57 +0000 Subject: [PATCH 28/54] Screenshot the dialog in the test. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index ff76550..d1ae668 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -60,8 +60,11 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { // Check output to determine why next step failing. $this->htmlOutput(); - $this->getSession()->getPage()->pressButton('Apply'); + $this->saveScreenshot('/tmp/modal_issue.png'); + sleep(5); + // $this->getSession()->getPage()->pressButton('Apply'); $this->htmlOutput(); + $this->saveScreenshot('/tmp/modal_issue.png'); // End check. $this->getSession()->getPage()->pressButton('Use selected'); -- GitLab From 8dac420f26e1a2d4c6ba10f3f9b0e1518b2010de Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 10:22:19 +0000 Subject: [PATCH 29/54] Attempt a different screenshot method. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index d1ae668..d74c7f8 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -60,11 +60,13 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { // Check output to determine why next step failing. $this->htmlOutput(); - $this->saveScreenshot('/tmp/modal_issue.png'); + $screenshot_filename_1 = '/tmp/modal_issue_1.png'; + file_put_contents($screenshot_filename_1, $this->getSession()->getScreenshot()); sleep(5); // $this->getSession()->getPage()->pressButton('Apply'); $this->htmlOutput(); - $this->saveScreenshot('/tmp/modal_issue.png'); + $screenshot_filename_2 = '/tmp/modal_issue_2.png'; + file_put_contents($screenshot_filename_2, $this->getSession()->getScreenshot()); // End check. $this->getSession()->getPage()->pressButton('Use selected'); -- GitLab From 54c1b0701540a362f1577285210c60a89976a278 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 10:33:17 +0000 Subject: [PATCH 30/54] Try again to take screenshots by including them as artifacts. --- .gitlab-ci.yml | 5 +++++ tests/src/FunctionalJavascript/FileBrowserTest.php | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2407511..7b17eaf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,3 +64,8 @@ variables: - curl -L https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.4/imagesloaded.pkgd.min.js -o imagesloaded/imagesloaded.pkgd.min.js - mkdir -p masonry/dist - curl -L https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js -o masonry/dist/masonry.pkgd.min.js + +artifacts: + paths: + - artifacts/screenshots/modal_issue_1.png + - artifacts/screenshots/modal_issue_2.png diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index d74c7f8..fcd1513 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -60,12 +60,16 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { // Check output to determine why next step failing. $this->htmlOutput(); - $screenshot_filename_1 = '/tmp/modal_issue_1.png'; + $screenshot_filename_1 = getenv('CI_PROJECT_DIR') . '/artifacts/screenshots/modal_issue_1.png'; + if (!file_exists(dirname($screenshot_filename_1))) { + mkdir(dirname($screenshot_filename_1), 0777, true); + } file_put_contents($screenshot_filename_1, $this->getSession()->getScreenshot()); sleep(5); // $this->getSession()->getPage()->pressButton('Apply'); $this->htmlOutput(); - $screenshot_filename_2 = '/tmp/modal_issue_2.png'; + $screenshot_filename_2 = getenv('CI_PROJECT_DIR') . '/artifacts/screenshots/modal_issue_2.png'; + file_put_contents($screenshot_filename_2, $this->getSession()->getScreenshot()); // End check. -- GitLab From 3e4cbcc5db197da0c75c1bb9065434cbabba1c5f Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 10:38:45 +0000 Subject: [PATCH 31/54] Fix gitlab-ci screenshot test. --- .gitlab-ci.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7b17eaf..b3fc005 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -65,7 +65,14 @@ variables: - mkdir -p masonry/dist - curl -L https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js -o masonry/dist/masonry.pkgd.min.js -artifacts: - paths: - - artifacts/screenshots/modal_issue_1.png - - artifacts/screenshots/modal_issue_2.png +test_and_capture_screenshots: + stage: test + script: + - echo "Running tests and capturing screenshots..." + - # Run your Drupal tests here (e.g., drush test-run or phpunit commands) + - # Screenshot saving logic here + artifacts: + paths: + - artifacts/screenshots/modal_issue_1.png + - artifacts/screenshots/modal_issue_2.png + expire_in: 1 hour -- GitLab From bec94e4868fca0ac43c08b1297cb3faffb4441c2 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 10:44:15 +0000 Subject: [PATCH 32/54] Try again to fix the test_and_capture_screenshots screenshots part of gitlab-ci. --- .gitlab-ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b3fc005..84798c4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -68,9 +68,7 @@ variables: test_and_capture_screenshots: stage: test script: - - echo "Running tests and capturing screenshots..." - - # Run your Drupal tests here (e.g., drush test-run or phpunit commands) - - # Screenshot saving logic here + - echo "Running existing tests..." artifacts: paths: - artifacts/screenshots/modal_issue_1.png -- GitLab From cb32e9d215be4f41a6d2f2124038a4024c63d337 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 11:18:09 +0000 Subject: [PATCH 33/54] Use Drupal createScreenshot function instead. --- .gitlab-ci.yml | 12 ------------ tests/src/FunctionalJavascript/FileBrowserTest.php | 10 ++-------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 84798c4..979cd40 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,8 +36,6 @@ include: ref: $_GITLAB_TEMPLATES_REF file: - '/includes/include.drupalci.main.yml' - # EXPERIMENTAL: For Drupal 7, remove the above line and uncomment the below. - # - '/includes/include.drupalci.main-d7.yml' - '/includes/include.drupalci.variables.yml' - '/includes/include.drupalci.workflows.yml' @@ -64,13 +62,3 @@ variables: - curl -L https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.4/imagesloaded.pkgd.min.js -o imagesloaded/imagesloaded.pkgd.min.js - mkdir -p masonry/dist - curl -L https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js -o masonry/dist/masonry.pkgd.min.js - -test_and_capture_screenshots: - stage: test - script: - - echo "Running existing tests..." - artifacts: - paths: - - artifacts/screenshots/modal_issue_1.png - - artifacts/screenshots/modal_issue_2.png - expire_in: 1 hour diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index fcd1513..9ab4288 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -60,17 +60,11 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { // Check output to determine why next step failing. $this->htmlOutput(); - $screenshot_filename_1 = getenv('CI_PROJECT_DIR') . '/artifacts/screenshots/modal_issue_1.png'; - if (!file_exists(dirname($screenshot_filename_1))) { - mkdir(dirname($screenshot_filename_1), 0777, true); - } - file_put_contents($screenshot_filename_1, $this->getSession()->getScreenshot()); + $this->createScreenshot('modal_issue_1.png'); sleep(5); // $this->getSession()->getPage()->pressButton('Apply'); $this->htmlOutput(); - $screenshot_filename_2 = getenv('CI_PROJECT_DIR') . '/artifacts/screenshots/modal_issue_2.png'; - - file_put_contents($screenshot_filename_2, $this->getSession()->getScreenshot()); + $this->createScreenshot('modal_issue_2.png'); // End check. $this->getSession()->getPage()->pressButton('Use selected'); -- GitLab From 558ae2fb4109138d7126cab6305c54d4295f2703 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 11:35:03 +0000 Subject: [PATCH 34/54] Ensure screenshots go to the files/simpletest directory. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 9ab4288..5a657c2 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -60,11 +60,11 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { // Check output to determine why next step failing. $this->htmlOutput(); - $this->createScreenshot('modal_issue_1.png'); + $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_1.png'); sleep(5); // $this->getSession()->getPage()->pressButton('Apply'); $this->htmlOutput(); - $this->createScreenshot('modal_issue_2.png'); + $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_2.png'); // End check. $this->getSession()->getPage()->pressButton('Use selected'); -- GitLab From a94ecd841efe7bd98db999e85b41a6151e25af6d Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 11:43:41 +0000 Subject: [PATCH 35/54] Try clicking the use selected button via find by css. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 5a657c2..e76b2fa 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -59,15 +59,16 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->assertSession()->assertWaitOnAjaxRequest(); // Check output to determine why next step failing. - $this->htmlOutput(); $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_1.png'); - sleep(5); - // $this->getSession()->getPage()->pressButton('Apply'); - $this->htmlOutput(); + // End check. + + $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); + + // Check output to determine why next step failing. $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_2.png'); // End check. - $this->getSession()->getPage()->pressButton('Use selected'); + // $this->getSession()->getPage()->pressButton('Use selected'); // Switch back to the main page and assert that the file was selected. $this->getSession()->switchToIFrame(); -- GitLab From e8c980a766e24997638f2140e3ceede0c5fd6a9d Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 12:01:10 +0000 Subject: [PATCH 36/54] Add some more intensive debugging to the test to find out if the 'Use selected' input even exists. --- .../FunctionalJavascript/FileBrowserTest.php | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index e76b2fa..3e4b943 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -11,6 +11,48 @@ use Drupal\Tests\entity_browser\FunctionalJavascript\EntityBrowserWebDriverTestB */ class FileBrowserTest extends EntityBrowserWebDriverTestBase { + /** + * Get all input and button elements on the page. + */ + protected function getClickableElements() { + // Get the entire DOM of the page. + $page = $this->getSession()->getPage(); + + // Find all input and button elements. + $inputs = $page->findAll('xpath', '//input'); + $buttons = $page->findAll('xpath', '//button'); + + // Combine inputs and buttons into one array. + $elements = array_merge($inputs, $buttons); + + // Prepare an array with element details for debugging. + $element_details = []; + foreach ($elements as $element) { + // Get the element type and value/label for debugging. + $element_details[] = [ + 'type' => $element->getTagName(), + 'value' => $element->getValue() ? $element->getValue() : $element->getText(), + 'id' => $element->getAttribute('id'), + 'name' => $element->getAttribute('name'), + 'classes' => $element->getAttribute('class'), + ]; + } + + // Return the list of clickable elements. + return $element_details; + } + + /** + * Debug method to print out the list of clickable elements. + */ + protected function debugClickableElements() { + $elements = $this->getClickableElements(); + foreach ($elements as $element) { + // Print each element's details for debugging. + $this->assertTrue(TRUE, print_r($element, TRUE)); + } + } + /** * {@inheritdoc} */ @@ -62,12 +104,15 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_1.png'); // End check. - $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); + $this->getSession()->getPage()->find('css', '.entity-browser-use-selected'); // Check output to determine why next step failing. $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_2.png'); + $this->debugClickableElements(); // End check. + $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); + // $this->getSession()->getPage()->pressButton('Use selected'); // Switch back to the main page and assert that the file was selected. -- GitLab From 4eee8a69d11ae7cfe55c1c19291822e8c3f59ba5 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 12:14:56 +0000 Subject: [PATCH 37/54] Run test again with different logging method for all buttons and inputs. --- .../src/FunctionalJavascript/FileBrowserTest.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 3e4b943..1b5c46f 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -4,6 +4,9 @@ namespace Drupal\Tests\file_browser\FunctionalJavascript; use Drupal\Tests\entity_browser\FunctionalJavascript\EntityBrowserWebDriverTestBase; +use Drupal\DrupalExtension\WebAssert; +use Drupal\Core\Logger\LoggerChannelInterface; + /** * Tests the file_browser module. * @@ -43,13 +46,15 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { } /** - * Debug method to print out the list of clickable elements. + * Debug method to log out the list of clickable elements. */ - protected function debugClickableElements() { + protected function logClickableElements() { $elements = $this->getClickableElements(); + + // Use Drupal's logger to log element details + $logger = \Drupal::logger('file_browser_test'); foreach ($elements as $element) { - // Print each element's details for debugging. - $this->assertTrue(TRUE, print_r($element, TRUE)); + $logger->info('Clickable Element: ' . print_r($element, TRUE)); } } @@ -111,7 +116,7 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->debugClickableElements(); // End check. - $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); + // $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); // $this->getSession()->getPage()->pressButton('Use selected'); -- GitLab From f1fc5cd983357b663bde5634aad483cca158b1f0 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 12:18:54 +0000 Subject: [PATCH 38/54] Change call to logClickableElements. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 1b5c46f..e3e634b 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -113,7 +113,7 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { // Check output to determine why next step failing. $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_2.png'); - $this->debugClickableElements(); + $this->logClickableElements(); // End check. // $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); -- GitLab From a9622a3cb32729823f2ce38dd083c579429331a8 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 12:32:37 +0000 Subject: [PATCH 39/54] Attempt switch to iframe before clicking button. --- .../FunctionalJavascript/FileBrowserTest.php | 56 +------------------ 1 file changed, 2 insertions(+), 54 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index e3e634b..3ad9ce5 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -4,9 +4,6 @@ namespace Drupal\Tests\file_browser\FunctionalJavascript; use Drupal\Tests\entity_browser\FunctionalJavascript\EntityBrowserWebDriverTestBase; -use Drupal\DrupalExtension\WebAssert; -use Drupal\Core\Logger\LoggerChannelInterface; - /** * Tests the file_browser module. * @@ -14,50 +11,6 @@ use Drupal\Core\Logger\LoggerChannelInterface; */ class FileBrowserTest extends EntityBrowserWebDriverTestBase { - /** - * Get all input and button elements on the page. - */ - protected function getClickableElements() { - // Get the entire DOM of the page. - $page = $this->getSession()->getPage(); - - // Find all input and button elements. - $inputs = $page->findAll('xpath', '//input'); - $buttons = $page->findAll('xpath', '//button'); - - // Combine inputs and buttons into one array. - $elements = array_merge($inputs, $buttons); - - // Prepare an array with element details for debugging. - $element_details = []; - foreach ($elements as $element) { - // Get the element type and value/label for debugging. - $element_details[] = [ - 'type' => $element->getTagName(), - 'value' => $element->getValue() ? $element->getValue() : $element->getText(), - 'id' => $element->getAttribute('id'), - 'name' => $element->getAttribute('name'), - 'classes' => $element->getAttribute('class'), - ]; - } - - // Return the list of clickable elements. - return $element_details; - } - - /** - * Debug method to log out the list of clickable elements. - */ - protected function logClickableElements() { - $elements = $this->getClickableElements(); - - // Use Drupal's logger to log element details - $logger = \Drupal::logger('file_browser_test'); - foreach ($elements as $element) { - $logger->info('Clickable Element: ' . print_r($element, TRUE)); - } - } - /** * {@inheritdoc} */ @@ -105,15 +58,10 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->clickViewEntity('file:' . $image->id()); $this->assertSession()->assertWaitOnAjaxRequest(); - // Check output to determine why next step failing. + // Check output to determine why next step failing. $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_1.png'); - // End check. - - $this->getSession()->getPage()->find('css', '.entity-browser-use-selected'); - - // Check output to determine why next step failing. + $this->getSession()->switchToIFrame(); $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_2.png'); - $this->logClickableElements(); // End check. // $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); -- GitLab From 5ef6edb1cdda8b36bf0bf3cadbf9b5a1d20ad1cf Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 12:37:04 +0000 Subject: [PATCH 40/54] Attempt to use the save button instead of Use selected button. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 3ad9ce5..ae695af 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -60,13 +60,13 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { // Check output to determine why next step failing. $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_1.png'); - $this->getSession()->switchToIFrame(); - $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_2.png'); // End check. - // $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); + $this->getSession()->getPage()->pressButton('Save'); - // $this->getSession()->getPage()->pressButton('Use selected'); + // Check output to determine why next step failing. + $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_2.png'); + // End check. // Switch back to the main page and assert that the file was selected. $this->getSession()->switchToIFrame(); -- GitLab From 49677c4357a8dd402d8429d27834d7135921a014 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 12:54:33 +0000 Subject: [PATCH 41/54] Wait for .entity-browser-use-selected element to be visible before proceeding with pressButton. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index ae695af..832c1db 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -57,16 +57,13 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->getSession()->getPage()->clickLink('Files listing'); $this->clickViewEntity('file:' . $image->id()); $this->assertSession()->assertWaitOnAjaxRequest(); + $this->assertSession()->waitForElementVisible('css', '.entity-browser-use-selected'); + $this->getSession()->getPage()->pressButton('Use selected'); // Check output to determine why next step failing. $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_1.png'); // End check. - $this->getSession()->getPage()->pressButton('Save'); - - // Check output to determine why next step failing. - $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_2.png'); - // End check. // Switch back to the main page and assert that the file was selected. $this->getSession()->switchToIFrame(); -- GitLab From 5fa356a2ecb1b9fb2fedd71f5f28b338581a286d Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 13:08:12 +0000 Subject: [PATCH 42/54] Try clicking button by css selector again after waiting for it. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 832c1db..a85752a 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -58,12 +58,12 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->clickViewEntity('file:' . $image->id()); $this->assertSession()->assertWaitOnAjaxRequest(); $this->assertSession()->waitForElementVisible('css', '.entity-browser-use-selected'); - $this->getSession()->getPage()->pressButton('Use selected'); // Check output to determine why next step failing. $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_1.png'); // End check. + $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); // Switch back to the main page and assert that the file was selected. $this->getSession()->switchToIFrame(); -- GitLab From 35a139eb4e5391189a8cae93dfb32ba7a41e5cda Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 13:59:48 +0000 Subject: [PATCH 43/54] Put things back to where they were in anticipation of further commits from others. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index a85752a..31be6ec 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -57,13 +57,7 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { $this->getSession()->getPage()->clickLink('Files listing'); $this->clickViewEntity('file:' . $image->id()); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->assertSession()->waitForElementVisible('css', '.entity-browser-use-selected'); - - // Check output to determine why next step failing. - $this->createScreenshot(\Drupal::root() . '/sites/default/files/simpletest/modal_issue_1.png'); - // End check. - - $this->getSession()->getPage()->find('css', '.entity-browser-use-selected')->click(); + $this->getSession()->getPage()->pressButton('Use selected'); // Switch back to the main page and assert that the file was selected. $this->getSession()->switchToIFrame(); -- GitLab From 98ca9cb61a4e4aec283a99a080e63b70249b4cd7 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 14:11:27 +0000 Subject: [PATCH 44/54] Attempt adding addition modules to public static modules. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 31be6ec..54b4a63 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -15,8 +15,11 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { * {@inheritdoc} */ public static $modules = [ - 'file_browser', 'dropzonejs', + 'embed', + 'entity_browser', + 'entity_embed', + 'file_browser', ]; /** -- GitLab From c973363ec6317d3e86972a8dc4127fe5a0fabaa3 Mon Sep 17 00:00:00 2001 From: Darren Fisher <60905-darren.fisher@users.noreply.drupalcode.org> Date: Tue, 11 Feb 2025 14:25:07 +0000 Subject: [PATCH 45/54] Revert previous commit. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 54b4a63..8491e9a 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -16,9 +16,6 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { */ public static $modules = [ 'dropzonejs', - 'embed', - 'entity_browser', - 'entity_embed', 'file_browser', ]; -- GitLab From ba8df9147f0149e85356cdea9abcd3c7bd120571 Mon Sep 17 00:00:00 2001 From: Daniel Johnson <dajohnson321@gmail.com> Date: Wed, 12 Feb 2025 14:05:31 +0000 Subject: [PATCH 46/54] stylelint: Refactor CSS for consistency and improved readability. Reorganized CSS properties for better logical grouping and readability. Updated syntax to use modern conventions (e.g., `::before` over `:before`). Enhanced maintainability by aligning styles and fixing property ordering inconsistencies. --- css/file_browser.dropzone.css | 12 +-- css/file_browser.preview.css | 10 +-- css/file_browser.view.css | 133 +++++++++++++++++++--------------- 3 files changed, 84 insertions(+), 71 deletions(-) diff --git a/css/file_browser.dropzone.css b/css/file_browser.dropzone.css index a89227b..032761e 100644 --- a/css/file_browser.dropzone.css +++ b/css/file_browser.dropzone.css @@ -3,24 +3,24 @@ */ .dropzone .dz-preview .dz-success-mark { - background: transparent url("../images/checkmark.svg") no-repeat center center; - background-size: 100% 100%; - width: 54px; - height: 54px; top: -20px; right: 0; bottom: 0; left: 0; + width: 54px; + height: 54px; margin: auto; + background: transparent url("../images/checkmark.svg") no-repeat center center; + background-size: 100% 100%; } .dropzone .dz-preview .dz-error-mark { - width: 54px; - height: 54px; top: -20px; right: 0; bottom: 0; left: 0; + width: 54px; + height: 54px; margin: auto; } diff --git a/css/file_browser.preview.css b/css/file_browser.preview.css index 348a501..c30d7b5 100644 --- a/css/file_browser.preview.css +++ b/css/file_browser.preview.css @@ -4,19 +4,19 @@ .file-browser-preview-dialog { position: absolute; - height: 100% !important; - width: 100% !important; - max-width: none !important; top: 0 !important; left: 0 !important; + width: 100% !important; + max-width: none !important; + height: 100% !important; } .file-browser-preview-dialog #drupal-modal { width: 100% !important; height: 100% !important; max-height: none !important; - padding-top: 0; margin-top: -20px; + padding-top: 0; background: #2d2d2d; } @@ -25,8 +25,8 @@ } .file-browser-preview-dialog.ui-dialog .ui-dialog-titlebar { - background-color: #2d2d2d; border-radius: 0; + background-color: #2d2d2d; } .file-browser-preview-dialog.ui-dialog .ui-dialog-title { diff --git a/css/file_browser.view.css b/css/file_browser.view.css index 46243bf..21e9b88 100644 --- a/css/file_browser.view.css +++ b/css/file_browser.view.css @@ -2,7 +2,6 @@ * @file file_browser.view.css */ - /* Generic styles */ .pager { @@ -65,51 +64,63 @@ .grid-item { display: block; - opacity: 0; - text-align: center; - background-color: #dedede; overflow: hidden; + text-align: center; + opacity: 0; border-radius: 2px; - box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 1px 5px 0 rgba(0,0,0,0.12), 0 3px 1px -2px rgba(0,0,0,0.2); + background-color: #dedede; + box-shadow: + 0 2px 2px 0 rgba(0, 0, 0, 0.14), + 0 1px 5px 0 rgba(0, 0, 0, 0.12), + 0 3px 1px -2px rgba(0, 0, 0, 0.2); } .grid-item.item-style { + -moz-transition: + opacity 0.25s ease-in-out, + box-shadow 0.25s ease-in-out; + -webkit-transition: + opacity 0.25s ease-in-out, + box-shadow 0.25s ease-in-out; + transition: + opacity 0.25s ease-in-out, + box-shadow 0.25s ease-in-out; opacity: 1; - transition: opacity .25s ease-in-out, box-shadow .25s ease-in-out; - -moz-transition: opacity .25s ease-in-out, box-shadow .25s ease-in-out;; - -webkit-transition: opacity .25s ease-in-out, box-shadow .25s ease-in-out;; } .grid-item:hover { cursor: pointer; } -.grid-item.checked:before { - content: " "; - color: transparent; +.grid-item.checked::before { position: absolute; - left: 0; - right: 0; top: 0; + right: 0; + left: 0; + overflow: hidden; width: calc(100% - 4px); height: calc(100% - 4px); + content: " "; + color: transparent; border: 2px solid #37802f; - overflow: hidden; } .grid-item:hover { - box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 1px 7px 3px rgba(0,0,0,0.12), 0 3px 1px -2px rgba(0,0,0,0.2); + box-shadow: + 0 2px 2px 0 rgba(0, 0, 0, 0.14), + 0 1px 7px 3px rgba(0, 0, 0, 0.12), + 0 3px 1px -2px rgba(0, 0, 0, 0.2); } .view-content { - margin: 0 auto; width: 100% !important; + margin: 0 auto; } .grid-item img { - vertical-align: bottom; width: 100%; height: auto; + vertical-align: bottom; } .grid-item img::selection { @@ -120,32 +131,32 @@ display: none; } -.grid-item:after { - content: " "; - width: 100%; - height: 100%; +.grid-item::after { + position: absolute; top: 0; left: 0; - position: absolute; + width: 100%; + height: 100%; + content: " "; } .grid-item-info { position: absolute; z-index: 1; - width: calc(100% - 20px); bottom: 0; - background-color: #2d2d2d; - color: #dedede; + width: calc(100% - 20px); padding: 10px; + color: #dedede; + background-color: #2d2d2d; } .grid-item-info-left { float: left; + overflow: hidden; + max-width: 50%; text-align: left; white-space: nowrap; - overflow: hidden; text-overflow: ellipsis; - max-width: 50%; } .grid-item-info-right { @@ -156,17 +167,16 @@ position: relative; } - /* Remove border above tabs. */ -.file-browser-form .is-collapse-enabled .tabs:before, -.file-browser-form .is-horizontal .tabs:before { +.file-browser-form .is-collapse-enabled .tabs::before, +.file-browser-form .is-horizontal .tabs::before { background-color: transparent; } input[type="submit"][name="filter"] { - margin-left: 10px; margin-top: 30px; + margin-left: 10px; } .layout-container { @@ -175,16 +185,16 @@ input[type="submit"][name="filter"] { .file-browser-actions { position: fixed; + z-index: 2; bottom: 0; display: flex; flex-direction: row-reverse; - justify-content: flex-end; align-items: center; - z-index: 2; - padding: 10px; + justify-content: flex-end; width: 100%; - background: white; + padding: 10px; border-top: 1px solid #b8b8b8; + background: white; } input.entity-browser-show-selection { @@ -193,8 +203,8 @@ input.entity-browser-show-selection { .entities-list .item-container { position: relative; - border: 1px dashed gray; margin: 5px; + border: 1px dashed gray; } .entities-list .item-container > img, @@ -208,11 +218,11 @@ input.entity-browser-show-selection { .entities-list .item-container:hover img, .entities-list .item-container:hover input { - transition: .2s; + transition: 0.2s; } .entities-list .item-container:hover img { - opacity: .6; + opacity: 0.6; } .entities-list .item-container:hover input { @@ -220,21 +230,21 @@ input.entity-browser-show-selection { } .entities-list .item-container input { - background: url(../images/remove.svg); - opacity: 0; - background-size: cover; - color: transparent; - text-shadow: none; position: absolute; + top: 2px; + right: 2px; width: 20px; height: 20px; + margin: 0; padding: 0; - top: 2px; - right: 2px; + opacity: 0; + color: transparent; + border: 1px solid #585858; border-radius: 10px; - margin: 0; + background: url(../images/remove.svg); background-color: #dedede; - border: 1px solid #585858; + background-size: cover; + text-shadow: none; } .entities-list .item-container input:hover { @@ -245,12 +255,12 @@ input.entity-browser-show-selection { display: flex; align-items: center; height: 25px; - padding: 0 0 0 25px; margin-bottom: 5px; + padding: 0 0 0 25px; background: url(../images/checkmark.svg); - background-position: 0px; - background-size: 20px; background-repeat: no-repeat; + background-position: 0; + background-size: 20px; } .grid-item:hover .file-browser-preview-button { @@ -259,21 +269,24 @@ input.entity-browser-show-selection { .file-browser-preview-button { position: absolute; + z-index: 2; top: 5px; right: 5px; + width: 40px; + height: 40px; + transition: opacity 0.2s; + opacity: 0; + color: transparent; + border-radius: 50%; background: url(../images/preview.svg); - z-index: 2; - background-size: 30px; - background-position: 5px; background-color: #2d2d2d; - border-radius: 50%; - height: 40px; - width: 40px; background-repeat: no-repeat; - color: transparent; - box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 1px 5px 0 rgba(0,0,0,0.12), 0 3px 1px -2px rgba(0,0,0,0.2); - opacity: 0; - transition: opacity .2s; + background-position: 5px; + background-size: 30px; + box-shadow: + 0 2px 2px 0 rgba(0, 0, 0, 0.14), + 0 1px 5px 0 rgba(0, 0, 0, 0.12), + 0 3px 1px -2px rgba(0, 0, 0, 0.2); } .file-browser-preview-button:hover, -- GitLab From 29e196d9ae6ad47882cf3cd38f84b220d682e3c8 Mon Sep 17 00:00:00 2001 From: Daniel Johnson <dajohnson321@gmail.com> Date: Wed, 12 Feb 2025 14:06:15 +0000 Subject: [PATCH 47/54] eslint: Add Prettier config and refactor JS to modern syntax Introduced a `.prettierrc.json` for consistent code formatting and a `.prettierignore` file. Refactored JavaScript files to use modern ES6+ syntax (e.g., arrow functions, `const`, `let`, template literals) for improved readability and maintainability. Additionally, cleaned up YAML formatting by removing unnecessary spaces. --- .prettierignore | 1 + .prettierrc.json | 1 + config/install/embed.button.file_browser.yml | 2 +- .../entity_browser.browser.browse_files.yml | 2 +- ...ity_browser.browser.browse_files_modal.yml | 2 +- .../image.style.file_entity_browser_small.yml | 2 +- ...ge.style.file_entity_browser_thumbnail.yml | 2 +- .../views.view.file_entity_browser.yml | 48 ++++---- js/file_browser.preview.js | 31 ++--- js/file_browser.view.js | 110 ++++++++++-------- .../block_content.type.file_browser.yml | 2 +- ...lay.block_content.file_browser.default.yml | 6 +- ...form_display.node.file_browser.default.yml | 26 ++--- ...lay.block_content.file_browser.default.yml | 4 +- ...view_display.node.file_browser.default.yml | 10 +- ...e_browser.field_file_browser_reference.yml | 2 +- .../field.field.node.file_browser.body.yml | 2 +- ....file_browser.field_file_browser_image.yml | 4 +- ...k_content.field_file_browser_reference.yml | 2 +- ....storage.node.field_file_browser_image.yml | 2 +- .../config/install/node.type.file_browser.yml | 2 +- 21 files changed, 142 insertions(+), 121 deletions(-) create mode 100644 .prettierignore create mode 120000 .prettierrc.json diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1cda54b --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +*.yml diff --git a/.prettierrc.json b/.prettierrc.json new file mode 120000 index 0000000..464f711 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1 @@ +web/core/.prettierrc.json \ No newline at end of file diff --git a/config/install/embed.button.file_browser.yml b/config/install/embed.button.file_browser.yml index 6f85828..3245dad 100644 --- a/config/install/embed.button.file_browser.yml +++ b/config/install/embed.button.file_browser.yml @@ -10,7 +10,7 @@ id: file_browser type_id: entity type_settings: entity_type: file - bundles: { } + bundles: {} display_plugins: - 'file:file_default' - 'image:image' diff --git a/config/install/entity_browser.browser.browse_files.yml b/config/install/entity_browser.browser.browse_files.yml index ca0e44b..b493f12 100644 --- a/config/install/entity_browser.browser.browse_files.yml +++ b/config/install/entity_browser.browser.browse_files.yml @@ -23,7 +23,7 @@ selection_display_configuration: image_style: file_entity_browser_small selection_hidden: false widget_selector: tabs -widget_selector_configuration: { } +widget_selector_configuration: {} widgets: a4ad947c-9669-497c-9988-24351955a02f: settings: diff --git a/config/install/entity_browser.browser.browse_files_modal.yml b/config/install/entity_browser.browser.browse_files_modal.yml index b5cef3c..82a3cb2 100644 --- a/config/install/entity_browser.browser.browse_files_modal.yml +++ b/config/install/entity_browser.browser.browse_files_modal.yml @@ -23,7 +23,7 @@ selection_display_configuration: image_style: file_entity_browser_small selection_hidden: false widget_selector: tabs -widget_selector_configuration: { } +widget_selector_configuration: {} widgets: a4ad947c-9669-497c-9988-24351955a02f: settings: diff --git a/config/install/image.style.file_entity_browser_small.yml b/config/install/image.style.file_entity_browser_small.yml index 29b0862..47b12dc 100644 --- a/config/install/image.style.file_entity_browser_small.yml +++ b/config/install/image.style.file_entity_browser_small.yml @@ -1,6 +1,6 @@ langcode: en status: true -dependencies: { } +dependencies: {} name: file_entity_browser_small label: 'File Entity Browser small thumbnail' effects: diff --git a/config/install/image.style.file_entity_browser_thumbnail.yml b/config/install/image.style.file_entity_browser_thumbnail.yml index 400eb34..4f474ae 100644 --- a/config/install/image.style.file_entity_browser_thumbnail.yml +++ b/config/install/image.style.file_entity_browser_thumbnail.yml @@ -1,6 +1,6 @@ langcode: en status: true -dependencies: { } +dependencies: {} name: file_entity_browser_thumbnail label: 'File Entity Browser thumbnail' effects: diff --git a/config/install/views.view.file_entity_browser.yml b/config/install/views.view.file_entity_browser.yml index 48b16ff..d47a97e 100644 --- a/config/install/views.view.file_entity_browser.yml +++ b/config/install/views.view.file_entity_browser.yml @@ -30,7 +30,7 @@ display: perm: 'access content' cache: type: none - options: { } + options: {} query: type: views_query options: @@ -38,7 +38,7 @@ display: distinct: false replica: false query_comment: '' - query_tags: { } + query_tags: {} exposed_form: type: basic options: @@ -73,13 +73,13 @@ display: style: type: default options: - grouping: { } + grouping: {} row_class: grid-item default_row_class: true row: type: fields options: - inline: { } + inline: {} separator: '' hide_empty: false default_field_elements: true @@ -237,7 +237,7 @@ display: settings: link_to_entity: false group_column: value - group_columns: { } + group_columns: {} group_rows: true delta_limit: 0 delta_offset: 0 @@ -299,9 +299,9 @@ display: hide_alter_empty: true click_sort_column: value type: file_size - settings: { } + settings: {} group_column: value - group_columns: { } + group_columns: {} group_rows: true delta_limit: 0 delta_offset: 0 @@ -398,8 +398,8 @@ display: multiple: false remember: false default_group: All - default_group_multiple: { } - group_items: { } + default_group_multiple: {} + group_items: {} entity_type: file entity_field: filename plugin_id: string @@ -438,8 +438,8 @@ display: multiple: false remember: false default_group: All - default_group_multiple: { } - group_items: { } + default_group_multiple: {} + group_items: {} entity_type: file entity_field: filemime plugin_id: string @@ -478,8 +478,8 @@ display: multiple: false remember: false default_group: All - default_group_multiple: { } - group_items: { } + default_group_multiple: {} + group_items: {} entity_type: file entity_field: status plugin_id: file_status @@ -516,8 +516,8 @@ display: multiple: false remember: false default_group: All - default_group_multiple: { } - group_items: { } + default_group_multiple: {} + group_items: {} entity_type: file entity_field: filename plugin_id: string @@ -565,12 +565,12 @@ display: entity_type: file entity_field: filename plugin_id: standard - header: { } - footer: { } - empty: { } - relationships: { } - arguments: { } - display_extenders: { } + header: {} + footer: {} + empty: {} + relationships: {} + arguments: {} + display_extenders: {} css_class: '' use_ajax: true cache_metadata: @@ -584,14 +584,14 @@ display: - user.permissions cacheable: false max-age: -1 - tags: { } + tags: {} entity_browser_1: display_plugin: entity_browser id: entity_browser_1 display_title: 'Entity browser' position: 2 display_options: - display_extenders: { } + display_extenders: {} cache_metadata: contexts: - 'languages:language_content' @@ -603,4 +603,4 @@ display: - user.permissions cacheable: false max-age: -1 - tags: { } + tags: {} diff --git a/js/file_browser.preview.js b/js/file_browser.preview.js index 935ac94..69542e4 100644 --- a/js/file_browser.preview.js +++ b/js/file_browser.preview.js @@ -3,25 +3,26 @@ * file_browser.preview.js */ -(function ($, Drupal) { - - "use strict"; - +(($, Drupal) => { /** * Contains logic for the view widget. */ Drupal.behaviors.fileBrowserPreview = { - attach: function (context, settings) { - var wrapper = once('file-browser-preview', '#file-browser-preview-wrapper'); + attach(context, settings) { + const wrapper = once( + 'file-browser-preview', + '#file-browser-preview-wrapper', + ); if (wrapper.length) { - $(wrapper).find('select').on('change', function () { - Drupal.ajax({ - url: settings.file_browser.preview_path + '/' + $(this).val(), - wrapper: 'file-browser-preview-wrapper' - }).execute(); - }); + $(wrapper) + .find('select') + .on('change', () => { + Drupal.ajax({ + url: `${settings.file_browser.preview_path} / ${this.val()}`, + wrapper: 'file-browser-preview-wrapper', + }).execute(); + }); } - } + }, }; - -}(jQuery, Drupal)); +})(jQuery, Drupal); diff --git a/js/file_browser.view.js b/js/file_browser.view.js index 6007693..4d444c8 100644 --- a/js/file_browser.view.js +++ b/js/file_browser.view.js @@ -3,42 +3,49 @@ * file_browser.view.js */ -(function ($, Drupal) { - - "use strict"; - +(($, Drupal) => { /** * Renders the file counter based on our internally tracked count. */ function renderFileCounter() { - $('.file-browser-file-counter').each(function () { + $('.file-browser-file-counter').each(() => { $(this).remove(); }); - var counter = []; - $('.entities-list [data-entity-id]').each(function () { + const counter = []; + $('.entities-list [data-entity-id]').each(() => { if (counter[this.dataset.entityId]) { - ++counter[this.dataset.entityId]; - } - else { + counter[this.dataset.entityId] += 1; + } else { counter[this.dataset.entityId] = 1; } }); - for (var id in counter) { - var count = counter[id]; + Object.keys(counter).forEach((id) => { + const count = counter[id]; if (count > 0) { - var text = Drupal.formatPlural(count, 'Selected one time', 'Selected @count times'); - var $counter = $('<div class="file-browser-file-counter"></div>').text(text); - $('[name="entity_browser_select[file:' + id + ']"]').closest('.grid-item').find('.grid-item-info').prepend($counter); + const text = Drupal.formatPlural( + count, + 'Selected one time', + 'Selected @count times', + ); + const $counter = $('<div class="file-browser-file-counter"></div>')[0]; + $counter.textContent = text; + $(`[name = "entity_browser_select[file:${id}]"]`) + .closest('.grid-item') + .find('.grid-item-info') + .prepend($counter); } - } + }); } /** * Adjusts the padding on the body to account for the fixed actions bar. */ function adjustBodyPadding() { - setTimeout(function () { - $('body').css('padding-bottom', $('.file-browser-actions').outerHeight() + 'px'); + setTimeout(() => { + const bodyElement = document.querySelector('body'); + const actionsElement = document.querySelector('.file-browser-actions'); + const actionsHeight = actionsElement ? actionsElement.offsetHeight : 0; + bodyElement.style.paddingBottom = `${actionsHeight}px`; }, 2000); } @@ -46,18 +53,22 @@ * Initializes Masonry for the view widget. */ Drupal.behaviors.fileBrowserMasonry = { - attach: function (context) { - var $item = $('.grid-item', context); - var view = once('file-browser-init', $item.parent()); + attach(context) { + const $item = $('.grid-item', context); + const view = once('file-browser-init', $item.parent()); if (view.length) { - var $view = $(view); - $view.prepend('<div class="grid-sizer"></div><div class="gutter-sizer"></div>'); + const $view = $(view); + $view.prepend( + '<div class="grid-sizer"></div><div class="gutter-sizer"></div>', + ); // Indicate that images are loading. - $view.append('<div class="ajax-progress ajax-progress-fullscreen"> </div>'); - $view.imagesLoaded(function () { + $view.append( + '<div class="ajax-progress ajax-progress-fullscreen"> </div>', + ); + $view.imagesLoaded(() => { // Save the scroll position. - var scroll = document.body.scrollTop; + const scroll = document.body.scrollTop; // Remove old Masonry object if it exists. This allows modules like // Views Infinite Scroll to function with File Browser. if ($view.data('masonry')) { @@ -68,7 +79,7 @@ gutter: '.gutter-sizer', itemSelector: '.grid-item', percentPosition: true, - isFitWidth: true + isFitWidth: true, }); // Jump to the old scroll position. document.body.scrollTop = scroll; @@ -77,7 +88,7 @@ $view.find('.ajax-progress').remove(); }); } - } + }, }; /** @@ -87,20 +98,21 @@ * auto-select and multi-step. */ Drupal.behaviors.fileBrowserClickProxy = { - attach: function (context, settings) { + attach(context, settings) { if (!settings.entity_browser_widget.auto_select) { - $(once('bind-click-event', '.grid-item', context)).click(function () { - var input = $(this).find('.views-field-entity-browser-select input'); + $(once('bind-click-event', '.grid-item', context)).click(() => { + const input = $(this).find( + '.views-field-entity-browser-select input', + ); input.prop('checked', !input.prop('checked')); if (input.prop('checked')) { $(this).addClass('checked'); - } - else { + } else { $(this).removeClass('checked'); } }); } - } + }, }; /** @@ -108,23 +120,29 @@ * and displays that information on each grid item. */ Drupal.behaviors.fileBrowserEntityCount = { - attach: function (context) { + attach(context) { adjustBodyPadding(); renderFileCounter(); // Indicate when files have been selected. - var entities = once('file-browser-add-count', '.entities-list', context); + const entities = once( + 'file-browser-add-count', + '.entities-list', + context, + ); if (entities.length) { - $(entities).bind('add-entities', function (event, entity_ids) { - adjustBodyPadding(); - renderFileCounter(); + entities.forEach((entity) => { + entity.addEventListener('add-entities', () => { + adjustBodyPadding(); + renderFileCounter(); + }); }); - - $(entities).bind('remove-entities', function (event, entity_ids) { - adjustBodyPadding(); - renderFileCounter(); + entities.forEach((entity) => { + entity.addEventListener('remove-entities', () => { + adjustBodyPadding(); + renderFileCounter(); + }); }); } - } + }, }; - -}(jQuery, Drupal)); +})(jQuery, Drupal); diff --git a/modules/file_browser_example/config/install/block_content.type.file_browser.yml b/modules/file_browser_example/config/install/block_content.type.file_browser.yml index 8035452..5e931a5 100644 --- a/modules/file_browser_example/config/install/block_content.type.file_browser.yml +++ b/modules/file_browser_example/config/install/block_content.type.file_browser.yml @@ -6,4 +6,4 @@ dependencies: id: file_browser label: 'File Browser' revision: 1 -description: 'An example Custom Block type that uses File Browser''s Entity Browser and EntityReferenceImageFormatter.' +description: "An example Custom Block type that uses File Browser's Entity Browser and EntityReferenceImageFormatter." diff --git a/modules/file_browser_example/config/install/core.entity_form_display.block_content.file_browser.default.yml b/modules/file_browser_example/config/install/core.entity_form_display.block_content.file_browser.default.yml index 5f33863..5e7df24 100644 --- a/modules/file_browser_example/config/install/core.entity_form_display.block_content.file_browser.default.yml +++ b/modules/file_browser_example/config/install/core.entity_form_display.block_content.file_browser.default.yml @@ -19,7 +19,7 @@ content: field_widget_display: thumbnail field_widget_display_settings: image_style: medium - third_party_settings: { } + third_party_settings: {} type: entity_browser_entity_reference region: content info: @@ -28,6 +28,6 @@ content: settings: size: 60 placeholder: '' - third_party_settings: { } + third_party_settings: {} region: content -hidden: { } +hidden: {} diff --git a/modules/file_browser_example/config/install/core.entity_form_display.node.file_browser.default.yml b/modules/file_browser_example/config/install/core.entity_form_display.node.file_browser.default.yml index 4b429a4..db4cd89 100644 --- a/modules/file_browser_example/config/install/core.entity_form_display.node.file_browser.default.yml +++ b/modules/file_browser_example/config/install/core.entity_form_display.node.file_browser.default.yml @@ -23,14 +23,14 @@ content: rows: 9 summary_rows: 3 placeholder: '' - third_party_settings: { } + third_party_settings: {} type: text_textarea_with_summary region: content created: type: datetime_timestamp weight: 4 - settings: { } - third_party_settings: { } + settings: {} + third_party_settings: {} region: content field_file_browser_image: weight: 2 @@ -40,34 +40,34 @@ content: field_widget_remove: true view_mode: default open: false - third_party_settings: { } + third_party_settings: {} type: entity_browser_file region: content langcode: type: language_select weight: 5 - settings: { } - third_party_settings: { } + settings: {} + third_party_settings: {} region: content path: type: path weight: 8 - settings: { } - third_party_settings: { } + settings: {} + third_party_settings: {} region: content promote: type: boolean_checkbox settings: display_label: true weight: 6 - third_party_settings: { } + third_party_settings: {} region: content sticky: type: boolean_checkbox settings: display_label: true weight: 7 - third_party_settings: { } + third_party_settings: {} region: content title: type: string_textfield @@ -75,7 +75,7 @@ content: settings: size: 60 placeholder: '' - third_party_settings: { } + third_party_settings: {} region: content uid: type: entity_reference_autocomplete @@ -84,6 +84,6 @@ content: match_operator: CONTAINS size: 60 placeholder: '' - third_party_settings: { } + third_party_settings: {} region: content -hidden: { } +hidden: {} diff --git a/modules/file_browser_example/config/install/core.entity_view_display.block_content.file_browser.default.yml b/modules/file_browser_example/config/install/core.entity_view_display.block_content.file_browser.default.yml index dfacc27..35563bb 100644 --- a/modules/file_browser_example/config/install/core.entity_view_display.block_content.file_browser.default.yml +++ b/modules/file_browser_example/config/install/core.entity_view_display.block_content.file_browser.default.yml @@ -18,7 +18,7 @@ content: settings: view_mode: default link: false - third_party_settings: { } + third_party_settings: {} type: entity_reference_entity_view region: content -hidden: { } +hidden: {} diff --git a/modules/file_browser_example/config/install/core.entity_view_display.node.file_browser.default.yml b/modules/file_browser_example/config/install/core.entity_view_display.node.file_browser.default.yml index 078ee9d..60c13be 100644 --- a/modules/file_browser_example/config/install/core.entity_view_display.node.file_browser.default.yml +++ b/modules/file_browser_example/config/install/core.entity_view_display.node.file_browser.default.yml @@ -20,8 +20,8 @@ content: body: weight: 3 label: above - settings: { } - third_party_settings: { } + settings: {} + third_party_settings: {} type: text_default region: content field_file_browser_image: @@ -30,13 +30,13 @@ content: settings: image_style: '' image_link: '' - third_party_settings: { } + third_party_settings: {} type: image region: content links: weight: 2 - settings: { } - third_party_settings: { } + settings: {} + third_party_settings: {} region: content hidden: langcode: true diff --git a/modules/file_browser_example/config/install/field.field.block_content.file_browser.field_file_browser_reference.yml b/modules/file_browser_example/config/install/field.field.block_content.file_browser.field_file_browser_reference.yml index e978217..a2973c0 100644 --- a/modules/file_browser_example/config/install/field.field.block_content.file_browser.field_file_browser_reference.yml +++ b/modules/file_browser_example/config/install/field.field.block_content.file_browser.field_file_browser_reference.yml @@ -14,7 +14,7 @@ label: 'File Browser Reference' description: '' required: false translatable: false -default_value: { } +default_value: {} default_value_callback: '' settings: handler: 'default:file' diff --git a/modules/file_browser_example/config/install/field.field.node.file_browser.body.yml b/modules/file_browser_example/config/install/field.field.node.file_browser.body.yml index 441686c..3127b55 100644 --- a/modules/file_browser_example/config/install/field.field.node.file_browser.body.yml +++ b/modules/file_browser_example/config/install/field.field.node.file_browser.body.yml @@ -15,7 +15,7 @@ label: Body description: '' required: false translatable: true -default_value: { } +default_value: {} default_value_callback: '' settings: display_summary: false diff --git a/modules/file_browser_example/config/install/field.field.node.file_browser.field_file_browser_image.yml b/modules/file_browser_example/config/install/field.field.node.file_browser.field_file_browser_image.yml index 748a696..3370a8a 100644 --- a/modules/file_browser_example/config/install/field.field.node.file_browser.field_file_browser_image.yml +++ b/modules/file_browser_example/config/install/field.field.node.file_browser.field_file_browser_image.yml @@ -15,7 +15,7 @@ label: 'File Browser Image' description: '' required: false translatable: false -default_value: { } +default_value: {} default_value_callback: '' settings: file_directory: '[date:custom:Y]-[date:custom:m]' @@ -34,5 +34,5 @@ settings: width: null height: null handler: 'default:file' - handler_settings: { } + handler_settings: {} field_type: image diff --git a/modules/file_browser_example/config/install/field.storage.block_content.field_file_browser_reference.yml b/modules/file_browser_example/config/install/field.storage.block_content.field_file_browser_reference.yml index a11c544..b527aab 100644 --- a/modules/file_browser_example/config/install/field.storage.block_content.field_file_browser_reference.yml +++ b/modules/file_browser_example/config/install/field.storage.block_content.field_file_browser_reference.yml @@ -15,6 +15,6 @@ module: core locked: false cardinality: -1 translatable: true -indexes: { } +indexes: {} persist_with_no_fields: false custom_storage: false diff --git a/modules/file_browser_example/config/install/field.storage.node.field_file_browser_image.yml b/modules/file_browser_example/config/install/field.storage.node.field_file_browser_image.yml index 3b97356..e2ad073 100644 --- a/modules/file_browser_example/config/install/field.storage.node.field_file_browser_image.yml +++ b/modules/file_browser_example/config/install/field.storage.node.field_file_browser_image.yml @@ -25,6 +25,6 @@ module: image locked: false cardinality: -1 translatable: true -indexes: { } +indexes: {} persist_with_no_fields: false custom_storage: false diff --git a/modules/file_browser_example/config/install/node.type.file_browser.yml b/modules/file_browser_example/config/install/node.type.file_browser.yml index 5e30e66..079c816 100644 --- a/modules/file_browser_example/config/install/node.type.file_browser.yml +++ b/modules/file_browser_example/config/install/node.type.file_browser.yml @@ -11,7 +11,7 @@ third_party_settings: parent: 'main:' name: 'File Browser' type: file_browser -description: 'An example Custom Content type that uses File Browser''s Entity Browser and EntityReferenceImageFormatter.' +description: "An example Custom Content type that uses File Browser's Entity Browser and EntityReferenceImageFormatter." help: '' new_revision: false preview_mode: 1 -- GitLab From 8baa7283006364998ba670c63a9d499bbaa8ab39 Mon Sep 17 00:00:00 2001 From: Daniel Johnson <dajohnson321@gmail.com> Date: Wed, 12 Feb 2025 14:08:08 +0000 Subject: [PATCH 48/54] cspell: Fix typo in README and add custom words to spell checker Corrected a misspelling in the README ("Adminstration" to "Administration"). Added a custom dictionary file to support project-specific terms for the spell checker. --- .cspell-project-words.txt | 7 +++++++ README.txt | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .cspell-project-words.txt diff --git a/.cspell-project-words.txt b/.cspell-project-words.txt new file mode 100644 index 0000000..2e3d675 --- /dev/null +++ b/.cspell-project-words.txt @@ -0,0 +1,7 @@ +acquia +dropzonejs +grih +imagesloaded +mortenson +nldz +pkgd diff --git a/README.txt b/README.txt index df06d9d..786dc67 100644 --- a/README.txt +++ b/README.txt @@ -79,7 +79,7 @@ CONFIGURATION c. Download https://github.com/enyo/dropzone/archive/v4.3.0.zip and extract the download to /libraries/dropzone (or any libraries directory if you're using the Libraries module). - 2. Navigate to Adminstration > Extend and enabled the File Entity Browser + 2. Navigate to Administration > Extend and enabled the File Entity Browser and its dependencies. Please note: -- GitLab From d2fed90cc632c73eaa31f09262527e9371957f45 Mon Sep 17 00:00:00 2001 From: Daniel Johnson <dajohnson321@gmail.com> Date: Wed, 12 Feb 2025 14:30:04 +0000 Subject: [PATCH 49/54] phpstan: Refactor image handling and improve dependency injection. Replaced direct service calls with dependency-injected services in `ImageEmbedBlock` to align with best practices. Updated visibility of static properties in tests and fixed deprecated constant usage in `file_browser.install`. Improves code maintainability and readability. --- file_browser.install | 4 +- src/Plugin/Block/ImageEmbedBlock.php | 48 +++++++++++++++++-- .../FunctionalJavascript/FileBrowserTest.php | 2 +- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/file_browser.install b/file_browser.install index fb2aefd..7fd2086 100644 --- a/file_browser.install +++ b/file_browser.install @@ -6,9 +6,9 @@ */ use Drupal\Component\Serialization\Yaml; +use Drupal\Core\File\FileExists; use Drupal\image\Entity\ImageStyle; use Drupal\views\Entity\View; -use Drupal\Core\File\FileSystemInterface; /** * Implements hook_install(). @@ -18,7 +18,7 @@ function file_browser_install() { if (!\Drupal::isConfigSyncing()) { $data = file_get_contents(dirname(__FILE__) . '/file_browser_icon.png'); /** @var \Drupal\file\FileInterface $file */ - $file = \Drupal::service('file.repository')->writeData($data, 'public://file_browser_icon.png', FileSystemInterface::EXISTS_REPLACE); + $file = \Drupal::service('file.repository')->writeData($data, 'public://file_browser_icon.png', FileExists::Replace); if ($file) { // Set file uuid same as default config. $uuid = Yaml::decode(file_get_contents(dirname(__FILE__) . '/config/install/embed.button.file_browser.yml'))['icon_uuid']; diff --git a/src/Plugin/Block/ImageEmbedBlock.php b/src/Plugin/Block/ImageEmbedBlock.php index 4776b01..5e5c1cf 100644 --- a/src/Plugin/Block/ImageEmbedBlock.php +++ b/src/Plugin/Block/ImageEmbedBlock.php @@ -5,7 +5,10 @@ namespace Drupal\file_browser\Plugin\Block; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Block\BlockBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Image\ImageFactory; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\file\Entity\File; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides the "Image Embed" block. @@ -16,7 +19,46 @@ use Drupal\file\Entity\File; * category = @Translation("Embed") * ) */ -class ImageEmbedBlock extends BlockBase { +class ImageEmbedBlock extends BlockBase implements ContainerFactoryPluginInterface { + + /** + * The image factory service. + * + * @var \Drupal\Core\Image\ImageFactory + */ + protected ImageFactory $imageFactory; + + /** + * Constructs a new ImageEmbedBlock instance. + * + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The container to pull out services used in the plugin. + * @param mixed[] $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin ID for the plugin instance. + * @param mixed[] $plugin_definition + * The plugin implementation definition. + * + * @return static + * Returns an instance of this plugin. + */ + public static function create( + ContainerInterface $container, + array $configuration, + $plugin_id, + $plugin_definition, + ): static { + $instance = new static( + $configuration, + $plugin_id, + $plugin_definition, + ); + + $instance->imageFactory = $container->get('image.factory'); + + return $instance; + } /** * {@inheritdoc} @@ -120,7 +162,7 @@ class ImageEmbedBlock extends BlockBase { foreach ($files as $info) { $file = File::load($info['fid']); $uri = $file->getFileUri(); - $image = \Drupal::service('image.factory')->get($uri); + $image = $this->imageFactory->get($uri); if ($image->isValid()) { $width = $image->getWidth(); $height = $image->getHeight(); @@ -216,7 +258,7 @@ class ImageEmbedBlock extends BlockBase { $file = File::load($info['fid']); if ($file && $file->access('view')) { $uri = $file->getFileUri(); - $image = \Drupal::service('image.factory')->get($uri); + $image = $this->imageFactory->get($uri); if ($image->isValid()) { $width = $image->getWidth(); $height = $image->getHeight(); diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 8491e9a..f2152df 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -14,7 +14,7 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'dropzonejs', 'file_browser', ]; -- GitLab From b5410dc1c9b3d2557fec09e59c6a8f5d794bab05 Mon Sep 17 00:00:00 2001 From: Daniel Johnson <dajohnson321@gmail.com> Date: Thu, 13 Feb 2025 11:14:08 +0000 Subject: [PATCH 50/54] Set default theme to "claro" in tests. Updated the default theme to "claro" in FileBrowserTest and InstallTest classes to align with the current theme standard. This ensures consistency across functional and functional JavaScript tests. --- tests/src/Functional/InstallTest.php | 2 +- tests/src/FunctionalJavascript/FileBrowserTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/src/Functional/InstallTest.php b/tests/src/Functional/InstallTest.php index 1771f30..a4f8539 100644 --- a/tests/src/Functional/InstallTest.php +++ b/tests/src/Functional/InstallTest.php @@ -22,7 +22,7 @@ class InstallTest extends BrowserTestBase { /** * {@inheritdoc} */ - protected $defaultTheme = 'stable9'; + protected $defaultTheme = 'claro'; /** * {@inheritdoc} diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index f2152df..846132c 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -19,6 +19,11 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { 'file_browser', ]; + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'claro'; + /** * {@inheritdoc} */ -- GitLab From 9cedacc4755ab711c83d30d10900643900ddb4b8 Mon Sep 17 00:00:00 2001 From: Daniel Johnson <dajohnson321@gmail.com> Date: Thu, 13 Feb 2025 11:14:27 +0000 Subject: [PATCH 51/54] Remove unused 'field_widget_display' setting from test config The 'field_widget_display' setting was redundant and has been removed from the test configuration. This cleanup helps streamline the test and ensures unnecessary settings are not included. --- tests/src/FunctionalJavascript/FileBrowserTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/src/FunctionalJavascript/FileBrowserTest.php b/tests/src/FunctionalJavascript/FileBrowserTest.php index 846132c..52086f3 100644 --- a/tests/src/FunctionalJavascript/FileBrowserTest.php +++ b/tests/src/FunctionalJavascript/FileBrowserTest.php @@ -47,7 +47,6 @@ class FileBrowserTest extends EntityBrowserWebDriverTestBase { 'type' => 'entity_browser_entity_reference', 'settings' => [ 'entity_browser' => 'browse_files', - 'field_widget_display' => 'label', 'open' => TRUE, ], ])->save(); -- GitLab From 94c531a0f9fd97fe3dfe98ac2eac13937f35f9e2 Mon Sep 17 00:00:00 2001 From: Daniel Johnson <dajohnson321@gmail.com> Date: Thu, 13 Feb 2025 11:14:59 +0000 Subject: [PATCH 52/54] Refactor file counter rendering with modern DOM methods Replace jQuery usage with modern DOM API for improved clarity and performance. Streamlined element removal and manipulation logic, ensuring compatibility and better maintainability. Added error handling for potential missing grid-item elements. --- js/file_browser.view.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/js/file_browser.view.js b/js/file_browser.view.js index 4d444c8..7e24adf 100644 --- a/js/file_browser.view.js +++ b/js/file_browser.view.js @@ -8,17 +8,20 @@ * Renders the file counter based on our internally tracked count. */ function renderFileCounter() { - $('.file-browser-file-counter').each(() => { - $(this).remove(); - }); - const counter = []; - $('.entities-list [data-entity-id]').each(() => { - if (counter[this.dataset.entityId]) { - counter[this.dataset.entityId] += 1; + document.querySelectorAll('.file-browser-file-counter').forEach(el => el.remove()); + + const counter = {}; + + document.querySelectorAll('.entities-list [data-entity-id]').forEach(element => { + console.log(element); + const entityId = element.dataset.entityId; + if (counter[entityId]) { + counter[entityId] += 1; } else { - counter[this.dataset.entityId] = 1; + counter[entityId] = 1; } }); + Object.keys(counter).forEach((id) => { const count = counter[id]; if (count > 0) { @@ -27,12 +30,17 @@ 'Selected one time', 'Selected @count times', ); - const $counter = $('<div class="file-browser-file-counter"></div>')[0]; - $counter.textContent = text; - $(`[name = "entity_browser_select[file:${id}]"]`) + const counterElement = document.createElement('div'); + counterElement.className = 'file-browser-file-counter'; + counterElement.textContent = text; + + const gridItemInfo = document.querySelector(`[name = "entity_browser_select[file:${id}]"]`) .closest('.grid-item') - .find('.grid-item-info') - .prepend($counter); + .querySelector('.grid-item-info'); + + if (gridItemInfo) { + gridItemInfo.insertAdjacentElement('afterbegin', counterElement); + } } }); } -- GitLab From 1b7625d705a052fa398867f2ed922a5a679d5440 Mon Sep 17 00:00:00 2001 From: Daniel Johnson <dajohnson321@gmail.com> Date: Thu, 13 Feb 2025 11:15:17 +0000 Subject: [PATCH 53/54] Add composer.libraries.json with required external libraries This commit introduces a composer.libraries.json file to manage external JavaScript libraries as Drupal libraries. It includes Dropzone.js, ImagesLoaded, and Masonry with their respective versions and distribution sources. These libraries will be managed independently from the core composer.json file. --- composer.libraries.json | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 composer.libraries.json diff --git a/composer.libraries.json b/composer.libraries.json new file mode 100644 index 0000000..5a7e22d --- /dev/null +++ b/composer.libraries.json @@ -0,0 +1,45 @@ +{ + "repositories": [ + { + "type": "package", + "package": { + "name": "dropzone/dropzone", + "version": "5.7.3", + "type": "drupal-library", + "dist": { + "url": "https://github.com/dropzone/dropzone-packagist/archive/refs/tags/v5.7.3.zip", + "type": "zip" + } + } + }, + { + "type": "package", + "package": { + "name": "desandro/imagesloaded", + "version": "4.1.4", + "type": "drupal-library", + "dist": { + "url": "https://github.com/desandro/imagesloaded/archive/refs/tags/v4.1.4.zip", + "type": "zip" + } + } + }, + { + "type": "package", + "package": { + "name": "desandro/masonry", + "version": "4.1.4", + "type": "drupal-library", + "dist": { + "url": "https://github.com/desandro/masonry/archive/refs/tags/v4.2.2.zip", + "type": "zip" + } + } + } + ], + "require": { + "dropzone/dropzone": "^5", + "desandro/imagesloaded": "^4", + "desandro/masonry": "^4" + } +} -- GitLab From e7d67c95467b44d8b17d298169a60986f69b8a7d Mon Sep 17 00:00:00 2001 From: Daniel Johnson <dajohnson321@gmail.com> Date: Thu, 13 Feb 2025 11:21:15 +0000 Subject: [PATCH 54/54] eslint: Refactor file counter rendering for improved readability Reformatted the code in `renderFileCounter` to improve readability by updating indentation and line breaks. Removed an unnecessary `console.log` statement. These changes make the function easier to understand and maintain without altering its behavior. --- js/file_browser.view.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/js/file_browser.view.js b/js/file_browser.view.js index 7e24adf..25ff830 100644 --- a/js/file_browser.view.js +++ b/js/file_browser.view.js @@ -8,19 +8,22 @@ * Renders the file counter based on our internally tracked count. */ function renderFileCounter() { - document.querySelectorAll('.file-browser-file-counter').forEach(el => el.remove()); + document + .querySelectorAll('.file-browser-file-counter') + .forEach((el) => el.remove()); const counter = {}; - document.querySelectorAll('.entities-list [data-entity-id]').forEach(element => { - console.log(element); - const entityId = element.dataset.entityId; - if (counter[entityId]) { - counter[entityId] += 1; - } else { - counter[entityId] = 1; - } - }); + document + .querySelectorAll('.entities-list [data-entity-id]') + .forEach((element) => { + const entityId = element.dataset.entityId; + if (counter[entityId]) { + counter[entityId] += 1; + } else { + counter[entityId] = 1; + } + }); Object.keys(counter).forEach((id) => { const count = counter[id]; @@ -34,7 +37,8 @@ counterElement.className = 'file-browser-file-counter'; counterElement.textContent = text; - const gridItemInfo = document.querySelector(`[name = "entity_browser_select[file:${id}]"]`) + const gridItemInfo = document + .querySelector(`[name = "entity_browser_select[file:${id}]"]`) .closest('.grid-item') .querySelector('.grid-item-info'); -- GitLab