You are here

public static function PushNotificationsToken::preCreate in Push Notifications 8

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

Overrides EntityBase::preCreate

File

src/Entity/PushNotificationsToken.php, line 54
Contains \Drupal\push_notifications\Entity\PushNotificationsToken.

Class

PushNotificationsToken
Defines the token entity.

Namespace

Drupal\push_notifications\Entity

Code

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

  // Set a default language if no language is passed.
  if (!array_key_exists('langcode', $values)) {
    $values += array(
      'langcode' => \Drupal::languageManager()
        ->getCurrentLanguage()
        ->getId(),
    );
  }
}