Change record status: 
Project: 
Introduced in branch: 
2.0.x
Introduced in version: 
2.0.0
Description: 

Before:

  • A GroupContentEnabler would declare its handlers like entity types do: in its annotation
  • The handler was a class that could get a container injected
  • The handlers were semi-optional

After:

  • A GroupRelationType no longer declares handlers in the annotation
  • The handlers are Symfony services that follow a specific naming pattern
  • The handlers are mandatory, but any handler you do not declare yourself will be declared for you

Example of how to declare handlers now:

# Note that ALL handlers must be declared as non-shared!
# Naming pattern is group.relation_handler.HANDLER_MACHINE_NAME.BASE_PLUGIN_ID

  # If this one uses the default, you can omit it and Group will declare it for you.
  # group.relation_handler.access_control.group_membership:

  # This one adds to the defaults so you need to declare it and have it decorate the default.
  group.relation_handler.permission_provider.group_membership:
    class: 'Drupal\group\Plugin\Group\RelationHandler\GroupMembershipPermissionProvider'
    arguments: ['@group.relation_handler.permission_provider']
    shared: false

What a handler service's class looks like:

namespace Drupal\group_test_plugin_alter\Plugin\Group\RelationHandler;

use Drupal\group\Plugin\Group\RelationHandler\PermissionProviderInterface;
use Drupal\group\Plugin\Group\RelationHandler\PermissionProviderTrait;

/**
 * Alters admin permission for a specific plugin to original + 'bar'.
 */
class BarAdminPermissionProvider implements PermissionProviderInterface {

  use PermissionProviderTrait;

  /**
   * Constructs a new BarAdminPermissionProvider.
   *
   * @param \Drupal\group\Plugin\Group\RelationHandler\PermissionProviderInterface $parent
   *   The parent permission provider.
   */
  public function __construct(PermissionProviderInterface $parent) {
    $this->parent = $parent;
  }

  /**
   * {@inheritdoc}
   */
  public function getAdminPermission() {
    return $this->parent->getAdminPermission() . 'bar';
  }

}

Each handler will have a trait you can use that takes care of all parent method calls so that you only need to implement the methods you're actually adjusting the behavior of. You can find plenty of examples in the group, group_test_plugin and group_test_plugin_alter module, all under the path src/Plugin/Group/RelationHandler.

Footnote

As long as you only declare the handlers that do something extra, you will always get the latest updates automatically with new module releases. Same goes for newly introduced handlers.

Impacts: 
Site builders, administrators, editors
Module developers
Site templates, recipes and distribution developers