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

Use absolute URL for answer permalink #12

Merged
merged 1 commit into from
Sep 18, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading