internetztube / craft-element-relations
Shows all relations of an element.
Installs: 17 041
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 9
Open Issues: 3
Type:craft-plugin
Requires
- ext-json: *
- craftcms/cms: ^4.0||^5.0
Requires (Dev)
- craftcms/rector: dev-main
- 3.x-dev
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.11.1
- 3.0.11
- 3.0.9
- 3.0.8
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2.3
- 3.0.2.2
- 3.0.2.1
- 3.0.2
- 3.0.1
- 3.0.0
- 2.x-dev
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-beta.3
- 2.0.0-beta.2
- 2.0.0-beta.1
- 1.3.10
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.4-beta.2
- 1.3.4-beta.1
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.6
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-master
This package is auto-updated.
Last update: 2025-08-22 14:14:37 UTC
README
This plugin shows all relations of an element. For example, where an asset, entry or any other element is linked.
Feature Requests are welcome!
Requirements
This plugin requires Craft CMS 4.0.0 or 5.0.0 later.
For Craft CMS 4: When using SEOmatic: MySQL 8.0.17+, MariaDB 10.4.6+, or PostgreSQL 13+ is required.
Installation
To install this plugin, follow these steps:
- Install with Composer via
composer require internetztube/craft-element-relations
- Install plugin in the Craft Control Panel under Settings > Plugins
You can also install this plugin via the Plugin Store in the Craft Control Panel.
Support
As a basis the relations table is used. This means that any field that stores relations in the relations table will work out of the box.
- Entries, Assets, Categories, Globals, Users, Products, ...
- Matrix
- Neo
- SuperTable
- User Photo
- SEOmatic
- Redactor
- CkEditor
- Hyper
- LinkIt
- TypedLinkField
- Formie
... and many more.
Usage
GraphQL
The Element Relations field exposes its data in GraphQL. Query the field by its handle to
access counts, usage flags, and related elements. Below is a minimal example fetching usage
information for a field named relationsField
on an entry:
{ entry(slug: "my-entry") { ... on entry_default_Entry { title relationsField { count isInUse elements(limit: 2) { id title } globalCount: count(siteIds: []), globalIsInUse: isInUse(siteIds: []), globalElements: elements(siteIds: [], limit:2) { id title } } } } }
Twig
Obtain a RelationsModel
instance from any element’s relations field, then use its methods to inspect usage.
{# Fetch the RelationsModel from a field named `relationsField` #} {# @var relationsModel \internetztube\elementRelations\models\RelationsModel #} {% set relationsModel = element.relationsField %}
Is in use?
{# Check if the element is used in the current site #} {% if relationsModel.isInUse %} {# ... #} {% endif %} {# Check usage across all sites #} {% if relationsModel.isInUse([]) %} {# ... #} {% endif %}
Elements
{# All related elements in elements site #} {% set elements = relationsModel.elements %} {# All related elements across all sites #} {% set allElements = relationsModel.elements([]) %} {# Filter by specific site id(s) #} {% set site1Elements = relationsModel.elements([1]) %} {# Limit number of results (e.g., first 2 items) #} {% set firstTwo = relationsModel.elements([], 2) %} {# All options #} {% set elements = relationsModel.elements(siteIds = [], limit = null, offset = 0) %}
Elements Iterator
{% for element in relationsModel.elementsIterator(siteIds = [], limit = null, offset = 0, batchSize = 100) %} {{ dump(element) }} {% endfor %}
Sites
{# List of sites where the element is in use #} {% set sites = relationsModel.sites %}
Special / SEOmatic
{# Detect usage in SEOmatic global settings #} {% if relationsModel.isUsedInSeomaticGlobalSettings %} {# ... #} {% endif %}
Screenshots
Issues
Please report any issues you find to the Issues page.
Brought to you by Frederic Koeberl