protected function MongodbUserStorage::entityToData in MongoDB 8
Add extra values from the entity to the data to be saved.
Parameters
ContentEntityInterface $entity:
array $data: Three keys:
- bundle: the entity bundle.
- translations: the list of entity languages
- values: the actual entity values
Overrides ContentEntityStorage::entityToData
File
- mongodb_user/
src/ MongodbUserStorage.php, line 46 - Definition of Drupal\mongodb_user\MongodbUserStorage.
Class
Namespace
Drupal\mongodb_userCode
protected function entityToData(ContentEntityInterface $account, &$data) {
/** @var \Drupal\user\UserInterface $account */
$definitions = $this->entityManager
->getFieldStorageDefinitions($this->entityTypeId);
$translation = $account
->getUntranslated();
foreach ($definitions as $field_name => $definition) {
if (count($definition
->getColumns()) == 1) {
$value = [];
foreach ($translation
->get($field_name) as $item) {
$item_value = $item
->getValue();
$value[] = reset($item_value);
}
if ($definition
->getCardinality() == 1) {
$value = reset($value);
}
$data['session'][$field_name] = $value;
}
}
}