public static function Subscriber::loadByMail in Simplenews 3.x
Same name and namespace in other branches
- 8.2 src/Entity/Subscriber.php \Drupal\simplenews\Entity\Subscriber::loadByMail()
Load a simplenews newsletter subscriber object by mail.
Parameters
string $mail: Subscriber e-mail address.
bool $create: (optional) Whether to create a new subscriber if none exists. Defaults to TRUE.
string $default_langcode: (optional) Langcode to set if a new subscriber is created.
Return value
\Drupal\simplenews\SubscriberInterface Newsletter subscriber entity, FALSE if subscriber does not exist.
Overrides SubscriberInterface::loadByMail
22 calls to Subscriber::loadByMail()
- Mailer::sendTest in src/
Mail/ Mailer.php - Send test version of newsletter.
- SimplenewsAdministrationTest::testNewsletterSettings in tests/
src/ Functional/ SimplenewsAdministrationTest.php - Test various combinations of newsletter settings.
- SimplenewsAdministrationTest::testSubscriptionManagement in tests/
src/ Functional/ SimplenewsAdministrationTest.php - Test newsletter subscription management.
- SimplenewsSourceTest::testSendMissingSubscriber in tests/
src/ Functional/ SimplenewsSourceTest.php - Test sending when there are no subscribers.
- SimplenewsSubscribeTest::testAdminCreate in tests/
src/ Functional/ SimplenewsSubscribeTest.php - Tests admin creating a single subscriber.
File
- src/
Entity/ Subscriber.php, line 417
Class
- Subscriber
- Defines the simplenews subscriber entity.
Namespace
Drupal\simplenews\EntityCode
public static function loadByMail($mail, $create = FALSE, $default_langcode = NULL) {
$subscriber = FALSE;
if ($mail) {
$subscribers = \Drupal::entityTypeManager()
->getStorage('simplenews_subscriber')
->loadByProperties([
'mail' => $mail,
]);
$subscriber = reset($subscribers);
}
if ($create && !$subscriber) {
$subscriber = static::create([
'mail' => $mail,
]);
if ($default_langcode) {
$subscriber
->setLangcode($default_langcode);
}
}
return $subscriber;
}