@kreatifklub/directus-extension-custom-link-json-interface
v1.0.7
Published
Directus interface extension for structured internal/external links in JSON fields
Maintainers
Readme
Directus Custom Link JSON Interface
Directus interface extension for json fields that manages repeatable link objects with:
- Internal or external link type
- Internal custom path or dynamic collection-based URL (
id+slug) - External custom URL
- Target (
_self/_blank) - Title
- Multiple
relvalues - Custom query parameters
- URL and required-field validation
Compatibility
- Directus
11.17.2and newer within major11(^11.17.2)
Install
npm install
npm run buildCopy this extension folder into your Directus extensions directory (folder name should start with directus-extension-), then restart Directus.
Field Setup
- Create a field with type
JSON. - Choose interface Custom Link (JSON).
- Configure interface options:
Allowed Internal CollectionsSelectable rel Values- Optional limits/defaults (
Max Links,Default Target, etc.)
Global Settings (Singleton)
For centralized defaults across many fields:
- Create a singleton collection (for example
link_interface_settings). - Add fields with the exact keys below:
maxLinksitemFetchLimitrequireTitlerequireHrefdefaultTargetdefaultInternalPathTemplateinternalCollections(JSON)externalCollections(JSON)relChoices(JSON)
- In each field interface config:
- Enable
Use Global Settings - Set
Global Settings Collection - Keep
Override Global For This Fielddisabled to use global values - Enable
Override Global For This Fieldwhen a specific field needs custom behavior
Stored JSON Shape
The field stores an array of link objects:
[
{
"type": "internal",
"title": "Product Detail",
"target": "_self",
"rel": ["nofollow"],
"queryParams": [
{ "key": "ref", "value": "homepage" }
],
"internal": {
"mode": "dynamic",
"customPath": "",
"collection": "products",
"itemId": "42",
"slugField": "handle",
"slugValue": "air-conditioner",
"titleValue": "Air Conditioner",
"pathTemplate": "/{collection}/{id}/{slug}"
},
"href": "/products/42/air-conditioner?ref=homepage",
"errors": []
}
]Notes
hrefis resolved by the interface for preview and output convenience.errorscontains current validation errors for each link entry.- Output includes only the active link branch (
internalfor internal links,externalfor external links). - Dynamic internal links default to
handleand supportslug(fallback), or any custom field viaslugField. - External links are URL-only (for example
https://google.com) and do not use collection item selection. - If you prefer to persist only selected properties, adapt
toLinkValue()insrc/interface.vue.
