Skip to content

Commit

Permalink
Merge pull request #18 from jurjenvn/patch-1
Browse files Browse the repository at this point in the history
Auto add fields from Content Type in method New
  • Loading branch information
I-Valchev authored Apr 16, 2021
2 parents 85ea949 + a5b7f70 commit 25d057c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Controller/FrontendUsersProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,17 @@ private function new(ContentType $contentType): Content
$content->setContentType($contentTypeName);
$content->setFieldValue('displayName', $user->getDisplayName()); // Hidden field for record title
$content->setFieldValue('username', $user->getUsername()); // Hidden field with copy of username
$content->setFieldValue('slug', $user->getUsername()); // Make slugs unique to users

// Initialise ALL extra fields as defined in the contenttype with empty strings.
// This ensures they are displayed on the /profile/edit route without backend intervention
$content->setFieldValue('dob', '');
foreach($contentType->get('fields') as $name => $field){

$content->setFieldValue('slug', $user->getUsername()); // Make slugs unique to users
if(!in_array($name, ['displayName','username','slug'])) {
$content->setFieldValue($name, '');
}
}

$this->contentFillListener->fillContent($content);

// Persist in DB
Expand Down

0 comments on commit 25d057c

Please sign in to comment.