Skip to content

Views integration

Membership entity Views data

Class: Drupal\crm_membership\MembershipViewsData
File: src/MembershipViewsData.php

The Membership content entity exposes Views data via this handler (declared on the entity type). In addition to the default entity base table and field data:

  • Label field — A synthetic label field is added to the base table. It uses id as the real field and the custom field plugin crm_membership_label to display the membership label (e.g. “Acme Corp membership for Jane Doe (Annual member)”).
  • Default field — The base table’s default field is set to label instead of id, so new Views of memberships show the label by default.

Custom field plugin: Membership label

Plugin ID: crm_membership_label
Class: Drupal\crm_membership\Plugin\views\field\MembershipLabel
File: src/Plugin/views/field/MembershipLabel.php

Views field that renders the membership entity’s label. Option “Link to entity” allows linking the label to the membership’s canonical URL. Use this field when building Views that list memberships and you want the same label as the entity’s label() method.

Optional view: membership periods for membership

Config: config/optional/views.view.membership_periods_for_membership.yml
View ID: membership_periods_for_membership

When the Views module is enabled, this optional configuration is installed. It lists membership periods filtered to a single parent membership.

Property Value
Base table crm_membership_period
Page display path admin/content/crm/membership/%crm_membership/all-periods
Route name view.membership_periods_for_membership.page_membership_periods
Contextual filter Membership ID from URL argument

Access: Users with view memberships (or administer crm_membership) can view this page. This is separate from membership period entity CRUD, which requires administer crm_membership.

The membership list (MembershipListBuilder) adds a Membership periods operation linking to this View when the route is available.

See Membership periods UI for when to use this View vs global period admin.

Building custom Views

To customize or extend membership or period listings, create a View that uses the crm_membership or crm_membership_period entity type; the base table and the custom label field are available as described above.