Skip to content

Commit 81bcdad

Browse files
authored
docs(dataproducter): Add how to resolve user properties to docs (#1292)
1 parent 92d8682 commit 81bcdad

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

doc/producers/custom.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,15 @@ we get a result like this :
136136
}
137137
```
138138

139-
(For this to actually work we would need to add resolvers to the User object to resolve the `id` and `name` properties).
139+
For this to actually work we would need to add resolvers to the User object to resolve the `id` and `name` properties like so:
140+
```php
141+
$registry->addFieldResolver('User', 'id', $builder->callback(function ($account) {
142+
/** @var \Drupal\Core\Session\AccountProxyInterface $account */
143+
return $account->id();
144+
}));
145+
146+
$registry->addFieldResolver('User', 'name', $builder->callback(function ($account) {
147+
/** @var \Drupal\Core\Session\AccountProxyInterface $account */
148+
return $account->getAccountName();
149+
}));
150+
```

0 commit comments

Comments
 (0)