Entity Usage

Categories

Component ID

2760065

Component name

Entity Usage

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

1180

Component created

Component changed

Component body

This module provides a tool to track usage of entities by other entities in drupal.

Currently the following "relationship" methods are supported out of the box:
- Entities related trough entity_reference fields
- Entities embedded into text fields (using the Entity Embed module)

Installation & Usage

There is no specific configuration, once enabled, the module will start tracking the relation between entities, being updated on all CRUD entity operations.

A basic views integration is provided. To use the tracked information in a view, follow the following steps:

  1. Create a view that has as base table any content entity (Node, User, Etc)
  2. Add a relationship to your view named
    "Information about the usage of this @entity_type"
  3. After adding the relationship, add the field to your view:
    "Usage count"
  4. You will probably want to enable aggregation, to avoid duplicate rows and have the real count sum. To do that, go to the "Advanced" section of the view configuration, select "Use aggregation" to "Yes"
  5. Go to the "Usage count" field you added before, open up the "Aggregation settings" form, and select "SUM"

In your view (or anywhere else) you can build a link to the page where you can consult the details of the entities that use (reference) any given entity. Build the link using the following structure:

/admin/content/entity-usage/{entity_type}/{entity_id}

Make sure the visitors of this page have the permission to 'access entity usage statistics' enabled.

This module is in early development phase. Please help testing it and provide feedback on the issue queue.

For developers

You can use the service
Drupal::service('entity_usage.usage')->listUsage($entity);
to get the statistics anywhere in your code.

If you want to provide your own tracking method (additionally to the methods provided by this module, which are entity_reference and entity_embed), you only need to implement a plugin of type @EntityUsageTrack, which will be used on all CRUD entity operations.

Examples on how to implement this plugin type can be found in src/Plugin/EntityUsage/Track

Feedback is very welcome on the issue queue.