You are here

public function EventMeta::canRegisterProxyIdentities in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/EventMeta.php \Drupal\rng\EventMeta::canRegisterProxyIdentities()
  2. 8 src/EventMeta.php \Drupal\rng\EventMeta::canRegisterProxyIdentities()

Determine if the current user has proxy register access.

Includes whether the current user can create an identity.

Return value

bool Whether the current user can create an identity or reference at least one identity.

Overrides EventMetaInterface::canRegisterProxyIdentities

File

src/EventMeta.php, line 484

Class

EventMeta
Meta event wrapper for RNG.

Namespace

Drupal\rng

Code

public function canRegisterProxyIdentities() {

  // Create is checked first since it is usually the cheapest.
  $identity_types = $this
    ->getCreatableIdentityTypes();
  foreach ($identity_types as $entity_type_id => $bundles) {
    $accessControl = $this->entityManager
      ->getAccessControlHandler($entity_type_id);
    if ($this
      ->entityTypeHasBundles($entity_type_id)) {
      foreach ($bundles as $bundle) {
        if ($accessControl
          ->createAccess($bundle)) {
          return TRUE;
        }
      }
    }
    elseif (!empty($bundles)) {
      if ($accessControl
        ->createAccess()) {
        return TRUE;
      }
    }
  }

  // Reference existing.
  $identity_types = $this
    ->getIdentityTypes();
  foreach ($identity_types as $entity_type_id => $bundles) {
    $referencable_bundles = $this
      ->entityTypeHasBundles($entity_type_id) ? $bundles : [];
    $count = $this
      ->countRngReferenceableEntities($entity_type_id, $referencable_bundles);
    if ($count > 0) {
      return TRUE;
    }
  }
  return FALSE;
}