You are here

public static function Contact::loadByMail in RedHen CRM 8

Load all Contact entities for a given email address.

Parameters

string $email: Required: an email address.

bool $status: RedHen status. Defaults to active.

Return value

array|bool An array of RedHen Contact entities or FALSE if no match found.

2 calls to Contact::loadByMail()
drush_redhen_contact_link_users in modules/redhen_contact/redhen_contact.drush.inc
Implements drush_hook_COMMAND().
redhen_contact_user_registration_validate in modules/redhen_contact/redhen_contact.module
User registration form RedHen Contact validation handler.

File

modules/redhen_contact/src/Entity/Contact.php, line 290

Class

Contact
Defines the Contact entity.

Namespace

Drupal\redhen_contact\Entity

Code

public static function loadByMail($email, $status = TRUE) {
  $contacts =& drupal_static(__FUNCTION__ . $email, FALSE);

  // If we don't have a cached Contact, try to find one with the given email.
  if (!$contacts) {
    $query = \Drupal::entityQuery('redhen_contact');
    $query
      ->condition('email', $email, '=');
    $query
      ->condition('status', $status);
    $results = $query
      ->execute();

    // If we find any Contacts with emails that match our request,
    // load and return them.
    if (!empty($results)) {
      $contacts = Contact::loadMultiple($results);
    }
  }
  return $contacts;
}