Skip to content

Commit

Permalink
Invalidate source tag if discussion does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
n-peugnet committed Jan 11, 2023
1 parent e6b9476 commit 294ec30
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ club-1-cross-references:
forum:
post_stream:
discussion_referenced_text: '{username} referenced this discussion from {source}'
unknown_discussion: 'Unknown discussion'
discussion_title: 'Discussion title'
unknown_discussion: '<UNKNOWN DISCUSSION>'
discussion_title: '<DISCUSSION TITLE>'
comment: 'comment'
4 changes: 2 additions & 2 deletions locale/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ club-1-cross-references:
forum:
post_stream:
discussion_referenced_text: '{username} a référencé cette discussion depuis {source}'
unknown_discussion: 'Discussion inconnue'
discussion_title: 'Titre de la discussion'
unknown_discussion: '<DISCUSSION INCONNUE>'
discussion_title: '<TITRE DE LA DISCUSSION>'
comment: 'commentaire'
9 changes: 8 additions & 1 deletion src/Formatter/CrossReferencesConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Club1\CrossReferences\Formatter;

use Flarum\Discussion\Discussion;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
use s9e\TextFormatter\Configurator;
Expand Down Expand Up @@ -65,9 +66,15 @@ public function __invoke(Configurator $config)

public static function filterCrossReferences(Tag $tag)
{
/** @var Discussion|null */
$d = Discussion::find($tag->getAttribute('id'));
if (is_null($d)) {
$tag->invalidate();
return false;
}
// Set placeholder values for TextFormatter to be happy.
// The real values is set during render.
$tag->setAttribute('title', '');
$tag->setAttribute('title', $d->title);
$tag->setAttribute('comment', '');
return true;
}
Expand Down

0 comments on commit 294ec30

Please sign in to comment.