You are here

public static function DomainAccessManager::getAccessValues in Domain Access 8

Get the domain access field values from an entity.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity to retrieve field data from.

string $field_name: The name of the field that holds our data.

Return value

array The domain access field values.

Overrides DomainAccessManagerInterface::getAccessValues

4 calls to DomainAccessManager::getAccessValues()
DomainAccessManager::checkEntityAccess in domain_access/src/DomainAccessManager.php
Compare the entity values against a user's account assignments.
DomainAccessManager::getContentUrls in domain_access/src/DomainAccessManager.php
Get all possible URLs pointing to an entity.
DomainAccessManager::getDefaultValue in domain_access/src/DomainAccessManager.php
Get the default field value for an entity.
DomainAccessManager::hasDomainPermissions in domain_access/src/DomainAccessManager.php
Checks that a user belongs to the domain and has a set of permissions.

File

domain_access/src/DomainAccessManager.php, line 69

Class

DomainAccessManager
Checks the access status of entities based on domain settings.

Namespace

Drupal\domain_access

Code

public static function getAccessValues(FieldableEntityInterface $entity, $field_name = DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD) {

  // @TODO: static cache.
  $list = [];

  // @TODO In tests, $entity is returning NULL.
  if (is_null($entity)) {
    return $list;
  }

  // Get the values of an entity.
  $values = $entity
    ->hasField($field_name) ? $entity
    ->get($field_name) : NULL;

  // Must be at least one item.
  if (!empty($values)) {
    foreach ($values as $item) {
      if ($target = $item
        ->getValue()) {
        if ($domain = \Drupal::entityTypeManager()
          ->getStorage('domain')
          ->load($target['target_id'])) {
          $list[$domain
            ->id()] = $domain
            ->getDomainId();
        }
      }
    }
  }
  return $list;
}