It’s a while ago, that you posted this thread, but I answered a similar question, I came across your question and I fiddled a bit.
I f you want to populate the name in an api request, have a look here:
If you want to display the name only in entries view /collections/entries/collection_name
, this might work in /config/boostrap.php
:
if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) {
// only on collections Admin controller
$app->on('app.collections.controller.admin.init', function() {
// only after collection "test2" was found
$this->on('collections.find.after.test2', function($name, &$entries) {
// ajax request in entries view
// didn't test with all possible edge cases...
if ($this['route'] == '/collections/find') {
foreach ($entries as &$entry) {
if (isset($entry['account'])) {
$account = $this->storage->findOne('cockpit/accounts', ['_id' => $entry['account']]);
$entry['account'] = !empty($account['name']) ? $account['name'] : $account['user'];
}
}
}
});
});
}