From 1347867281a85c1057a94645d2f6764e584262f9 Mon Sep 17 00:00:00 2001 From: edalzell Date: Wed, 8 Oct 2025 15:37:07 -0700 Subject: [PATCH 01/10] Use permalink so it works when the site is in a diff domain --- src/Fieldtypes/Bard/LinkMark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fieldtypes/Bard/LinkMark.php b/src/Fieldtypes/Bard/LinkMark.php index 727ecce2703..c19dfc02687 100644 --- a/src/Fieldtypes/Bard/LinkMark.php +++ b/src/Fieldtypes/Bard/LinkMark.php @@ -65,7 +65,7 @@ protected function convertHref($href) } if (! $this->isApi() && $item instanceof Entry) { - return ($item->in(Site::current()->handle()) ?? $item)->url(); + return ($item->in(Site::current()->handle()) ?? $item)->permalink; } return $item->url(); From f8830f156f33e14ae6bfb68e6a7349377293334c Mon Sep 17 00:00:00 2001 From: edalzell Date: Wed, 8 Oct 2025 16:00:28 -0700 Subject: [PATCH 02/10] Test for same domain --- src/Sites/Site.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Sites/Site.php b/src/Sites/Site.php index 75d4c777311..3e1163dcb10 100644 --- a/src/Sites/Site.php +++ b/src/Sites/Site.php @@ -102,6 +102,11 @@ public function isDefault() return $this->isDefault; } + public function sameDomain(Site $site): bool + { + return $this->removePath($this->absoluteUrl()) === $this->removePath($site->absoluteUrl()); + } + public function set($key, $value) { $this->config[$key] = $this->resolveAntlersValue($value); From b54b40ef49612dfb6194143ea357b047fe75698e Mon Sep 17 00:00:00 2001 From: edalzell Date: Wed, 8 Oct 2025 16:00:39 -0700 Subject: [PATCH 03/10] =?UTF-8?q?use=20permalink=20if=20it=E2=80=99s=20in?= =?UTF-8?q?=20a=20different=20domain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Fieldtypes/Bard/LinkMark.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Fieldtypes/Bard/LinkMark.php b/src/Fieldtypes/Bard/LinkMark.php index c19dfc02687..7f5f7a06b02 100644 --- a/src/Fieldtypes/Bard/LinkMark.php +++ b/src/Fieldtypes/Bard/LinkMark.php @@ -65,7 +65,11 @@ protected function convertHref($href) } if (! $this->isApi() && $item instanceof Entry) { - return ($item->in(Site::current()->handle()) ?? $item)->permalink; + if (Site::current()->sameDomain($item->site())) { + return $item->url(); + } + + return $item->permalink; } return $item->url(); From 14679f6bafe7497caa2a6330b0d300cce0471e73 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 9 Oct 2025 09:38:10 -0700 Subject: [PATCH 04/10] Use the existing config --- src/Fieldtypes/Bard/Augmentor.php | 9 ++++++++- src/Fieldtypes/Bard/LinkMark.php | 14 +++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Fieldtypes/Bard/Augmentor.php b/src/Fieldtypes/Bard/Augmentor.php index 4d1db607d80..b1dc686c889 100644 --- a/src/Fieldtypes/Bard/Augmentor.php +++ b/src/Fieldtypes/Bard/Augmentor.php @@ -13,6 +13,7 @@ class Augmentor { + public static $currentBardConfig = []; protected $fieldtype; protected $sets = []; protected $includeDisabledSets = false; @@ -169,7 +170,13 @@ public function renderHtmlToProsemirror(string $value) public function renderProsemirrorToHtml(array $value) { - return $this->editor()->setContent($value)->getHTML(); + static::$currentBardConfig = $this->fieldtype->config(); + + $html = $this->editor()->setContent($value)->getHTML(); + + static::$currentBardConfig = []; + + return $html; } private function editor() diff --git a/src/Fieldtypes/Bard/LinkMark.php b/src/Fieldtypes/Bard/LinkMark.php index 7f5f7a06b02..57be9d92c69 100644 --- a/src/Fieldtypes/Bard/LinkMark.php +++ b/src/Fieldtypes/Bard/LinkMark.php @@ -64,15 +64,15 @@ protected function convertHref($href) return ''; } - if (! $this->isApi() && $item instanceof Entry) { - if (Site::current()->sameDomain($item->site())) { - return $item->url(); - } - - return $item->permalink; + if ( + ! Augmentor::$currentBardConfig['select_across_sites'] && + ! $this->isApi() && + $item instanceof Entry + ) { + return ($item->in(Site::current()->handle()) ?? $item)->url(); } - return $item->url(); + return $item->permalink ?? $item->url(); } private function isApi() From 70967b1ec81004395407e109bd60a8e99b222066 Mon Sep 17 00:00:00 2001 From: Erin Dalzell Date: Thu, 9 Oct 2025 09:39:05 -0700 Subject: [PATCH 05/10] Not needed anymore --- src/Sites/Site.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Sites/Site.php b/src/Sites/Site.php index 3e1163dcb10..75d4c777311 100644 --- a/src/Sites/Site.php +++ b/src/Sites/Site.php @@ -102,11 +102,6 @@ public function isDefault() return $this->isDefault; } - public function sameDomain(Site $site): bool - { - return $this->removePath($this->absoluteUrl()) === $this->removePath($site->absoluteUrl()); - } - public function set($key, $value) { $this->config[$key] = $this->resolveAntlersValue($value); From 7b76010c0dbc38d49896dbe849a06d0ca1f13255 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 9 Oct 2025 10:38:27 -0700 Subject: [PATCH 06/10] test --- tests/Fieldtypes/BardTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Fieldtypes/BardTest.php b/tests/Fieldtypes/BardTest.php index c81004c0672..f63dfa35e36 100644 --- a/tests/Fieldtypes/BardTest.php +++ b/tests/Fieldtypes/BardTest.php @@ -1338,6 +1338,28 @@ public function it_calls_hooks() $this->assertArrayHasKey('custom_field', $bard->extraValidationAttributes($data)); } + #[Test] + public function it_doesnt_localize_when_select_across_sites_setting_is_enabled() + { + $this->setSites([ + 'en' => ['url' => 'http://localhost/', 'locale' => 'en'], + 'fr' => ['url' => 'http://localhost/fr/', 'locale' => 'fr'], + ]); + + tap(Facades\Collection::make('blog')->routes('blog/{slug}'))->sites(['en', 'fr'])->save(); + + EntryFactory::id('parent')->collection('blog')->slug('theparent')->id(123)->locale('en')->create(); + EntryFactory::id('123-fr')->origin('123')->locale('fr')->collection('blog')->slug('one-fr')->data(['title' => 'Le One', 'test' => ['type' => 'link', 'attrs' => ['href' => 'statamic://entry::123-fr']]])->create(); + + $field = (new Bard)->setField(new Field('test', array_merge(['type' => 'bard'], ['select_across_sites' => true]))); + + $augmented = $field->augment([ + ['type' => 'text', 'marks' => [['type' => 'link', 'attrs' => ['href' => 'statamic://entry::123-fr']]], 'text' => 'The One'], + ]); + + $this->assertEquals('The One', $augmented); + } + private function bard($config = []) { return (new Bard)->setField(new Field('test', array_merge(['type' => 'bard', 'sets' => ['one' => []]], $config))); From 552b87caf426338680a539f187dc8a9d40bddcf3 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 13 Oct 2025 11:38:06 -0400 Subject: [PATCH 07/10] selecting across sites uses permalink (absoluteUrl). matches logic in ArrayableLink --- src/Fieldtypes/Bard/LinkMark.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Fieldtypes/Bard/LinkMark.php b/src/Fieldtypes/Bard/LinkMark.php index 57be9d92c69..f1a3777152c 100644 --- a/src/Fieldtypes/Bard/LinkMark.php +++ b/src/Fieldtypes/Bard/LinkMark.php @@ -64,15 +64,17 @@ protected function convertHref($href) return ''; } + $selectAcrossSites = Augmentor::$currentBardConfig['select_across_sites'] ?? false; + if ( - ! Augmentor::$currentBardConfig['select_across_sites'] && + ! $selectAcrossSites && ! $this->isApi() && $item instanceof Entry ) { return ($item->in(Site::current()->handle()) ?? $item)->url(); } - return $item->permalink ?? $item->url(); + return $selectAcrossSites ? $item->absoluteUrl() : $item->url(); } private function isApi() From 46658412e61eceab07b0d0437fed12ff972bee07 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 13 Oct 2025 11:44:05 -0400 Subject: [PATCH 08/10] add test for localizing --- tests/Fieldtypes/BardTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Fieldtypes/BardTest.php b/tests/Fieldtypes/BardTest.php index f63dfa35e36..5d29b7e622e 100644 --- a/tests/Fieldtypes/BardTest.php +++ b/tests/Fieldtypes/BardTest.php @@ -1338,6 +1338,30 @@ public function it_calls_hooks() $this->assertArrayHasKey('custom_field', $bard->extraValidationAttributes($data)); } + #[Test] + public function it_localizes_when_select_across_sites_setting_is_disabled() + { + $this->setSites([ + 'en' => ['url' => 'http://localhost/', 'locale' => 'en'], + 'fr' => ['url' => 'http://localhost/fr/', 'locale' => 'fr'], + ]); + + Facades\Site::setCurrent('fr'); + + tap(Facades\Collection::make('blog')->routes('blog/{slug}'))->sites(['en', 'fr'])->save(); + + EntryFactory::id('parent')->collection('blog')->slug('theparent')->id(123)->locale('en')->create(); + EntryFactory::id('123-fr')->origin('123')->locale('fr')->collection('blog')->slug('one-fr')->data(['title' => 'Le One', 'test' => ['type' => 'link', 'attrs' => ['href' => 'statamic://entry::123-fr']]])->create(); + + $field = (new Bard)->setField(new Field('test', array_merge(['type' => 'bard'], ['select_across_sites' => false]))); + + $augmented = $field->augment([ + ['type' => 'text', 'marks' => [['type' => 'link', 'attrs' => ['href' => 'statamic://entry::123-fr']]], 'text' => 'The One'], + ]); + + $this->assertEquals('The One', $augmented); + } + #[Test] public function it_doesnt_localize_when_select_across_sites_setting_is_enabled() { From 678ba53b02f75eee4718709c19567d596d3f71a7 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 13 Oct 2025 11:44:18 -0400 Subject: [PATCH 09/10] be explicit about which site we're in --- tests/Fieldtypes/BardTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Fieldtypes/BardTest.php b/tests/Fieldtypes/BardTest.php index 5d29b7e622e..cf43e330fe9 100644 --- a/tests/Fieldtypes/BardTest.php +++ b/tests/Fieldtypes/BardTest.php @@ -1370,6 +1370,8 @@ public function it_doesnt_localize_when_select_across_sites_setting_is_enabled() 'fr' => ['url' => 'http://localhost/fr/', 'locale' => 'fr'], ]); + Facades\Site::setCurrent('en'); + tap(Facades\Collection::make('blog')->routes('blog/{slug}'))->sites(['en', 'fr'])->save(); EntryFactory::id('parent')->collection('blog')->slug('theparent')->id(123)->locale('en')->create(); From 2030963f1acdbbeed8ed032b67332e1f365714cf Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 13 Oct 2025 11:45:31 -0400 Subject: [PATCH 10/10] this passes the arbitrary "it fits on one line" test --- src/Fieldtypes/Bard/LinkMark.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Fieldtypes/Bard/LinkMark.php b/src/Fieldtypes/Bard/LinkMark.php index f1a3777152c..8bf5cfb7b81 100644 --- a/src/Fieldtypes/Bard/LinkMark.php +++ b/src/Fieldtypes/Bard/LinkMark.php @@ -66,11 +66,7 @@ protected function convertHref($href) $selectAcrossSites = Augmentor::$currentBardConfig['select_across_sites'] ?? false; - if ( - ! $selectAcrossSites && - ! $this->isApi() && - $item instanceof Entry - ) { + if (! $selectAcrossSites && ! $this->isApi() && $item instanceof Entry) { return ($item->in(Site::current()->handle()) ?? $item)->url(); }