public function ExportUserData::onCreateCdf in Acquia Content Hub 8.2
Serializes User Data.
Parameters
\Drupal\acquia_contenthub\Event\CreateCdfEntityEvent $event: Event object.
File
- src/
EventSubscriber/ Cdf/ ExportUserData.php, line 60
Class
- ExportUserData
- Exports user data.
Namespace
Drupal\acquia_contenthub\EventSubscriber\CdfCode
public function onCreateCdf(CreateCdfEntityEvent $event) {
$entity = $event
->getEntity();
if ('user' !== $entity
->getEntityTypeId()) {
return;
}
$cdf = $event
->getCdf($entity
->uuid());
$metadata = $cdf
->getMetadata();
$metadata['user_data'] = [];
/** @var \Drupal\Core\Database\Query\Select $query */
$query = $this->database
->select('users_data', 'ud')
->fields('ud', [
'module',
])
->condition('uid', $entity
->id());
$modules = $query
->execute()
->fetchCol();
if (!$modules) {
$cdf
->setMetadata($metadata);
return;
}
foreach ($modules as $module) {
$metadata['user_data'][$module] = $this->userData
->get($module, $entity
->id());
}
$cdf
->setMetadata($metadata);
}