You are here

public function Subscriber::fillFromAccount in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 src/Entity/Subscriber.php \Drupal\simplenews\Entity\Subscriber::fillFromAccount()
  2. 8 src/Entity/Subscriber.php \Drupal\simplenews\Entity\Subscriber::fillFromAccount()

Fill values from a user account.

Parameters

\Drupal\Core\Session\AccountInterface $account: The account to fill from.

Return value

$this

Overrides SubscriberInterface::fillFromAccount

2 calls to Subscriber::fillFromAccount()
Subscriber::postCreate in src/Entity/Subscriber.php
Acts on a created entity before hooks are invoked.
Subscriber::preSave in src/Entity/Subscriber.php
Acts on an entity before the presave hook is invoked.

File

src/Entity/Subscriber.php, line 141

Class

Subscriber
Defines the simplenews subscriber entity.

Namespace

Drupal\simplenews\Entity

Code

public function fillFromAccount(AccountInterface $account) {
  if (static::$syncing) {
    return $this;
  }
  static::$syncing = TRUE;
  $this
    ->set('uid', $account
    ->id());
  $this
    ->setMail($account
    ->getEmail());
  $this
    ->setLangcode($account
    ->getPreferredLangcode());
  $this
    ->setStatus($account
    ->isActive());

  // Copy values for shared fields to existing subscriber.
  foreach ($this
    ->getUserSharedFields($account) as $field_name) {
    $this
      ->set($field_name, $account
      ->get($field_name)
      ->getValue());
  }
  static::$syncing = FALSE;
  return $this;
}