Problem/Motivation

Currently, the CRM Contact "Add Relationship" page (/crm/contact/{contact_id}/relationship/add) displays all available relationship types regardless of whether the contact is eligible for them.
This can lead to invalid relationships being created and adds unnecessary complexity for site users.

We need to filter the available relationship types based on the contact's type, status, or other eligibility rules so that users only see relationship types that are valid for the given contact.

Steps to reproduce

  1. Go to a contact’s relationship tab.
  2. Click "Add Relationship."
  3. Observe that the form shows all relationship types, including types that the contact cannot validly have.

Proposed resolution

  • Create a new method to "Add Relationship" page for each contact:
    • Filter available relationship types based on the contact’s type or other eligibility rules.
    • Only show relationship types that the contact can validly participate in.
  • Ensure that programmatic creation of relationships also respects these rules.
  • Maintain the existing permissions system to control who can create relationships.

Remaining tasks

User interface changes

  • The "Add Relationship" page will only display eligible relationship types for the current contact.
  • Add contextual link on crm/contact/{crm_contact}/relationship to 'Add Relationship'

API changes

  • Add new route crm/contact/{crm_contact}/relationship/add

Data model changes

  • No changes to the data model are required; behavior changes are implemented at the form and service level.

Issue fork crm-3554372

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

Title: Restrict Add Relationship page to eligible relationship types for a contact » Relationship: Restrict Add page to eligible relationship types for a contact
bluegeek9’s picture

Issue summary: View changes

  • bluegeek9 committed a2733655 on 1.0.x
    feat: #3554372 Relationship: Restrict Add page to eligible relationship...
bluegeek9’s picture

Status: Active » 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.