MembershipTermInterface
All Membership Term plugins implement Drupal\crm_membership\Plugin\MembershipTermInterface. The interface defines how the membership lifecycle and status are controlled. Base implementation: MembershipTermBase in src/Plugin/MembershipTermBase.php.
Membership binding
| Method | Purpose |
|---|---|
setMembership(Membership $membership): void |
Set the membership entity the plugin operates on. Called before using the plugin. |
getMembership(): ?Membership |
Get the current membership. |
When using plugin.manager.crm_membership_term directly, the caller must call setMembership() after instantiation. The Membership entity’s getMembershipTerm() method handles this automatically.
Configuration
| Method | Purpose |
|---|---|
getSettings(): array |
Return the plugin configuration (e.g. duration, grace period). Typically the same as the membership type’s membership_term_config. |
Configuration form (base class)
These methods are used when editing a Membership Type (MembershipTypeForm):
| Method | Purpose |
|---|---|
buildConfigurationForm(array $current_config, FormStateInterface $form_state): array |
Build plugin-specific settings on the type form. Base returns an empty array; subclasses override. |
validateConfigurationForm(array $form, FormStateInterface $form_state): void |
Validate submitted configuration. |
saveConfiguration(array $values): array |
Convert form values to config stored in membership_term_config. |
Status checks
| Method | Purpose |
|---|---|
isActiveFor(Contact $contact): bool |
Whether the membership is currently active for the given contact. Checks current periods and grace period (days after end date). Used by Membership::isActiveFor() and MembershipService::isMember(). |
isExpiredFor(Contact $contact): bool |
Not implemented in MembershipTermBase (returns FALSE; @todo implement). Cron does not call this method — it compares period date_range.end_value instead. Lifetime overrides to always return FALSE. |
Lifecycle actions
| Method | Purpose |
|---|---|
activate(?array $contacts = NULL): void |
Activate the membership: create initial membership period(s). If $contacts is null, use the membership’s contacts. Called when a new membership is first activated. |
renew(?array $contacts = NULL): void |
Renew: add new period(s) (e.g. next year). Optional contact list; null means all membership contacts. No-op for lifetime. |
expire(): void |
Mark the membership as expired and perform cleanup (e.g. clear current_periods). Used by the expiration queue worker. |
cancel(): void |
Cancel the membership. No UI route or form calls this — use programmatically only. |
Date overrides and renewal
| Method | Purpose |
|---|---|
allowRenewal(): bool |
Whether this term allows renewal (e.g. lifetime returns false). |
allowOverrideStartDate(): bool |
Whether the UI/code may override the period start date when activating or renewing. |
allowOverrideEndDate(): bool |
Whether the end date may be overridden. |
setStartDate(DrupalDateTime $start): void |
Set an override start date for the next period (used before activate()/renew()). |
setEndDate(DrupalDateTime $end): void |
Set an override end date for the next period. |
Override flags are defined on the plugin attribute (see Custom plugins); the setters are used by forms to pass in user-entered dates.
Protected helper: addMembershipPeriod()
Custom plugins should use the base class addMembershipPeriod($contacts, $start, $end) to create periods. It:
- Creates and saves a
crm_membership_periodentity with the date range and applicable contacts. - Removes expired periods from
current_periods. - Adds the new period to
current_periods. - Sets membership
statustoactiveorfuturebased on whether the period is currently active. - Saves the membership with a new revision.
See Custom plugins and Status and periods.