Skip to content

Commit c2ebba4

Browse files
chore: Improve setting the link sources
1 parent e8476f1 commit c2ebba4

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/controllers/links/Collections.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function update(Request $request): Response
107107

108108
if (!auth\LinksAccess::canUpdate($user, $link)) {
109109
$link = $user->obtainLink($link);
110-
utils\SourceHelper::setLinkSource($link, $from);
110+
$link->setSourceFrom($from);
111111
}
112112

113113
$form = new forms\links\EditLinkCollections(model: $link);

src/controllers/links/Read.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function create(Request $request): Response
5555

5656
$link = $user->obtainLink($link);
5757
if (!$link->isPersisted()) {
58-
utils\SourceHelper::setLinkSource($link, $from);
58+
$link->setSourceFrom($from);
5959
$link->save();
6060
}
6161

@@ -103,7 +103,7 @@ public function later(Request $request): Response
103103

104104
$link = $user->obtainLink($link);
105105
if (!$link->isPersisted()) {
106-
utils\SourceHelper::setLinkSource($link, $from);
106+
$link->setSourceFrom($from);
107107
$link->save();
108108
}
109109

src/models/Link.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,18 @@ public function source(): User|Collection|null
353353
}
354354
}
355355

356+
/**
357+
* Set the source properties of the link if "from" is a supported internal path.
358+
*/
359+
public function setSourceFrom(string $from): void
360+
{
361+
list($source_type, $source_resource_id) = utils\SourceHelper::extractFromPath($from);
362+
if ($source_type) {
363+
$this->source_type = $source_type;
364+
$this->source_resource_id = $source_resource_id;
365+
}
366+
}
367+
356368
/**
357369
* Return whether or not the given user has the link URL in its bookmarks.
358370
*/

src/utils/SourceHelper.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@
1010
*/
1111
class SourceHelper
1212
{
13-
/**
14-
* Set the source_* properties of a link if possible.
15-
*/
16-
public static function setLinkSource(models\Link $link, string $from): void
17-
{
18-
list($source_type, $source_resource_id) = self::extractFromPath($from);
19-
if ($source_type) {
20-
$link->source_type = $source_type;
21-
$link->source_resource_id = $source_resource_id;
22-
}
23-
}
24-
2513
/**
2614
* Return the source type and resource id from a path.
2715
*

0 commit comments

Comments
 (0)