From 07c4638b8a21b266c268525996092803d6643949 Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Sat, 15 Feb 2025 17:40:44 +0100
Subject: [PATCH 1/2] Issue #3506530 by grimreaper: Media Library Edit support

---
 .../media-library/media-library-buttons.css   |  9 +++-
 .../PreprocessMediaLibraryItem.php            | 54 ++++++++++++++++++-
 ui_suite_bootstrap.info.yml                   |  4 ++
 3 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/assets/css/media-library/media-library-buttons.css b/assets/css/media-library/media-library-buttons.css
index 8dcaed60..492f72f2 100644
--- a/assets/css/media-library/media-library-buttons.css
+++ b/assets/css/media-library/media-library-buttons.css
@@ -1,11 +1,18 @@
 /* Remove button of selected medias. */
-button[name$="media-library-remove-button"] {
+button.media-library-remove-button,
+/* Edit button. */
+a.media-library-edit__link {
   position: absolute;
   z-index: 1;
   right: var(--bs-card-spacer-x);
   margin: 0.25rem;
 }
 
+/* Edit button. */
+a.media-library-edit__link {
+  top: 30px;
+}
+
 /* Remove button when creating a media. */
 .media-added-remove-button {
   position: absolute;
diff --git a/src/HookHandler/PreprocessMediaLibraryItem.php b/src/HookHandler/PreprocessMediaLibraryItem.php
index ea05edda..d395c513 100644
--- a/src/HookHandler/PreprocessMediaLibraryItem.php
+++ b/src/HookHandler/PreprocessMediaLibraryItem.php
@@ -13,12 +13,33 @@ use Drupal\ui_suite_bootstrap\Utility\Element;
 class PreprocessMediaLibraryItem {
 
   /**
-   * Add icons in media library view.
+   * Ensure the remove button is the first element.
+   */
+  public const REMOVE_BUTTON_WEIGHT = -10;
+
+  /**
+   * Ensure the edit link is after the remove button.
+   */
+  public const EDIT_LINK_WEIGHT = -5;
+
+  /**
+   * Add icons in media library item.
    *
    * @param array $variables
    *   The preprocessed variables.
    */
   public function preprocess(array &$variables): void {
+    $this->preprocessRemoveButton($variables);
+    $this->preprocessEditLink($variables);
+  }
+
+  /**
+   * Add icon on remove button.
+   *
+   * @param array $variables
+   *   The preprocessed variables.
+   */
+  protected function preprocessRemoveButton(array &$variables): void {
     if (!isset($variables['content']['remove_button'])) {
       return;
     }
@@ -29,7 +50,36 @@ class PreprocessMediaLibraryItem {
       'alt' => $element->getProperty('value'),
     ]));
     $element->setProperty('icon_position', 'icon_only');
-    $element->addClass('btn-sm');
+    $element->addClass([
+      'btn-sm',
+      'media-library-remove-button',
+    ]);
+    $element->setProperty('weight', static::REMOVE_BUTTON_WEIGHT);
+  }
+
+  /**
+   * Add icon and button style on edit link.
+   *
+   * @param array $variables
+   *   The preprocessed variables.
+   */
+  protected function preprocessEditLink(array &$variables): void {
+    if (!isset($variables['content']['media_edit'])) {
+      return;
+    }
+
+    $element = Element::create($variables['content']['media_edit']);
+    $element->setIcon(Bootstrap::icon('pencil-fill', 'bootstrap', [
+      'size' => '16px',
+      'alt' => $element->getProperty('value'),
+    ]));
+    $element->setProperty('icon_position', 'icon_only');
+    $element->addClass([
+      'btn',
+      'btn-sm',
+      'btn-success',
+    ]);
+    $element->setProperty('weight', static::EDIT_LINK_WEIGHT);
   }
 
 }
diff --git a/ui_suite_bootstrap.info.yml b/ui_suite_bootstrap.info.yml
index 13b276a5..76c770ea 100644
--- a/ui_suite_bootstrap.info.yml
+++ b/ui_suite_bootstrap.info.yml
@@ -80,6 +80,10 @@ libraries-override:
   commerce_checkout/form: false
   commerce_checkout/login_pane: false
   layout_builder_browser/browser: false
+  media_library_edit/admin:
+    css:
+      component:
+        css/media_library_edit.admin.css: false
   paragraphs/drupal.paragraphs.unpublished: false
   section_library/section_library:
     css:
-- 
GitLab


From eaee783216bb8161c3261ff0a5fd548d8794af57 Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Sat, 15 Feb 2025 17:47:08 +0100
Subject: [PATCH 2/2] Issue #3506530 by grimreaper: Media Library Edit support

---
 src/HookHandler/PreprocessMediaLibraryItem.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/HookHandler/PreprocessMediaLibraryItem.php b/src/HookHandler/PreprocessMediaLibraryItem.php
index d395c513..54779ffd 100644
--- a/src/HookHandler/PreprocessMediaLibraryItem.php
+++ b/src/HookHandler/PreprocessMediaLibraryItem.php
@@ -71,7 +71,6 @@ class PreprocessMediaLibraryItem {
     $element = Element::create($variables['content']['media_edit']);
     $element->setIcon(Bootstrap::icon('pencil-fill', 'bootstrap', [
       'size' => '16px',
-      'alt' => $element->getProperty('value'),
     ]));
     $element->setProperty('icon_position', 'icon_only');
     $element->addClass([
-- 
GitLab