You are here

protected function SetUserCountry::doExecute in IP-based Determination of a Visitor's Country 8

Sets the country_iso_code_2 property of the global $user object.

Parameters

\Drupal\Core\Session\AccountInterface $account: User object.

string $country_code: A 2-character ISO 3166-2 country code.

File

src/Plugin/RulesAction/SetUserCountry.php, line 75

Class

SetUserCountry
Provides an 'Add a country_iso_code_2 to user data' action.

Namespace

Drupal\ip2country\Plugin\RulesAction

Code

protected function doExecute(AccountInterface $account, $country_code) {

  // Store the ISO country code in the $user object.
  $account = User::load($account
    ->id());
  $account->country_iso_code_2 = $country_code;
  $this->userData
    ->set('ip2country', $account
    ->id(), 'country_iso_code_2', $country_code);
}