Problem/Motivation

In #3547945: Call to a member function getPath() on null, we moved an entity link:

I have tried to move

#[ConfigEntityType(
  id: 'pattern_preset',
  ...
  links: [
    'edit-form' => '/admin/structure/display-builder/preset/{pattern_preset}',
  ],
)]

To display_builder_ui module, where the route belongs:

  #[Hook('entity_type_alter')]
  public function entityTypeAlter(array &$entity_types): void {
    $entity_types['pattern_preset']->setLinkTemplate('edit-form', '/admin/structure/display-builder/preset/{pattern_preset}');
  }

In order to avoid a fatal error.

Steps to reproduce

Do we need to do the same for other links and handlers with routes managed by display_builder_ui?

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pdureau created an issue. See original summary.

pdureau’s picture

pdureau’s picture

The bigger question here is: what happens if I disable display_builder_ui? Does it breaks?

There are currently 3 hard dependencies to display_builder_ui from the main module:

$ grep -r display_builder_ui src/
src/Entity/Profile.php:use Drupal\display_builder_ui\ProfileListBuilder;
src/Entity/Instance.php:use Drupal\display_builder_ui\InstanceListBuilder;
src/Entity/PatternPreset.php:use Drupal\display_builder_ui\PatternPresetListBuilder;

So, with display_builder_ui disabled:

Profiles

  • entity.display_builder_profile.collection: ❌ /admin/structure/display-builder : InvalidPluginDefinitionException: The list_builder handler of the "display_builder_profile" entity type specifies a non-existent class "Drupal\display_builder_ui\ProfileListBuilder"
  • entity.display_builder_profile.add-form: /admin/structure/display-builder/add >> ⚠️ Is loading. Is it really what we want?

Instances

  • entity.display_builder_profile.collection: /admin/structure/display-builder/instances >> ✅ 404 NOT FOUND

Presets

  • entity.pattern_preset.collection: /admin/structure/display-builder/preset >> ✅ 404 NOT FOUND
  • entity.pattern_preset.add-form: /admin/structure/display-builder/preset/add >> ✅ 404 NOT FOUND

andres alvarez made their first commit to this issue’s fork.

andres alvarez’s picture

Consolidated all UI route links into DisplayBuilderUiHooks::entityTypeAlter().

All nine link templates for pattern_preset, display_builder_profile, and display_builder_instance are for routes owned and defined by display_builder_ui.routing.yml. Removed link declarations from entity type annotations (the three entity classes) and moved them to a single place: entityTypeAlter() in the UI module. This makes responsibility clear: display_builder_ui manages routes and their link templates; the main modules no longer need to know about routing.

Added EntityLinkTemplatesTest (Kernel test) that verifies: (1) the links come from the hook, not the annotations, and (2) the link templates resolve to the correct routed paths for both collection and per-entity forms.

Kept edit-plugin-form on the Profile entity, since that route is not managed by display_builder_ui.

MR to follow.

andres alvarez’s picture

Status: Active » Needs review
pdureau’s picture

Status: Needs review » Needs work

Thanks a lot Andres.

Before sending to review, can you:

  • rebase your branch with 1.0.x
  • fix the phpunit fail (see pipeline)
pdureau’s picture

Status: Needs work » Needs review
mogtofu33’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.