You are here

public function ImportUserData::onImportUserData in Acquia Content Hub 8.2

Imports User Data.

Parameters

\Drupal\acquia_contenthub\Event\EntityImportEvent $event: Event object.

File

src/EventSubscriber/EntityImport/ImportUserData.php, line 52

Class

ImportUserData
Imports user data.

Namespace

Drupal\acquia_contenthub\EventSubscriber\EntityImport

Code

public function onImportUserData(EntityImportEvent $event) {
  $entity = $event
    ->getEntity();
  if ('user' !== $entity
    ->getEntityTypeId()) {
    return;
  }
  $cdf = $event
    ->getEntityData();
  $metadata = $cdf
    ->getMetadata();
  if (!isset($metadata['user_data'])) {
    return;
  }
  $uid = $entity
    ->id();

  // Delete all current User Data.
  $this->userData
    ->delete(NULL, $uid);

  // Import actual User Data.
  foreach ($metadata['user_data'] as $module => $data) {
    foreach ($data as $key => $value) {
      $this->userData
        ->set($module, $uid, $key, $value);
    }
  }
}