<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mwiki.costasano.club/index.php?action=history&amp;feed=atom&amp;title=ICT%3ADrupal_Media_Library_simple_clone</id>
	<title>ICT:Drupal Media Library simple clone - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mwiki.costasano.club/index.php?action=history&amp;feed=atom&amp;title=ICT%3ADrupal_Media_Library_simple_clone"/>
	<link rel="alternate" type="text/html" href="https://mwiki.costasano.club/index.php?title=ICT:Drupal_Media_Library_simple_clone&amp;action=history"/>
	<updated>2026-04-17T19:44:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://mwiki.costasano.club/index.php?title=ICT:Drupal_Media_Library_simple_clone&amp;diff=1503&amp;oldid=prev</id>
		<title>Mngr: Created page with &quot;= Media Library Minimal Clone – Problem Description and Architectural Outline =  == 1. The Problem == Drupal’s built‑in Media Library widget uses a multi‑step modal workflow:  * Step 1: Upload file → validate → create file entity → create media entity. * Step 2: Display a selection grid inside a modal/iframe. * Step 3: User selects the media item → modal returns the media ID to the field.  This workflow is powerful but problematic for simple use cases:  *...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mwiki.costasano.club/index.php?title=ICT:Drupal_Media_Library_simple_clone&amp;diff=1503&amp;oldid=prev"/>
		<updated>2026-03-10T22:52:20Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Media Library Minimal Clone – Problem Description and Architectural Outline =  == 1. The Problem == Drupal’s built‑in Media Library widget uses a multi‑step modal workflow:  * Step 1: Upload file → validate → create file entity → create media entity. * Step 2: Display a selection grid inside a modal/iframe. * Step 3: User selects the media item → modal returns the media ID to the field.  This workflow is powerful but problematic for simple use cases:  *...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Media Library Minimal Clone – Problem Description and Architectural Outline =&lt;br /&gt;
&lt;br /&gt;
== 1. The Problem ==&lt;br /&gt;
Drupal’s built‑in Media Library widget uses a multi‑step modal workflow:&lt;br /&gt;
&lt;br /&gt;
* Step 1: Upload file → validate → create file entity → create media entity.&lt;br /&gt;
* Step 2: Display a selection grid inside a modal/iframe.&lt;br /&gt;
* Step 3: User selects the media item → modal returns the media ID to the field.&lt;br /&gt;
&lt;br /&gt;
This workflow is powerful but problematic for simple use cases:&lt;br /&gt;
&lt;br /&gt;
* The modal is implemented as a Drupal dialog with no reliable events.&lt;br /&gt;
* The modal often loads inside an iframe, blocking parent‑window JavaScript.&lt;br /&gt;
* AJAX events do not consistently fire.&lt;br /&gt;
* The “Save” button inside the modal cannot be intercepted cleanly.&lt;br /&gt;
* Gin theme dialog overrides do not apply to Media Library.&lt;br /&gt;
* The modal cannot be closed programmatically in a deterministic way.&lt;br /&gt;
* The selection UI is unnecessary when the user only uploads a single file.&lt;br /&gt;
&lt;br /&gt;
As a result, it is extremely difficult to implement:&lt;br /&gt;
* auto‑closing the modal after upload,&lt;br /&gt;
* returning the media ID directly,&lt;br /&gt;
* or integrating the workflow into custom forms.&lt;br /&gt;
&lt;br /&gt;
The core issue is that the Media Library modal is a “black box” with no hooks.&lt;br /&gt;
&lt;br /&gt;
== 2. Architectural Approach: A Minimal Media Library Clone ==&lt;br /&gt;
Instead of modifying or forking the entire Media Library module, we create a &lt;br /&gt;
**minimal custom field widget** that reuses the good parts of Media Library &lt;br /&gt;
(upload + validation + media entity creation) and replaces the problematic UI.&lt;br /&gt;
&lt;br /&gt;
This is not a fork of the module.  &lt;br /&gt;
It is a small subsystem that uses Drupal’s existing APIs.&lt;br /&gt;
&lt;br /&gt;
=== 2.1 What We Keep (from Media Library) ===&lt;br /&gt;
* File upload handling&lt;br /&gt;
* File validation (MIME, size, dimensions)&lt;br /&gt;
* File entity creation&lt;br /&gt;
* Media entity creation&lt;br /&gt;
* Metadata extraction&lt;br /&gt;
* Access checks&lt;br /&gt;
* Storage logic&lt;br /&gt;
&lt;br /&gt;
These parts are stable, well‑engineered, and should not be rewritten.&lt;br /&gt;
&lt;br /&gt;
=== 2.2 What We Remove ===&lt;br /&gt;
* The modal dialog&lt;br /&gt;
* The iframe wrapper&lt;br /&gt;
* The multi‑step wizard&lt;br /&gt;
* The selection grid&lt;br /&gt;
* The “Add selected” button&lt;br /&gt;
* All AJAX‑based selection logic&lt;br /&gt;
&lt;br /&gt;
These parts cause the unpredictability and cannot be reliably extended.&lt;br /&gt;
&lt;br /&gt;
=== 2.3 What We Replace ===&lt;br /&gt;
We replace the Media Library widget with:&lt;br /&gt;
&lt;br /&gt;
* A custom field widget that renders a simple “Upload image” button.&lt;br /&gt;
* A custom modal (or inline form) that contains only the upload form.&lt;br /&gt;
* A modified save handler that:&lt;br /&gt;
** creates the media entity (using core logic),&lt;br /&gt;
** immediately returns the media ID to the parent form,&lt;br /&gt;
** closes the modal.&lt;br /&gt;
&lt;br /&gt;
This eliminates the entire selection UI and second step.&lt;br /&gt;
&lt;br /&gt;
=== 2.4 Resulting Workflow (Simplified) ===&lt;br /&gt;
# User clicks “Upload image”.&lt;br /&gt;
# A minimal modal opens with the upload form.&lt;br /&gt;
# User uploads a file.&lt;br /&gt;
# Drupal validates and creates the media entity (core logic).&lt;br /&gt;
# The save handler returns the media ID directly to the field.&lt;br /&gt;
# The modal closes immediately.&lt;br /&gt;
&lt;br /&gt;
No iframe.  &lt;br /&gt;
No selection grid.  &lt;br /&gt;
No multi‑step wizard.  &lt;br /&gt;
No AJAX events.  &lt;br /&gt;
No Gin dialog interference.&lt;br /&gt;
&lt;br /&gt;
=== 2.5 Advantages ===&lt;br /&gt;
* Deterministic behaviour.&lt;br /&gt;
* No dependency on Drupal’s dialog system.&lt;br /&gt;
* No dependency on Gin theme.&lt;br /&gt;
* No fragile JavaScript hooks.&lt;br /&gt;
* Fully successor‑friendly.&lt;br /&gt;
* Uses Drupal’s backend logic without modification.&lt;br /&gt;
* Minimal code surface.&lt;br /&gt;
* Easy to document and maintain.&lt;br /&gt;
&lt;br /&gt;
=== 2.6 Components to Implement ===&lt;br /&gt;
* A custom field widget plugin.&lt;br /&gt;
* A custom route/controller for the upload form.&lt;br /&gt;
* A custom modal (or inline form wrapper).&lt;br /&gt;
* A save handler override that:&lt;br /&gt;
** calls Drupal’s media creation logic,&lt;br /&gt;
** returns the media ID,&lt;br /&gt;
** closes the modal.&lt;br /&gt;
&lt;br /&gt;
No need to rewrite Media Library.  &lt;br /&gt;
No need to fork the module.  &lt;br /&gt;
No need to override core services.&lt;br /&gt;
&lt;br /&gt;
== 3. Summary ==&lt;br /&gt;
The Media Library modal is not extensible in a reliable way.  &lt;br /&gt;
The simplest and most maintainable solution is to create a minimal clone of the &lt;br /&gt;
Media Library widget that:&lt;br /&gt;
&lt;br /&gt;
* reuses the upload + validation + media creation logic,&lt;br /&gt;
* removes the selection UI,&lt;br /&gt;
* returns the media ID immediately after save.&lt;br /&gt;
&lt;br /&gt;
This produces a clean, deterministic subsystem that avoids all modal issues and &lt;br /&gt;
is easy to maintain for future administrators.&lt;/div&gt;</summary>
		<author><name>Mngr</name></author>
	</entry>
</feed>