<?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%3AD_JSON_based_Multi-Link_Field</id>
	<title>ICT:D JSON based Multi-Link Field - 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%3AD_JSON_based_Multi-Link_Field"/>
	<link rel="alternate" type="text/html" href="https://mwiki.costasano.club/index.php?title=ICT:D_JSON_based_Multi-Link_Field&amp;action=history"/>
	<updated>2026-04-17T16:09:11Z</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:D_JSON_based_Multi-Link_Field&amp;diff=1597&amp;oldid=prev</id>
		<title>Mngr: Created page with &quot;= JSON-Based Multi-Link Field Architecture = This document summarizes a proposed architecture for storing and managing 0…N website links per record in Drupal, using a single text field containing JSON and a modal-based custom widget.  The goal is: * A clean edit form (one line only) * A modal to manage multiple links * Deterministic behavior (no handler surprises) * Easy rendering in Views and Twig * Reusable across all content types  == 1. Overview == Instead of using...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mwiki.costasano.club/index.php?title=ICT:D_JSON_based_Multi-Link_Field&amp;diff=1597&amp;oldid=prev"/>
		<updated>2026-04-02T15:02:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= JSON-Based Multi-Link Field Architecture = This document summarizes a proposed architecture for storing and managing 0…N website links per record in Drupal, using a single text field containing JSON and a modal-based custom widget.  The goal is: * A clean edit form (one line only) * A modal to manage multiple links * Deterministic behavior (no handler surprises) * Easy rendering in Views and Twig * Reusable across all content types  == 1. Overview == Instead of using...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= JSON-Based Multi-Link Field Architecture =&lt;br /&gt;
This document summarizes a proposed architecture for storing and managing&lt;br /&gt;
0…N website links per record in Drupal, using a single text field containing&lt;br /&gt;
JSON and a modal-based custom widget.&lt;br /&gt;
&lt;br /&gt;
The goal is:&lt;br /&gt;
* A clean edit form (one line only)&lt;br /&gt;
* A modal to manage multiple links&lt;br /&gt;
* Deterministic behavior (no handler surprises)&lt;br /&gt;
* Easy rendering in Views and Twig&lt;br /&gt;
* Reusable across all content types&lt;br /&gt;
&lt;br /&gt;
== 1. Overview ==&lt;br /&gt;
Instead of using Drupal’s multi-value Link field (which clutters the edit form),&lt;br /&gt;
a single text field is used to store all links in JSON format.&lt;br /&gt;
&lt;br /&gt;
Each record stores its own JSON string. There is no global file.&lt;br /&gt;
&lt;br /&gt;
Example JSON stored in the field:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
  { &amp;quot;label&amp;quot;: &amp;quot;Foo&amp;quot;, &amp;quot;url&amp;quot;: &amp;quot;https://foo.com&amp;quot; },&lt;br /&gt;
  { &amp;quot;label&amp;quot;: &amp;quot;Bar&amp;quot;, &amp;quot;url&amp;quot;: &amp;quot;https://bar.com&amp;quot; }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 2. Edit Form UX ==&lt;br /&gt;
The edit form shows only one line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Website links: [ Manage links ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Clicking the button opens a modal where the editor can:&lt;br /&gt;
* Add a link&lt;br /&gt;
* Edit a link&lt;br /&gt;
* Remove a link&lt;br /&gt;
* Reorder links&lt;br /&gt;
&lt;br /&gt;
When the modal is saved, the JSON is written back into the field.&lt;br /&gt;
&lt;br /&gt;
== 3. Storage Model ==&lt;br /&gt;
A single field (e.g., &amp;lt;code&amp;gt;field_links_json&amp;lt;/code&amp;gt;) stores the JSON string.&lt;br /&gt;
&lt;br /&gt;
Characteristics:&lt;br /&gt;
* One JSON string per record&lt;br /&gt;
* No shared storage&lt;br /&gt;
* No extra entities required&lt;br /&gt;
* Deterministic and simple&lt;br /&gt;
&lt;br /&gt;
== 4. Rendering in Twig ==&lt;br /&gt;
Twig can decode and loop through the JSON:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{% set links = node.field_links_json.value|json_decode %}&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
{% for link in links %}&lt;br /&gt;
  &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;{{ link.url }}&amp;quot;&amp;gt;{{ link.label }}&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
{% endfor %}&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 5. Rendering in Views ==&lt;br /&gt;
A small custom Views field handler is used.&lt;br /&gt;
&lt;br /&gt;
Responsibilities:&lt;br /&gt;
* Read the JSON string&lt;br /&gt;
* Decode it&lt;br /&gt;
* Render 0…N links as HTML or a render array&lt;br /&gt;
&lt;br /&gt;
This keeps Views clean and avoids exposing raw JSON.&lt;br /&gt;
&lt;br /&gt;
== 6. Reusability ==&lt;br /&gt;
This architecture works for:&lt;br /&gt;
* All records in a content type&lt;br /&gt;
* Any number of content types&lt;br /&gt;
* Any custom entity type&lt;br /&gt;
&lt;br /&gt;
The field and widget are generic and reusable.&lt;br /&gt;
&lt;br /&gt;
== 7. Module Complexity Estimate ==&lt;br /&gt;
Approximate code size:&lt;br /&gt;
* Field widget: 80–120 lines&lt;br /&gt;
* Modal form: 100–150 lines&lt;br /&gt;
* Views field handler: 60–80 lines&lt;br /&gt;
* Module scaffolding: 20–40 lines&lt;br /&gt;
&lt;br /&gt;
Total: ~260–390 lines of code.&lt;br /&gt;
&lt;br /&gt;
== 8. Advantages ==&lt;br /&gt;
* Clean edit form (one line only)&lt;br /&gt;
* Deterministic behavior&lt;br /&gt;
* No multi-value field clutter&lt;br /&gt;
* No handler switching&lt;br /&gt;
* Easy to render in Twig and Views&lt;br /&gt;
* Successor-friendly and maintainable&lt;br /&gt;
* Reusable across the entire system&lt;br /&gt;
&lt;br /&gt;
== 9. Considerations ==&lt;br /&gt;
* Links are not reusable across records (by design)&lt;br /&gt;
* Requires a small custom module&lt;br /&gt;
* JSON must be validated in the modal&lt;br /&gt;
&lt;br /&gt;
== 10. Conclusion ==&lt;br /&gt;
This JSON-based approach provides a clean, predictable, and maintainable&lt;br /&gt;
solution for managing multiple website links per record, without cluttering&lt;br /&gt;
the edit form or relying on Drupal’s multi-value field behavior.&lt;/div&gt;</summary>
		<author><name>Mngr</name></author>
	</entry>
</feed>