Skip to content

Commit 4c75ac9

Browse files
committed
MC-3865: Content Types With Links Redirect On Storefront If Link Is Empty
Simplify converter logic
1 parent d424d7d commit 4c75ac9

File tree

6 files changed

+28
-52
lines changed

6 files changed

+28
-52
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/converter/attribute/link-href.js

Lines changed: 8 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/converter/attribute/preview/link-href.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/property/link.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/converter/attribute/link-href.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,15 @@ export default class CreateValueForHref implements ConverterInterface {
6464
* @returns {string}
6565
*/
6666
public toDom(name: string, data: DataObject): string {
67-
const link = data[name] as any;
68-
let href;
67+
let link = data[name] as any;
6968

70-
if (typeof link === "undefined") {
71-
href = "javascript:void(0)";
72-
} else if (typeof link.type !== "undefined") {
73-
if (typeof link.href !== "undefined" && link.type === "default") {
74-
link[link.type] = link.href;
75-
}
76-
77-
delete link.href;
78-
79-
if (link[link.type] === "javascript:void(0)") {
80-
link[link.type] = "";
81-
}
82-
83-
href = link[link.type];
84-
85-
if (!href.length) {
86-
href = "javascript:void(0)";
87-
}
69+
if (typeof link === "undefined" || !link[link.type].length) {
70+
return "javascript:void(0)";
71+
}
8872

89-
const isHrefIdReference = !isNaN(parseInt(href, 10)) && link.type !== "default";
73+
let href = link[link.type];
9074

91-
if (isHrefIdReference) {
92-
href = this.convertToWidget(href, link.type);
93-
}
94-
}
75+
href = this.convertToWidget(href, link.type);
9576

9677
return href;
9778
}
@@ -102,6 +83,10 @@ export default class CreateValueForHref implements ConverterInterface {
10283
* @returns {string}
10384
*/
10485
private convertToWidget(href: string, linkType: string): string {
86+
if (!href || !this.widgetParamsByLinkType[linkType]) {
87+
return href;
88+
}
89+
10590
const attributesString = _.map(
10691
this.widgetParamsByLinkType[linkType],
10792
(val: string, key: string) => `${key}='${val.replace(":href", href)}'`,

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/converter/attribute/preview/link-href.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export default class CreateValueForHref implements ConverterInterface {
3838
const linkType = link.type;
3939

4040
if (link[linkType]) {
41+
if (link[linkType] === "javascript:void(0)") {
42+
link[linkType] = "";
43+
}
44+
4145
href = link[linkType];
4246
}
4347

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/property/link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class Link implements PropertyReaderInterface {
5050
const attributeIdMatches = href.match(regexp);
5151

5252
if (!attributeIdMatches) {
53-
return href;
53+
return "";
5454
}
5555

5656
return attributeIdMatches[1];

0 commit comments

Comments
 (0)