You are here

public function GroupContentEnablerBase::createAccess in Group 8

Performs access check for the create 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 content 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::createAccess

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 297

Class

GroupContentEnablerBase
Provides a base class for GroupContentEnabler plugins.

Namespace

Drupal\group\Plugin

Code

public function createAccess(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)
      ->relationCreateAccess($group, $account, TRUE);
  }

  // Backwards compatibility layer:
  // - Run the old code if there is no access control handler.
  $plugin_id = $this
    ->getPluginId();
  return GroupAccessResult::allowedIfHasGroupPermission($group, $account, "create {$plugin_id} content");
}