Skip to content

Plugin system overview

Membership Term plugins define how membership periods are calculated and how the membership lifecycle (activation, renewal, expiration, cancellation) behaves. Each Membership Type selects one plugin and its configuration; that plugin is then used for all memberships of that type.

Manager service

Plugins are managed by:

  • Service ID: plugin.manager.crm_membership_term
  • Class: Drupal\crm_membership\Plugin\MembershipTermManager

Get the manager via the service container:

$manager = \Drupal::service('plugin.manager.crm_membership_term');
$plugin = $manager->createInstance($plugin_id, $configuration);

The Membership entity resolves its term plugin internally using the type’s membership_term and membership_term_config (see Entities).

Built-in plugins

Plugin ID Class Description
fixed_duration MembershipTerm\FixedDuration Fixed date ranges (e.g. calendar year). Supports configurable start/end times, duration, and time gap between renewals.
rolling_duration MembershipTerm\RollingDuration Duration from activation (e.g. 1 year from start). Configurable duration; start/end can be overridden.
lifetime MembershipTerm\Lifetime No end date; membership does not expire. Start date can be overridden; renewal is a no-op.

Plugin classes live under src/Plugin/MembershipTerm/. Each is discovered via the #[MembershipTerm] PHP attribute (see Custom plugins).

When plugins are used

  • Activation / renewal: Forms and other code call the term plugin’s activate() or renew() to create new membership periods (with dates calculated by the plugin).
  • Status checks: Membership::isActiveFor(Contact $contact) and the service’s isMember() use the plugin’s isActiveFor() and isExpiredFor() (including grace periods where applicable).
  • Expiration: The cron/queue flow loads the membership and calls the plugin’s expire() to transition to expired and clean up periods.

See Interface for the full API and Custom plugins for implementing your own plugin.