You are here

public static function GroupContentAccessControlHandler::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

5 calls to GroupContentAccessControlHandler::createInstance()
GroupContentAccessControlHandlerTest::testCreateInstanceException in tests/src/Unit/GroupContentAccessControlHandlerTest.php
Tests the exception thrown when there is no permission provider.
GroupContentAccessControlHandlerTest::testEntityAccess in tests/src/Unit/GroupContentAccessControlHandlerTest.php
Tests the entity operation access.
GroupContentAccessControlHandlerTest::testEntityCreateAccess in tests/src/Unit/GroupContentAccessControlHandlerTest.php
Tests the entity create access.
GroupContentAccessControlHandlerTest::testRelationAccess in tests/src/Unit/GroupContentAccessControlHandlerTest.php
Tests the relation operation access.
GroupContentAccessControlHandlerTest::testRelationCreateAccess in tests/src/Unit/GroupContentAccessControlHandlerTest.php
Tests the relation create access.

File

src/Plugin/GroupContentAccessControlHandler.php, line 37

Class

GroupContentAccessControlHandler
Provides access control for GroupContent entities and grouped entities.

Namespace

Drupal\group\Plugin

Code

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

  /** @var \Drupal\group\Plugin\GroupContentEnablerManagerInterface $manager */
  $manager = $container
    ->get('plugin.manager.group_content_enabler');
  if (!$manager
    ->hasHandler($plugin_id, 'permission_provider')) {
    throw new \LogicException('Cannot use an "access" handler without a "permission_provider" handler.');
  }

  /** @var static $instance */
  $instance = parent::createInstance($container, $plugin_id, $definition);
  $instance->permissionProvider = $manager
    ->getPermissionProvider($plugin_id);
  $instance->entityTypeManager = $container
    ->get('entity_type.manager');
  return $instance;
}