For each fieldable entity display number of entities that have value on each entity's fields

Created on 1 April 2024, 6 months ago
Updated 16 August 2024, about 1 month ago

Problem/Motivation

Sometimes is good to know if a field is used or not. I would be great to have a report for each fieldable entity (nodes, taxonomies, useds, etc) that displays all entity fields with the number of entities that use that field. Similar to "Node report" (/admin/reports/xray-audit/queries_data/queries_data_node-node_by_types) but for fields.

It could be for a fixed list of entities (as said before: nodes, users, taxonomies) or automatically include all include fieldable entities.

Proposed resolution

The report can begin reporting the fields that are not basic fields of the entity because the basic ones can't be removed, and this report is mainly useful when simplifying content architecture.

Remaining tasks

User interface changes

A new report will be added.

API changes

Data model changes

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇪🇸Spain tunic Madrid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @tunic
  • 🇪🇸Spain tunic Madrid

    Just for reference, this code returns the nodes of a certain content type that have value (not null) on a given field:

    
    $ct_name = "theContentType";
    $field_name = "theField";
    $node_storage = \Drupal::entityTypeManager()->getStorage('node');
    
    $nids = $node_storage->getQuery()->condition($field_name, NULL, "IS NOT NULL")->condition("type", $ct_name)->execute();
    
    $nodes = $node_storage->loadMultiple($nids);
    
  • 🇪🇸Spain tunic Madrid

    Why do this only for nodes when we can do it for all fieldable entities?

  • 🇪🇸Spain lpeidro Madrid

    Hello @Tuni, yes, this is indeed a very interesting and useful functionality for detecting fields that are not in use and thus being able to simplify the content architecture.

    I just want to add a clarification to the description of the functionality: in a first iteration, at least, this check should be performed only on fields that are not basic fields of the entity. Since these are the fields that can be eliminated, and also we would reduce the amount of information in the report, resulting in something more manageable and useful.

  • 🇪🇸Spain tunic Madrid

    Ok to start with fields that are not basic fields of entities.

  • Assigned to lpeidro
  • 🇪🇸Spain lpeidro Madrid

    Status

    First approach completed.

    It has been implemented for the case of nodes. However, it would be advisable to implement a batch process since these queries might take some time. In the end, we performed an accounting of the usage of all fields.

    It might be worthwhile to create another report from the perspective of the storage

Production build 0.71.5 2024