Problem/Motivation

The entity_dependency_visualizer_depcalc submodule renders a graph, but the graph is wrong in two ways. Both come from DependencyCollector, which has carried @todo markers since it was added in #3275266 and was never finished.

1. Arrow labels are literal placeholder strings.

DependencyCollector::onCalculateDependencies() populates the dependency info with hard-coded text instead of real values:

'bundle' => '@todo bundle', // @todo: Call $this->getEntityBundle($entity),
...
'field'  => '@todo add field',

so every arrow in the graph is labelled:

bundle/name: @todo bundle
url: taxonomy_term/2
field: @todo add field

The Native calculator fills both of these in correctly, so switching the calculator plugin silently degrades the graph.

2. References are missing from the graph.

The same file already carries // @todo: Fix bug of missing arrows. and the bug is real: for identical content, DepCalc draws fewer edges than Native.

Steps to reproduce

On Drupal 11 with drupal/depcalc 1.23 installed (depcalc has no Drupal 12 release yet, which is why the submodule declares ^10.2 || ^11):

  1. Enable entity_dependency_visualizer, depcalc and entity_dependency_visualizer_depcalc.
  2. Create an Article with an entity reference field to nodes (field_related) and one to taxonomy terms (field_tags).
  3. Create two terms, T1 and T2, and two articles: Child, with field_tags = [T2]; and Parent, with field_tags = [T1, T2] and field_related = [Child].
  4. Visit /node/<parent>/entity_dependencies with the calculator set to Native, then set it to DepCalc at /admin/config/development/entity_dependency_visualizer/settings, rebuild caches, and visit it again.

Native produces four edges:

Parent -> Child   field: field_related
Parent -> T1      field: field_tags
Parent -> T2      field: field_tags
Child  -> T2      field: field_tags

DepCalc produces three, with Parent -> T2 missing, and every label reads bundle/name: @todo bundle / field: @todo add field.

Proposed resolution

  1. Replace the placeholders with the real values. The abstract calculator already provides getEntityBundle($entity), which is what the inline @todo comment points at. The field name is harder: DepCalc reports deapendencies per entity rather than per field, so the collector needs to work out which field on the parent produced each child. The Native calculator now records this as child_fields[<child uuid>] = <field name> on the parent, and Graphviz::getArrowLabel() reads that first, so populating the same key here is enough to make the labels correct.
  2. Find out why Parent -> T2 is dropped. A likely cause is that the collector keys $deplist by wrapper uuid and each entity is only visited once, so a term already collected as a child of one entity is not re-registered as a child of another. This needs confirming against DependentEntityWrapper::getChildDependencies().

Remaining tasks

  • Fix the labels.
  • Fix the missing edges.
  • Add test coverage for the DepCalc calculator. There is currently none: the test suite only exercises the Native plugin, which is why both of these survived. A kernel or functional test asserting that the DepCalc graph has the same edge set as the Native graph for the same content would cover both bugs at once.

User interface changes

Arrow labels in DepCalc mode will show real bundle and field names, and the graph will show the references it is currently missing.

API changes

None expected.

Notes

  • Both bugs predate #3597677 and were found while testing that branch; that branch deliberately did not touch them.
  • drupal/depcalc 1.23 requires drupal/core ^9.4.15 || ^10 || ^11, so Drupal 12 support for this submodule is blocked on depcalc itself and belongs in a separate issue.

Comments

marcelovani created an issue. See original summary.

marcelovani’s picture

Issue summary: View changes