[COMPONENTS][Posting][Link][Tag] Pass the note, not just the id in ProcessNoteContent
This commit is contained in:
parent
7926f18f93
commit
2f3f7b8469
@ -25,6 +25,7 @@ use App\Core\DB\DB;
|
||||
use App\Core\Event;
|
||||
use App\Core\Modules\Component;
|
||||
use App\Entity;
|
||||
use App\Entity\Note;
|
||||
use App\Entity\NoteToLink;
|
||||
use App\Util\Common;
|
||||
use App\Util\HTML;
|
||||
@ -35,7 +36,7 @@ class Link extends Component
|
||||
/**
|
||||
* Extract URLs from $content and create the appropriate Link and NoteToLink entities
|
||||
*/
|
||||
public function onProcessNoteContent(int $note_id, string $content)
|
||||
public function onProcessNoteContent(Note $note, string $content)
|
||||
{
|
||||
if (Common::config('attachments', 'process_links')) {
|
||||
$matched_urls = [];
|
||||
@ -44,7 +45,7 @@ class Link extends Component
|
||||
foreach ($matched_urls as $match) {
|
||||
try {
|
||||
$link_id = Entity\Link::getOrCreate($match)->getId();
|
||||
DB::persist(NoteToLink::create(['link_id' => $link_id, 'note_id' => $note_id]));
|
||||
DB::persist(NoteToLink::create(['link_id' => $link_id, 'note_id' => $note->getId()]));
|
||||
} catch (InvalidArgumentException) {
|
||||
continue;
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ class Posting extends Component
|
||||
DB::persist($note);
|
||||
|
||||
// Need file and note ids for the next step
|
||||
Event::handle('ProcessNoteContent', [$note->getId(), $content, $content_type]);
|
||||
Event::handle('ProcessNoteContent', [$note, $content, $content_type]);
|
||||
DB::flush();
|
||||
|
||||
if ($processed_attachments != []) {
|
||||
|
@ -21,10 +21,12 @@
|
||||
|
||||
namespace Component\Tag;
|
||||
|
||||
use App\Core\Cache;
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Event;
|
||||
use App\Core\Modules\Component;
|
||||
use App\Core\Router\Router;
|
||||
use App\Entity\Note;
|
||||
use App\Entity\NoteTag;
|
||||
use App\Util\Formatting;
|
||||
use App\Util\HTML;
|
||||
@ -51,14 +53,16 @@ class Tag extends Component
|
||||
/**
|
||||
* Process note by extracting any tags present
|
||||
*/
|
||||
public function onProcessNoteContent(int $note_id, string $content)
|
||||
public function onProcessNoteContent(Note $note, string $content)
|
||||
{
|
||||
$matched_tags = [];
|
||||
$processed_tags = false;
|
||||
preg_match_all(self::TAG_REGEX, $content, $matched_tags, PREG_SET_ORDER);
|
||||
foreach ($matched_tags as $match) {
|
||||
$tag = $match[2];
|
||||
DB::persist(NoteTag::create(['tag' => $tag, 'canonical' => $this->canonicalTag($tag), 'note_id' => $note_id]));
|
||||
$canonical_tag = self::canonicalTag($tag);
|
||||
DB::persist(NoteTag::create(['tag' => $tag, 'canonical' => $canonical_tag, 'note_id' => $note->getId()]));
|
||||
Cache::pushList("tag-{$canonical_tag}", $note);
|
||||
$processed_tags = true;
|
||||
}
|
||||
if ($processed_tags) {
|
||||
@ -73,12 +77,12 @@ class Tag extends Component
|
||||
|
||||
private function tagLink(string $tag): string
|
||||
{
|
||||
$canonical = $this->canonicalTag($tag);
|
||||
$canonical = self::canonicalTag($tag);
|
||||
$url = Router::url('tag', ['tag' => $canonical]);
|
||||
return HTML::html(['a' => ['attrs' => ['href' => $url, 'title' => $tag, 'rel' => 'tag'], $tag]], options: ['indent' => false]);
|
||||
}
|
||||
|
||||
public function canonicalTag(string $tag): string
|
||||
public static function canonicalTag(string $tag): string
|
||||
{
|
||||
return substr(Formatting::slugify($tag), 0, self::MAX_TAG_LENGTH);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user