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

parseInternalLinks corrections for double digit ids #2338

Merged
merged 5 commits into from
Jan 24, 2024
Merged
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
12 changes: 11 additions & 1 deletion src/TwillUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace A17\Twill;

use A17\Twill\Models\Contracts\TwillLinkableModel;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Session;

/**
Expand Down Expand Up @@ -57,13 +58,22 @@ public function clearTempStore(): void
public function parseInternalLinks(string $content): string
{
return preg_replace_callback(
'/(#twillInternalLink::(.*)#(\d))/',
'/(#twillInternalLink::(.*?)#(\d+))/',
function (array $data) {
if (isset($data[2], $data[3])) {
$modelClass = $data[2];
$id = $data[3];

if (array_key_exists($modelClass, Relation::morphMap())) {
$modelClass = Relation::morphMap()[$modelClass];
}

$model = $modelClass::published()->where('id', $id)->first();

if (!$model) {
return url('404');
}

if ($model instanceof TwillLinkableModel) {
return $model->getFullUrl();
}
Expand Down
Loading