I've taken some time to fiddle with the code in FrontendUsersProfileController.php and found that a bug seems to be in the record creation bit. I have rewritten my getUserRecord() function as follows:
private function getUserRecord(ContentType $contentType): Content
{
/** @var User $user */
$user = $this->getUser();
// access record if available
$contentTypeSlug = $this->getExtension()->getExtConfig('contenttype', $user->getRoles()[0]);
$contentType = $this->getBoltConfig()->getContentType($contentTypeSlug);
$content = $this->contentRepository->findBy([
'author' => $user,
'contentType' => $contentType->getSlug(),
]);
// bug in record creation bit
if (empty($content)) {
$content = new Content($contentType);
$content->setAuthor($user);
$content->setPublishedAt(new \DateTime());
$content->setStatus(Statuses::PUBLISHED);
$contentTypeName = strtolower($contentType->get('name', $contentType->get('slug')));
$content->setContentType($contentTypeName);
$this->contentFillListener->fillContent($content);
} elseif (is_iterable($content)) {
$content = end($content);
}
return $content;
}
I have found that when I manually create a Member record, rewriting the $content definition as follows fetches content as expected, thereby rendering a profile page.
Adding back the author filter throws an error because $content is empty, indicating that the block of code is working as expected. However, if $content is empty, we are supposed to add the respective user record, but that doesn't happen. I believe the issue is in this bit of the code:
I have tried working on a function to generate the record during user registration, but I've been swimming in exceptions. I have also tried using a standalone record creation function in FrontendUsersProfileController.php as follows...
Dumping $content outputs the following, but the record is never created, even though it seems as though the new Content() function is working.
The implication is that the /profile route throws an error that the content requested cannot be found (see screenshot 1 below), and the edit fields in /profile/edit are not generated because there is no record to edit (see screenshot 2 below).
This is related to Issue #7 and PR #8.
I've taken some time to fiddle with the code in
FrontendUsersProfileController.php
and found that a bug seems to be in the record creation bit. I have rewritten mygetUserRecord()
function as follows:I have found that when I manually create a Member record, rewriting the $content definition as follows fetches content as expected, thereby rendering a profile page.
Adding back the author filter throws an error because
$content
is empty, indicating that the block of code is working as expected. However, if$content
is empty, we are supposed to add the respective user record, but that doesn't happen. I believe the issue is in this bit of the code:I have tried working on a function to generate the record during user registration, but I've been swimming in exceptions. I have also tried using a standalone record creation function in
FrontendUsersProfileController.php
as follows......called from of the
getUserRecord()
function as follows:Dumping
$content
outputs the following, but the record is never created, even though it seems as though thenew Content()
function is working.The implication is that the
/profile
route throws an error that the content requested cannot be found (see screenshot 1 below), and the edit fields in/profile/edit
are not generated because there is no record to edit (see screenshot 2 below).Any help will be greatly appreciated. Thanks!