You are here

private function DrupalUserProcessor::userPictureFromLdapEntry in Lightweight Directory Access Protocol (LDAP) 8.3

Same name and namespace in other branches
  1. 8.4 ldap_user/src/Processor/DrupalUserProcessor.php \Drupal\ldap_user\Processor\DrupalUserProcessor::userPictureFromLdapEntry()

Process user picture from LDAP entry.

Parameters

array $ldap_entry: The LDAP entry.

Return value

bool|\Drupal\file\Entity\File Drupal file object image user's thumbnail or FALSE if none present or an error occurs.

1 call to DrupalUserProcessor::userPictureFromLdapEntry()
DrupalUserProcessor::setLdapBaseFields in ldap_user/src/Processor/DrupalUserProcessor.php
Sets the fields required by LDAP.

File

ldap_user/src/Processor/DrupalUserProcessor.php, line 710

Class

DrupalUserProcessor
Handles processing of a user from LDAP to Drupal.

Namespace

Drupal\ldap_user\Processor

Code

private function userPictureFromLdapEntry(array $ldap_entry) {
  if ($ldap_entry && $this->server
    ->get('picture_attr')) {

    // Check if LDAP entry has been provisioned.
    if (isset($ldap_entry[$this->server
      ->get('picture_attr')][0])) {
      $ldapUserPicture = $ldap_entry[$this->server
        ->get('picture_attr')][0];
    }
    else {

      // No picture present.
      return FALSE;
    }

    // @TODO 2914053.
    if (!$this->account || $this->account
      ->isAnonymous() || $this->account
      ->id() == 1) {
      return FALSE;
    }
    $currentUserPicture = $this->account
      ->get('user_picture')
      ->getValue();
    if (empty($currentUserPicture)) {
      return $this
        ->saveUserPicture($this->account
        ->get('user_picture'), $ldapUserPicture);
    }
    else {
      $file = File::load($currentUserPicture[0]['target_id']);
      if ($file && md5(file_get_contents($file
        ->getFileUri())) == md5($ldapUserPicture)) {

        // Same image, do nothing.
        return FALSE;
      }
      else {
        return $this
          ->saveUserPicture($this->account
          ->get('user_picture'), $ldapUserPicture);
      }
    }
  }
}