Closed I-Valchev closed 3 years ago
Thank you @I-Valchev and @bobdenotter. That seems to have worked partially. The /profile/edit
page is now accessible, but the /profile
page throws a 404: Content is not viewable
error as shown below.
Am I supposed to point the extension to a Profile view page as well?
I assume when a new user registers, the respective record is supposed to be created with default Published status and the user tagged as Author? If so, this is not happening as expected, which perhaps may be the cause of the 404 error above?
hmm... @crim3hound can you check if the record is created in the backend? What do you see there? Is the ContentType viewless
maybe?
@I-Valchev no record is created in the backend as shown below. I've tried multiple times registering users but nothing happens.
I set the ContentType as viewless
as per the demonstration, and that did not work. Let me omit the flag and see if it helps.
@I-Valchev removing the viewless
flag does not make a difference. I'm stumped.
thanks for the info @crim3hound , I'll look into it and see if I can find why it's not working as it should :-)
Thank you @I-Valchev. I appreciate all the work you're doing on this.
hi @crim3hound , you actually pointed out the issue earlier in your description :-)
The user contenttype record is missing. It is not created by default, hence why you cannot view the content on the /profile
page.
Also, there's a little bug between how the extension works and what Bolt sees as a "missing" record, which is why it says that the content is viewless rather than missing.
As far as I can see, there are two possible solutions:
/profile
page, if a record does not exist, do something. Something can be show a proper 404, perhaps...Option 1 seems a little more appropriate, I think.
Hi @I-Valchev and @bobdenotter. I've taken some time to fiddle with the code in FrontendUsersProfileController.php
and found that the 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.
$content = $this->contentRepository->findBy([
'contentType' => $contentType->getSlug(),
]);
Adding back the author
filter throws an error because $content
is empty, indicating that the block of code is working as expected. However, if empty, we are supposed to add the respective record, but that doesn't seem to be happening as expected. So I believe the issue is in this bit of the code:
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;
Not sure if you're in any position to assist? I have tried working on a function to generate the record during user registration, but I've been swimming in exceptions. Any help will be highly appreciated. Thanks!
@crim3hound thanks for the bug report, this PR should fix the issue.