You are here

public function Subscription::getEmail in Mailing List 8

Get this subscription email address.

Parameters

bool $obfuscate: Obfuscate the email address by replacing some characters with '*'. Defaults to FALSE (do not obfuscate).

Return value

string The subscription email address.

Overrides SubscriptionInterface::getEmail

1 call to Subscription::getEmail()
Subscription::preSave in src/Entity/Subscription.php
Acts on an entity before the presave hook is invoked.

File

src/Entity/Subscription.php, line 169

Class

Subscription
Defines the subscription entity class.

Namespace

Drupal\mailing_list\Entity

Code

public function getEmail($obfuscate = FALSE) {
  $email = $this
    ->get('email')->value;
  if ($obfuscate) {
    $parts = explode('@', $email);

    // User.
    $u = $parts[0];

    // Domain.
    $d = $parts[1];

    // Domain first point.
    $dp = strpos($d, '.');
    $email = $u[0] . str_repeat('*', strlen($u) - 1) . '@' . $d[0] . str_repeat('*', $dp - 1) . substr($d, $dp);
  }
  return $email;
}