You are here

function adsense_revenue_sharing_basic_get_profile_client_id in Google AdSense integration 8

Provide the Publisher ID of the the specified user.

Parameters

int $uid: User ID.

Return value

string|null Publisher ID of the specified user in case it applies, otherwise NULL.

1 call to adsense_revenue_sharing_basic_get_profile_client_id()
adsense_revenue_sharing_basic_choose_client in oldcode/revenue_sharing_basic/adsense_revenue_sharing_basic.module
Provide the applicable Publisher ID, based on the configured probabilities.

File

oldcode/revenue_sharing_basic/adsense_revenue_sharing_basic.module, line 125
Main file of the adsense_revenue_sharing_basic module.

Code

function adsense_revenue_sharing_basic_get_profile_client_id($uid) {
  $client_id = NULL;
  $config = Drupal::config('adsense_revenue_sharing_basic.settings');

  // Get the profile field for a certain user.
  $profile_field = explode(':', $config
    ->get('client_id_profile_field'));
  if ($uid && count($profile_field) > 1) {

    /** @var \Drupal\user\Entity\User $user */
    $user = User::load($uid);
    switch ($profile_field[0]) {
      case 'field':
        $client_id = $user
          ->get($profile_field[1])
          ->getString();
        break;
      case 'profile':

        // @todo adapt this to the profile module.

        /* @codingStandardsIgnoreStart
           $client_id = isset($user->{$profile_field[1]}) ? $user->{$profile_field[1]} : NULL;
           @codingStandardsIgnoreEnd */
        break;
    }
  }
  return $client_id;
}