You are here

public function DomainElementManager::getFieldValues in Domain Access 8

Gets the domain entity reference field values from an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $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, keyed by id (machine_name) with value of the numeric domain_id used by node access.

Overrides DomainElementManagerInterface::getFieldValues

1 call to DomainElementManager::getFieldValues()
DomainElementManager::disallowedOptions in domain/src/DomainElementManager.php
Finds options not accessible to the current user.

File

domain/src/DomainElementManager.php, line 170

Class

DomainElementManager
Generic base class for handling hidden field options.

Namespace

Drupal\domain

Code

public function getFieldValues(EntityInterface $entity, $field_name) {

  // @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 = $this->domainStorage
          ->load($target['target_id'])) {
          $list[$domain
            ->id()] = $domain
            ->getDomainId();
        }
      }
    }
  }
  return $list;
}