Skip to content

Entities

The module defines three entity types: one config entity (Membership Type) and two content entities (Membership and Membership Period). Source: src/Entity/.

See Status and periods for how membership_status, status, and current_periods interact.

Membership

Class: Drupal\crm_membership\Entity\Membership Entity type ID: crm_membership Base table: crm_membership Revision table: crm_membership_revision

Content entity representing a membership record. It links one or more Contact entities (the members) to a target Contact (the “member of” entity, e.g. an organization). Each membership has a bundle (Membership Type) that selects the Membership Term plugin and its configuration.

Entity keys

Key Field
id id
revision vid
bundle type
uuid uuid
label id (label is built dynamically via label())
published status

Label format

label() returns a translatable string:

@target membership for @contacts (@membership_type)

Example: “Acme Corp membership for Jane Doe (Annual member)”.

Base fields

Field Type Description
contacts entity_reference (crm_contact, unlimited) The contact(s) who are members.
target_contact entity_reference (crm_contact, 1) The contact this membership is “for” (member of).
status boolean Published flag (EntityPublishedInterface). Defaults to published.
membership_status list_string Lifecycle: active, future, or expired.
current_periods entity_reference (crm_membership_period, unlimited) Current membership period(s) for this membership.
created created Creation timestamp.
changed changed Last change timestamp.

preSave behavior

If target_contact is empty when saving, preSave() copies the type’s default_target_contact onto the membership.

Link Path
canonical /crm/membership/{crm_membership}
add-page /crm/membership/add
add-form /crm/membership/add/{crm_membership_type}
edit-form /crm/membership/{crm_membership}/edit
delete-form /crm/membership/{crm_membership}/delete
renew-form /crm/membership/{crm_membership}/renew
collection /crm/membership

Handlers

  • Views data: MembershipViewsData — exposes a “Label” field and sets the base default field to label.
  • Access: MembershipAccessControlHandler.
  • List builder: MembershipListBuilder — adds Renew and Membership periods operations.
  • Route provider: MembershipRouteHtmlRouteProvider.
  • Forms: default/add/edit MembershipForm, delete ContentEntityDeleteForm, renew MembershipRenewForm.

Notable methods

Method Purpose
getType() Membership Type bundle.
getContacts() / addContact() Member contacts.
getTargetContact() / setTargetContact() Target (“member of”) contact.
getMembershipStatus() / setMembershipStatus() Lifecycle: active, future, or expired.
isPublished() / setPublished() / setUnpublished() Published flag via EntityPublishedInterface.
getCurrentPeriods() / addCurrentPeriod() Current period references.
getCurrentPeriodsForContact() Periods applicable to a given contact.
isActiveFor(Contact $contact) Delegates to the term plugin.
getMembershipTerm(bool $reset = FALSE) Resolves and caches the term plugin for this membership.
getCreatedTime() / getChangedTime() Timestamps.

Membership Type

Class: Drupal\crm_membership\Entity\MembershipType Entity type ID: crm_membership_type Config prefix: crm_membership_type

Config entity that acts as the bundle for crm_membership. Defines the membership category (label, description), optional default target contact, and which Membership Term plugin to use plus its configuration.

Config export keys

  • id
  • label
  • description
  • default_target_contact
  • membership_term (plugin ID)
  • membership_term_config (sequence of plugin config)
Link Path
add-form /admin/structure/crm/membership_types/add
edit-form /admin/structure/crm/membership_types/{crm_membership_type}/edit
delete-form /admin/structure/crm/membership_types/{crm_membership_type}/delete
collection /admin/structure/crm/membership_types

Handlers

  • Access: MembershipTypeAccessControlHandler — grants view, update, delete, and create when the user has the corresponding granular permission or administer crm_membership.
  • List builder: MembershipTypeListBuilder.
  • Form: add/edit MembershipTypeForm, delete EntityDeleteForm.
  • Route provider: AdminHtmlRouteProvider.

The entity definition sets collection permission view crm membership types for the collection route.

Methods: getMembershipTermPluginId(), getMembershipTermPluginConfig().


Membership Period

Class: Drupal\crm_membership\Entity\MembershipPeriod Entity type ID: crm_membership_period Base table: crm_membership_period Revision table: crm_membership_period_revision

Content entity representing a single time span of a membership. It has a date range and optional applicable contacts; if applicable contacts are not set, getApplicableContacts() falls back to all contacts on the parent membership (useful for household memberships where a period can restrict which contacts are covered).

Entity keys

Key Field
id id
revision vid
uuid uuid
label id (label built dynamically via label())

Label format

With end date: “Membership period from @start_date to @end_date for @contacts” Without end date: “Membership period from @start_date for @contacts”

Base fields

Field Type Description
membership entity_reference (crm_membership, 1) Parent membership.
date_range daterange Start and end datetime for the period.
applicable_contacts entity_reference (crm_contact, unlimited) Contacts this period applies to; empty means all contacts on the membership.
created created Creation timestamp.
changed changed Last change timestamp.
Link Path
canonical /crm/membership/periods/{crm_membership_period}
add-form /crm/membership/periods/add
edit-form /crm/membership/periods/{crm_membership_period}/edit
delete-form /crm/membership/periods/{crm_membership_period}/delete
collection /crm/membership/periods

Handlers

  • Views data: EntityViewsData (default).
  • List builder: MembershipPeriodListBuilder.
  • Route provider: AdminHtmlRouteProvider.
  • Forms: default/add/edit MembershipPeriodForm, delete ContentEntityDeleteForm.

Notable methods: getMembership(), getApplicableContacts(), isApplicableForContact(Contact $contact), getStartDate(), getEndDate(), isActive(), isExpired().