Skip to content

Link fieldtype recursively augments linked entries causing infinite loop #14696

Closed

Description

@o1y

Bug description

A link fieldtype that points to an entry whose own link field points back triggers infinite recursion as soon as anything deep-augments the entry (live preview,Entry::toArray(), JSON serialization etc.).

Expected:
The augmentation should bottom out, like it does for the other relationship fieldtypes (entries, terms, users).

How to reproduce

  1. Create a blueprint with a link field.
  2. Add two entries A and B; A's link_field = entry::B, B's link_field = entry::A.
  3. Any template that JSON-serializes the entry, e.g. {{ page | to_json }}.
  4. Visit A in the browser:
Maximum call stack size … reached. Infinite recursion?

Logs

Environment

Environment
Application Name: Statamic
Laravel Version: 12.60.1
PHP Version: 8.4.19
Composer Version: 2.9.8
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Storage
public/storage: NOT LINKED

Statamic
Sites: 8 (English, Deutsch, Español, and 5 more)
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.73.22 PRO

Installation

Fresh statamic/statamic site via CLI

Additional details

It is also a V6 issue.

Possible "fix"

In src/Fieldtypes/Link/ArrayableLink.php:

public function toArray()
{
-    return is_object($this->value)
-        ? $this->value->toAugmentedArray()
-        : ['url' => $this->url()];
+    if (! is_object($this->value)) {
+        return ['url' => $this->url()];
+    }
+
+    if ($this->value instanceof \Statamic\Contracts\Data\Augmentable) {
+        return array_merge(
+            $this->value->toShallowAugmentedArray(),
+            ['url' => $this->url()]
+        );
+    }
+
+    return ['url' => $this->url()];
}

Activity

  1. o1y commented on May 20, 2026

    @o1y
    ContributorAuthor

    Could be a duplicate of #9105

  2. duncanmcclean commented on May 21, 2026

    @duncanmcclean
    Member

    Sounds like the same issue to me. Closing in favour of #9105

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions