Skip to content

Commit

Permalink
Merge pull request #12 from humhub/fix/10-wrong-answer-permalink
Browse files Browse the repository at this point in the history
Use absolute URL for answer permalink
  • Loading branch information
luke- authored Sep 18, 2023
2 parents f61e76f + 65ce925 commit 9b0d20a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.0.2 (Unreleased)
--------------------------
- Fix #10: Use absolute URL for answer permalink

1.0.1 (September 18, 2023)
--------------------------
- Fix #6: Fix error on delete a question
Expand Down
14 changes: 7 additions & 7 deletions helpers/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class Url extends BaseUrl
const ROUTE_ANSWER_SELECT_BEST = self::ROUTE_ANSWER . '/select-best';
const ROUTE_ANSWER_DELETE = self::ROUTE_ANSWER . '/delete';

private static function create($route, $params = [], ContentContainerActiveRecord $container = null)
private static function create($route, $params = [], ContentContainerActiveRecord $container = null, bool $scheme = false)
{
if ($container) {
return $container->createUrl($route, $params);
return $container->createUrl($route, $params, $scheme);
} else {
$params[0] = $route;
return static::to($params);
return static::to($params, $scheme);
}
}

Expand All @@ -45,7 +45,7 @@ public static function toContainerSettings(ContentContainerActiveRecord $contain
return $container->createUrl(static::ROUTE_SETTINGS);
}

public static function toViewQuestion(Question $question, array $params = []): string
public static function toViewQuestion(Question $question, array $params = [], bool $scheme = false): string
{
if (isset($params['#'])) {
$anchor = '#' . $params['#'];
Expand All @@ -56,7 +56,7 @@ public static function toViewQuestion(Question $question, array $params = []): s

return static::create(static::ROUTE_QUESTION_VIEW,
array_merge(['id' => $question->id], $params),
$question->content->container) . $anchor;
$question->content->container, $scheme) . $anchor;
}

public static function toEditQuestion(Question $question): string
Expand Down Expand Up @@ -84,9 +84,9 @@ public static function toContentAnswer(QuestionAnswer $answer): string
return static::create(static::ROUTE_ANSWER_CONTENT, ['id' => $answer->id], $answer->question->content->container);
}

public static function toViewAnswer(QuestionAnswer $answer): string
public static function toViewAnswer(QuestionAnswer $answer, bool $scheme = false): string
{
return self::toViewQuestion($answer->question, ['aid' => $answer->id, '#' => 'answer' . $answer->id]);
return self::toViewQuestion($answer->question, ['aid' => $answer->id, '#' => 'answer' . $answer->id], $scheme);
}

public static function toVoteUpAnswer(QuestionAnswer $answer): string
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Q&A",
"description": "Elevate your knowledge sharing experience by enabling users to ask questions and upvote the most helpful answers.",
"keywords": ["Q&A", "questions answers"],
"version": "1.0.1",
"version": "1.0.2",
"humhub": {
"minVersion": "1.14"
},
Expand Down
2 changes: 1 addition & 1 deletion widgets/AnswerControls.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private function initAnswerControls()
'url' => '#',
'htmlOptions' => [
'data-action-click' => 'content.permalink',
'data-content-permalink' => Url::toViewAnswer($this->answer),
'data-content-permalink' => Url::toViewAnswer($this->answer, true),
'data-content-permalink-title' => Yii::t('QuestionsModule.base', '<strong>Permalink</strong> to this answer'),
],
'sortOrder' => 100,
Expand Down

0 comments on commit 9b0d20a

Please sign in to comment.