You are here

public static function DomainAccessManager::getDefaultValue in Domain Access 8

Get the default field value for an entity.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity being created.

\Drupal\Core\Field\FieldDefinitionInterface $definition: The field being created.

Return value

array The default field value(s).

Overrides DomainAccessManagerInterface::getDefaultValue

File

domain_access/src/DomainAccessManager.php, line 114

Class

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

Namespace

Drupal\domain_access

Code

public static function getDefaultValue(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
  $item = [];
  if (!$entity
    ->isNew()) {

    // If set, ensure we do not drop existing data.
    foreach (self::getAccessValues($entity) as $id) {
      $item[] = $id;
    }
  }
  elseif ($entity
    ->getFieldDefinition(DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD)
    ->isRequired()) {

    /** @var \Drupal\domain\DomainInterface $active */
    if ($active = \Drupal::service('domain.negotiator')
      ->getActiveDomain()) {
      $item[0]['target_uuid'] = $active
        ->uuid();
    }
  }
  return $item;
}