Add absolute url property to FileUriItem field type

Created on 6 February 2025, 3 months ago

Problem/Motivation

When looking at a File field, you can quickly get access to the internal URI through the "value" property and and relative paths through the "url" property but the absolute path is not available. This generally isn't a big deal as we generally _want_ the relative path or to send the URI through a URL object which gives a lot more flexibility to a developer.

However, when using a system built entirely off properties and typed data like SearchAPI, that flexibility is not available. Recently I needed to push that absolute URL into a SearchBackend and its not readily available requiring a lot of hacking.

A simple solution is to add an absolute property to the FileType so its available when needed.

Steps to reproduce

This is admittedly pretty specialized but if you have a site using SearchAPI you can try pushing an absolute URL and see the missing functionality.

Proposed resolution

Add an absolute URL property to the FileUriItem file type.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

No database changes. New computed property available on FileUriItem fields.

Additional notes

✨ Add a computed 'file_url' property to FileItem (for exposing file URL in file field normalization) Needs work is talking about a similar URL functionality, though only the relative URL, on the related FileItem field type. If this is added, it would probably be useful to include the same functionality there.

Release notes snippet

✨ Feature request
Status

Active

Version

11.1 πŸ”₯

Component

file.module

Created by

πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @neclimdul
  • πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX

    Pushed a simple implementation. Testing still needed but its "reviewable"

  • Merge request !11136Absolute file url on FileUriItem β†’ (Open) created by neclimdul
  • Pipeline finished with Failed
    3 months ago
    Total: 772s
    #417142
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    search api also supports computed properties through plugins, I'm not convinced that this is worth doing.

  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX

    Skimming the failures I see some interesting things including a lot of tests asserting relative url's in places I would have expected the API to want an absolute URL so my gut tells me this is maybe kinda needed by other places in core.

    And while search_api could fix it, I feel like this is a common problem I run into so I'd like to push the fix to the source rather then having a ton of hacks.

    But also that's just a ton of systems affected by failures and its going to take a long time to audit and review just the test changes that would be involved let alone documenting how this would help site developers and contrib.

    So rather then just leaving this to clog up the queue I'm going to go ahead and close it as suggested and I'll revist it as I have time to review all that code and document why this is needed better.

  • πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX
Production build 0.71.5 2024