You are here

private function TokenProcessor::fetchRegularFieldToken in Lightweight Directory Access Protocol (LDAP) 8.3

Fetch regular field token.

Parameters

\Drupal\user\UserInterface $account: User.

string $attribute_name: Field name.

Return value

string Field data.

1 call to TokenProcessor::fetchRegularFieldToken()
TokenProcessor::fetchSingleToken in ldap_servers/src/Processor/TokenProcessor.php
Fetch a single token.

File

ldap_servers/src/Processor/TokenProcessor.php, line 318

Class

TokenProcessor
Helper to manage LDAP tokens and process their content.

Namespace

Drupal\ldap_servers\Processor

Code

private function fetchRegularFieldToken(UserInterface $account, $attribute_name) {
  $value = '';
  if (is_scalar($account
    ->get($attribute_name)->value)) {
    $value = $account
      ->get($attribute_name)->value;
  }
  elseif (!empty($account
    ->get($attribute_name)
    ->getValue())) {
    $file_reference = $account
      ->get($attribute_name)
      ->getValue();
    if (isset($file_reference[0]['target_id'])) {
      $file = file_load($file_reference[0]['target_id']);
      if ($file) {
        $value = file_get_contents($this->fileSystem
          ->realpath($file
          ->getFileUri()));
      }
    }
  }
  return $value;
}