You are here

public static function GroupContentPermissionProvider::createInstance in Group 8

Instantiates a new instance of this group content handler.

This is a factory method that returns a new instance of this object. The factory should pass any needed dependencies into the constructor of this object, but not the container itself. Every call to this method must return a new instance of this object; that is, it may not implement a singleton.

@todo Replace the definition array with a class-based approach like the one entity types use.

@internal Marked as internal because the plugin definitions will become classes in a future release to further mimic the entity type system. Try to extend the base handlers shipped with this module. If not, you'll need to update your implementations when 2.0 lands.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The service container this object should use.

string $plugin_id: The ID of the plugin the handler is for. This will contain the derivative ID when present, whereas the definition will contain only the base ID.

array $definition: The group content enabler definition.

Return value

static A new instance of the group content handler.

Overrides GroupContentHandlerBase::createInstance

1 call to GroupContentPermissionProvider::createInstance()
GroupContentPermissionProviderTest::createPermissionProvider in tests/src/Unit/GroupContentPermissionProviderTest.php
Instantiates a default permission provider handler.

File

src/Plugin/GroupContentPermissionProvider.php, line 46

Class

GroupContentPermissionProvider
Provides group permissions for GroupContent entities.

Namespace

Drupal\group\Plugin

Code

public static function createInstance(ContainerInterface $container, $plugin_id, array $definition) {

  /** @var EntityTypeManagerInterface $entity_type_manager */
  $entity_type_manager = $container
    ->get('entity_type.manager');
  $entity_type = $entity_type_manager
    ->getDefinition($definition['entity_type_id']);

  /** @var static $instance */
  $instance = parent::createInstance($container, $plugin_id, $definition);
  $instance->entityType = $entity_type;
  $instance->implementsOwnerInterface = $entity_type
    ->entityClassImplements(EntityOwnerInterface::class);
  $instance->implementsPublishedInterface = $entity_type
    ->entityClassImplements(EntityPublishedInterface::class);
  $instance->definesEntityPermissions = !empty($definition['entity_access']);
  return $instance;
}