You are here

public static function Contact::preCreate in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/content_entity_example/src/Entity/Contact.php \Drupal\content_entity_example\Entity\Contact::preCreate()

When a new entity instance is added, set the user_id entity reference to the current user as the creator of the instance.

Overrides EntityBase::preCreate

File

content_entity_example/src/Entity/Contact.php, line 148

Class

Contact
Defines the ContentEntityExample entity.

Namespace

Drupal\content_entity_example\Entity

Code

public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
  parent::preCreate($storage_controller, $values);
  $values += [
    'user_id' => \Drupal::currentUser()
      ->id(),
  ];
}