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
#accesstoFALSEon 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
- Install and enable the Navigation module.
- Install and enable the CRM module.
- Navigate to a contact's canonical URL (e.g.
/crm/contact/1). - 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, orcrm.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_rendercallbackmergeSecondaryIntoPrimaryso 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. ContactHooksimplementsTrustedCallbackInterfaceand exposesmergeSecondaryIntoPrimaryintrustedCallbacks().
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 routescrm.contact_relationshipandcrm.contact_commentand 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— coversblockBuildLocalTasksBlockAlter(with/without navigation, wrong route),blockViewLocalTasksBlockAlter(wrong route, adds pre_render on CRM routes), andmergeSecondaryIntoPrimary(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 extendsContactTestBaseand enablesblock,datetime.
Other changes in this branch:
phpunit.xmladded at project root for running unit/kernel/functional tests.UserContactMappingTestandUserHooksTestrefactored to usecreateMock()and explicit return values instead ofgetMockBuilder()->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
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
Comment #2
bluegeek9 commentedComment #4
bluegeek9 commentedComment #6
bluegeek9 commented