You are here

public function GroupContentEnablerBase::createEntityAccess in Group 8

Performs access check for the create target entity operation.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

\Drupal\group\Entity\GroupInterface $group: The group to check for target entity creation access.

\Drupal\Core\Session\AccountInterface $account: The user for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides GroupContentEnablerInterface::createEntityAccess

Deprecated

in Group 1.0, will be removed before Group 2.0. Retrieve the access handler from the plugin manager instead.

File

src/Plugin/GroupContentEnablerBase.php, line 273

Class

GroupContentEnablerBase
Provides a base class for GroupContentEnabler plugins.

Namespace

Drupal\group\Plugin

Code

public function createEntityAccess(GroupInterface $group, AccountInterface $account) {

  /** @var \Drupal\group\Plugin\GroupContentEnablerManagerInterface $manager */
  $manager = \Drupal::service('plugin.manager.group_content_enabler');

  // Backwards compatibility layer:
  // - Use the declared access control handler if available.
  if ($manager
    ->hasHandler($this->pluginId, 'access')) {
    return $manager
      ->getAccessControlHandler($this->pluginId)
      ->entityCreateAccess($group, $account, TRUE);
  }

  // Backwards compatibility layer:
  // - Run the old code if there is no access control handler.
  // You cannot create target entities if the plugin does not support it.
  if (!$this
    ->definesEntityAccess()) {
    return AccessResult::neutral();
  }
  $plugin_id = $this
    ->getPluginId();
  return GroupAccessResult::allowedIfHasGroupPermission($group, $account, "create {$plugin_id} entity");
}