Skip to content

Link Field doesn't return any data #201

Description

@sk8stevieuk

Description

When trying to access a link field with the Element API, no data is returned that is usable. What I get instead is:

urlSuffix | null
target | null
title | null
class | null
id | null
rel | null
ariaLabel | null
download | false

Has this been added when the link field was added to Craft?

Additional info

  • Craft version: 5.10.3
  • PHP version: 8.2

Activity

  1. linear-code commented on Jun 9, 2026

    @linear-code
  2. added a commit that references this issue on Aug 5, 2026
    24371bd
  3. brandonkelly commented on Aug 5, 2026

    @brandonkelly
    Member

    That’s just the default array representation of craft\fields\data\LinkData objects, based on the class’s public properties.

    You can fetch additional values by calling their public methods directly. For example, if all you want is the resulting URL, you could do:

    'transformer' => fn(Entry $entry) => [
        'linkUrl' => $entry->myLinkField->getUrl(),
    ],

    Or if you want additional info from LinkData:

    'transformer' => fn(Entry $entry) => [
        'linkData' => [
            'label' => $entry->myLinkField->getLabel(),
            'url' => $entry->myLinkField->getUrl(),
            // ...
        ],
    ],

    That said, I’ve updated LinkData to automatically include several new values when it’s converted to an array, for Craft 5.11:

    • type
    • value
    • url
    • label
    • filename
    • link
    • attributes
    • defaultLabel
    • elementType
    • elementId
    • elementSiteId
    • elementTitle
  4. brandonkelly commented on Sep 1, 2026

    @brandonkelly
    Member

    Craft 5.11.0 is out with that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions