Yarn for Craft CMS

Free · Craft CMS 5

Is anything still using this?

Craft knows exactly which entry uses which image. It just never tells you. There is no screen in the control panel that answers the question, and the answer matters most at the moment somebody is about to press Delete. Yarn reads the relations Craft already stores, plus the ones it doesn’t — reference tags in rich text, hard-coded links, relations buried in Matrix blocks — and shows you both ends of every one.

Yarn

One element, both ends

This is Yarn’s element screen, with the Relations panel from the edit-screen sidebar beside it, running the plugin’s own rules against a small sample site. Pick another element, or switch roll-up off, and everything recomputes.

Yarn → Browse → studio-front.jpg

Points at

Pointed at by

Pick Careers or Our team to see a page from both ends, then pick open-studio-map.pdf: it is only reached by a reference tag, so the sidebar panel, which counts relation fields only, says nothing uses it while the full view says something does. Switch roll-up off and the Matrix blocks become elements of their own — which is accurate, and not what anyone opening the control panel means.

The panel reads the relations table directly, because it renders on every edit screen on the site and building a whole-site graph there would slow every edit form down. It counts relation fields only. The full view also counts reference tags, links and Matrix blocks, and it’s one click away.

Ask from a template, or from a deploy

The cheap calls read the relations table for one element and are fine on a front-end page. The whole-site ones belong in a report. And the findings command exits non-zero, so a pipeline can refuse to ship a page pointing into the trash.

twig
{# cheap: one element, straight from the relations table #}
{% if craft.yarn.isUsed(asset) %}
  <p>Used on {{ craft.yarn.usageCount(asset) }} pages.</p>
{% endif %}

<h2>Also mentioned in</h2>
{% for other in craft.yarn.usedBy(entry) %}
  <a href="{{ other.url }}">{{ other.title }}</a>
{% endfor %}

{# and from the console #}
{# php craft yarn/element 1234 --depth=3     both directions, three hops of knock-on #}
{# php craft yarn/path 1234 5678             how one element reaches another #}
{# php craft yarn/findings --fail-on=error   the audit, with an exit code for CI #}
{# php craft yarn/export --format=dot | dot -Tsvg > site.svg #}

Features

Four ways of looking at the same graph, and a panel that catches you before the delete.

A map of the whole site

Every element and every relation, laid out and colour-coded by kind. Click one to light up its threads, double-click to see only its neighbourhood, and drag one to pin it. The layout is about two hundred lines of hand-written arithmetic, not a graph library.

  • Filter by kind, section, volume or group
  • Unconnected elements hidden by default, and counted
  • Says when it has trimmed to the busiest elements

Both directions for anything

What an element points at and what points at it, grouped by the field each relation came through, plus what else breaks at two and three removes. An asset in a hero field and in three Matrix blocks reads as used four times, because it is.

  • Matrix and CKEditor relations rolled up onto the page
  • Roll-up is a setting — switch it off to see the blocks
  • The shortest path from one element to another

Asset usage and globals

Every asset with a use count and the pages that use it, filterable down to the ones nothing uses. And globals, which are the blind spot: nothing in Craft tells you the image you’re about to delete is in the footer of every page.

  • Filter by volume, or to unused only
  • Each global set, what it points at, and how far that reaches
  • The “only what Yarn scans” caveat on every screen that says unused

Eight findings, each with a next step

Relations into the trash, relations to elements missing from the site, live pages pointing at things that aren’t live, reference tags that resolve to nothing, orphans, unused assets, circular relations and elements related to themselves. Every finding says what to do, not just what’s wrong.

  • Sorted worst first: errors, warnings, notices
  • Only ids and UIDs are resolved; other plugins’ ref grammars are skipped, not flagged
  • The same checks from the console, with --fail-on

A panel on every edit screen

The sidebar of every element edit screen says how many elements point at this one and what deleting it will empty. It reads the relations table directly, so it adds nothing you’d notice to a page nobody opened Yarn to look at.

  • Counts relation fields only, and says so
  • “See the whole thread” opens the full view
  • Can be switched off in settings

Nothing to install but the plugin

No database tables, no runtime dependencies, no build step. Settings live in project config, and the graph is built in memory and cached until any element is saved, deleted or restored. Export it as JSON, CSV, Graphviz DOT or Mermaid.

  • Drafts and revisions excluded everywhere
  • Other plugins can add their own relations through an event
  • Uninstalling leaves nothing behind

Yarn in the control panel

The map with one entry selected, an element seen from both ends, the findings it raised, and the panel on an entry’s edit screen.

The Yarn map in the Craft control panel: 68 connected elements colour-coded by kind, with the entry “South quay scheduling: the plan” selected so its six outgoing and five incoming relations stay lit while the rest of the graph fades, and a card showing its counts
Yarn’s view of the entry “Harbour terminal moves to a single scheduling window”: four things it points at grouped by field, four entries pointing at it through reference tags, and three more two hops downstream that deleting it would affect
The Yarn findings screen with 2 errors, 3 warnings and 157 notices: two reference tags that resolve to nothing, two circular relations, a live entry pointing at a disabled one, then entries nothing points at, each with a sentence saying what to do
An entry edit screen in the Craft control panel with Yarn’s Relations panel in the sidebar, warning that 3 elements point at this entry and deleting it will empty those fields, with a button to see the whole thread

Screenshots from a live install, not mockups. The findings were planted on purpose: a dead reference tag, two cycles and a live page pointing at a disabled one.

Frequently Asked Questions

The questions worth answering before you trust it with a delete.

Find out what’s holding on

Install it, open Yarn → Map, and the first load builds the graph. After that, every edit screen has a Relations panel, and the findings list will tell you what was already broken.