Skip to content

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.

The plugin is always used in the context of a single membership; the manager/createInstance flow does not set the membership — the caller must call setMembership() after instantiation.

Configuration

Method Purpose
getSettings(): array Return the plugin configuration (e.g. duration, time gap). Typically the same as the membership type’s membership_term_config.

Status checks

Method Purpose
isActiveFor(Contact $contact): bool Whether the membership is currently active for the given contact. May take grace periods into account. Used by Membership::isActiveFor() and by MembershipService::isMember().
isExpiredFor(Contact $contact): bool Whether the membership is expired for the contact (no grace). Used when evaluating expiration.

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 any cleanup (e.g. remove from current_periods). Used by the expiration queue worker.
cancel(): void Cancel the membership (e.g. end current periods, set status).

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.

Configuration form (base class)

MembershipTermBase defines buildConfigurationForm(array $current_config, FormStateInterface $form_state): array. The base implementation returns an empty array; subclasses (e.g. FixedDuration, RollingDuration) override it to provide duration, start time, time gap, etc. The form is used when editing a Membership Type to configure the selected term plugin.