Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new method getCommentUrl for permanent comment URL #6892

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ HumHub Changelog
- Enh #6707: Uninstalling modules should be done in a background job
- Enh #25: Improve contrast of @default button color
- Fix #6889: Issue with modal boxes when positioning an element at the bottom of the screen
- Enh #6892: Implement new method `getCommentUrl` for comment permanent URL
14 changes: 12 additions & 2 deletions protected/humhub/modules/comment/controllers/PermaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use humhub\components\Controller;
use humhub\modules\comment\models\Comment;
use yii\web\BadRequestHttpException;
use yii\web\NotFoundHttpException;
use yii\web\Response;

Expand Down Expand Up @@ -36,15 +37,24 @@ public function actionIndex($id)
}

$content = $comment->content;
$record = $content->getPolymorphicRelation();

if ($record !== null && method_exists($record, 'getCommentUrl')) {
return $this->redirect($record->getCommentUrl($comment->id));
}

if ($content->container !== null) {
return $this->redirect($content->container->createUrl(null, [
'contentId' => $comment->content->id,
'commentId' => $comment->id,
]));
}
if (method_exists($content->getPolymorphicRelation(), 'getUrl')) {
return $this->redirect($content->getPolymorphicRelation()->getUrl());

if ($record !== null && method_exists($record, 'getUrl')) {
return $this->redirect($record->getUrl());
}

throw new BadRequestHttpException('Content has no URL for comments');
}

}