Skip to content
Open
Show file tree
Hide file tree
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
35 changes: 30 additions & 5 deletions resources/js/components/fieldtypes/bard/LinkToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@
<ui-separator :text="__('Advanced Options')" />

<section class="space-y-5">
<!-- Append attribute -->
<ui-input
v-if="linkType === 'entry'"
type="text"
ref="input"
v-model="appends"
prepend="Append"
:placeholder="__('?query=params#anchor')"
/>

<!-- Title attribute -->
<ui-input
type="text"
Expand Down Expand Up @@ -196,6 +206,7 @@ export default {
url: {},
urlData: {},
itemData: {},
appends: null,
title: null,
rel: null,
targetBlank: false,
Expand Down Expand Up @@ -307,7 +318,11 @@ export default {
},

watch: {
linkType() {
linkType(type) {
if (type != 'entry') {
this.appends = null;
}

this.autofocus();
},

Expand Down Expand Up @@ -349,8 +364,8 @@ export default {
methods: {
applyAttrs(attrs) {
this.linkType = this.getLinkTypeForUrl(attrs.href);

this.url = { [this.linkType]: attrs.href };
this.appends = this.getAppendsForUrl(attrs.href);
this.url = { [this.linkType]: attrs.href?.replace(this.appends, '' ) };
this.urlData = { [this.linkType]: this.getUrlDataForUrl(attrs.href) };
this.itemData = { [this.linkType]: this.getItemDataForUrl(attrs.href) };

Expand Down Expand Up @@ -393,7 +408,7 @@ export default {
}

this.$emit('updated', {
href: this.href,
href: this.href + (this.appends ?? ''),
rel: this.rel,
target: this.canHaveTarget && this.targetBlank ? '_blank' : null,
title: this.title,
Expand Down Expand Up @@ -494,14 +509,24 @@ export default {
return this.bard.meta.linkData[ref];
},

getAppendsForUrl(urlString) {
// appends is only relevant to entry links
if (! urlString?.includes('statamic://entry::')) {
return null;
}

return urlString.replace(urlString.split(/[?#]/)[0], '');
},

parseDataUrl(url) {
if (!url) {
return {};
}

const appends = this.getAppendsForUrl(url);
const regex = /^statamic:\/\/((.*?)::(.*))$/;

const matches = url.match(regex);
const matches = url.replace(appends, '').match(regex);
if (!matches) {
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fieldtypes/Bard.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ private function extractLinkDataFromNode($node)

private function getLinkDataForUrl($url)
{
$ref = Str::after($url, 'statamic://');
$ref = str($url)->after('statamic://')->before('?')->before('#')->toString();
[$type, $id] = explode('::', $ref, 2);

$data = null;
Expand Down
8 changes: 5 additions & 3 deletions src/Fieldtypes/Bard/LinkMark.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ protected function convertHref($href)
return $href;
}

$ref = Str::after($href, 'statamic://');
$ref = str($href)->after('statamic://')->before('?')->before('#')->toString();

if (! $item = Data::find($ref)) {
return '';
}

$selectAcrossSites = Augmentor::$currentBardConfig['select_across_sites'] ?? false;

$extras = Str::after($href, $ref);

if (! $selectAcrossSites && ! $this->isApi() && $item instanceof Entry) {
return ($item->in(Site::current()->handle()) ?? $item)->url();
return ($item->in(Site::current()->handle()) ?? $item)->url().$extras;
}

return $selectAcrossSites ? $item->absoluteUrl() : $item->url();
return $selectAcrossSites ? $item->absoluteUrl().$extras : $item->url().$extras;
}

private function isApi()
Expand Down
Loading