Problem/Motivation

When the Navigation module is installed and the entity.crm_contact.canonical route is loaded, the CRM module has poor integration:

  • The navigation module sets #access to FALSE on the local tasks block, hiding all tabs.
  • Navigation takes primary tasks (level 0) and places them in its "More actions" region, but does nothing with secondary tasks (level 1).
  • Secondary tasks (Summary, Relationships, Comments) never appear because navigation only reads level 0.

As a result, users cannot access Summary, Relationships, or Comments from the contact view page when navigation is installed.

Steps to reproduce

  1. Install and enable the Navigation module.
  2. Install and enable the CRM module.
  3. Navigate to a contact's canonical URL (e.g. /crm/contact/1).
  4. Observe that the local tasks block is hidden and secondary tabs (Summary, Relationships, Comments) are not visible in the navigation "More actions" dropdown.

Proposed resolution

Update the ContactHooks class to add hook implementations that run after the navigation module's implementations, so CRM can restore the local tasks block visibility and show a single row of tabs (Summary, Relationships, Comments) on contact-related routes.

Implementation (as implemented)

The branch implements the following.

1. hook_block_build_local_tasks_block_alter()

  • Runs after navigation via #[Hook(..., order: new OrderAfter(['navigation']))].
  • When the navigation module is installed and the route is one of entity.crm_contact.canonical, crm.contact_relationship, or crm.contact_comment, unset($build['#access']) so the local tasks block is visible (default access behavior).

2. hook_block_view_local_tasks_block_alter()

  • Runs after navigation with the same order.
  • On the same three routes when navigation is installed, adds a #pre_render callback mergeSecondaryIntoPrimary so the block displays a single row of tabs (secondary tasks in the primary slot) and does not show a "Secondary tabs" heading. Task data is not altered for Navigation or other consumers.
  • ContactHooks implements TrustedCallbackInterface and exposes mergeSecondaryIntoPrimary in trustedCallbacks().

Dependencies in ContactHooks:

  • ModuleHandlerInterface (Core\Extension) — moduleExists('navigation').
  • RouteMatchInterface — to check the current route in both alter hooks.

Contact entity (src/Entity/Contact.php):

  • Link templates added: relationship/crm/contact/{crm_contact}/relationship, comment/crm/contact/{crm_contact}/comment. These align with the existing routes crm.contact_relationship and crm.contact_comment and support tab URLs.

Service definition (crm.services.yml):

  • Drupal\crm\Hook\ContactHooks: ~ added so the class is autowired and available for the new hooks.

Tests:

  • Kernel: ContactHooksNavigationTest — covers blockBuildLocalTasksBlockAlter (with/without navigation, wrong route), blockViewLocalTasksBlockAlter (wrong route, adds pre_render on CRM routes), and mergeSecondaryIntoPrimary (merge primary+secondary, empty secondary).
  • Functional: NavigationIntegrationTest::testContactTabsSingleRowWithNavigation() — ensures contact canonical and relationship tab show Summary/Relationship in one row and no "Secondary tabs" when Navigation is enabled. Class now extends ContactTestBase and enables block, datetime.

Other changes in this branch:

  • phpunit.xml added at project root for running unit/kernel/functional tests.
  • UserContactMappingTest and UserHooksTest refactored to use createMock() and explicit return values instead of getMockBuilder()->onlyMethods(); behavior unchanged.

Remaining tasks

  • None. Implementation and tests are in place.

User interface changes

When the Navigation module is installed and the user is on a contact-related route (entity.crm_contact.canonical, crm.contact_relationship, or crm.contact_comment):

  • The local tasks block is visible (access restored by unsetting #access).
  • A single row of tabs (Summary, Relationship, Comments) is shown in the block; the "Secondary tabs" heading does not appear.

When the Navigation module is not installed, behavior is unchanged.

API changes

None. Internal hook implementations only.

Data model changes

None.

Issue fork crm-3571612

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

bluegeek9 created an issue. See original summary.

bluegeek9’s picture

Issue summary: View changes

bluegeek9’s picture

Status: Active » Needs review

bluegeek9’s picture

Status: Needs review » Fixed
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triage issues and adding more context to existing issues.
  • Flagging CRM as a favorite on the project page to help others discover it and show your support.
  • Review the Developer Docs for accuracy and clarity.

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.