You are here

public static function Domain::preCreate in Domain Access 8

Changes the values of an entity before it is created.

Load defaults for example.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

mixed[] $values: An array of values to set, keyed by property name. If the entity type has bundles the bundle key has to be specified.

Overrides EntityBase::preCreate

File

domain/src/Entity/Domain.php, line 157

Class

Domain
Defines the domain entity.

Namespace

Drupal\domain\Entity

Code

public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
  parent::preCreate($storage_controller, $values);
  $domain_storage = \Drupal::entityTypeManager()
    ->getStorage('domain');
  $default = $domain_storage
    ->loadDefaultId();
  $count = $storage_controller
    ->getQuery()
    ->count()
    ->execute();
  $values += [
    'scheme' => empty($GLOBALS['is_https']) ? 'http' : 'https',
    'status' => 1,
    'weight' => $count + 1,
    'is_default' => (int) empty($default),
  ];

  // Note that we have not created a domain_id, which is only used for
  // node access control and will be added on save.
}