Skip to content

Commit

Permalink
fix(templates): override content + htmlelement components
Browse files Browse the repository at this point in the history
This is a fix for EPR-1048 that overrides the content getter in
both the "content" and "htmlelement" component classes so
that the input of the interpolation is the translated string.
  • Loading branch information
shawnbot committed Nov 16, 2023
1 parent 603014a commit 83429cc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/components/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { content: ContentComponent } = window.Formio.Components.components

export default class Content extends ContentComponent {
get content () {
const submission = this.root?.submission || {}
const html = this.t([`${this.component.key}.html`, this.component.html])
// console.warn('[%s] get content(): %s -> %s <-', this.component.type, this.component.html, html, this.rootValue)
const content = html
? this.interpolate(html, {
metadata: submission.metadata || {},
submission: submission,
data: this.rootValue,
row: this.data
})
: ''
return content || ''
}
}
17 changes: 17 additions & 0 deletions src/components/htmlelement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { htmlelement: FormioHTMLElementComponent } = window.Formio.Components.components

export default class HTMLElementComponent extends FormioHTMLElementComponent {
get content () {
const submission = this.root?.submission || {}
const content = this.t([`${this.component.key}.content`, this.component.content])
// console.warn('[%s] get content(): %s -> %s <-', this.component.type, this.component.content, content, data)
return content
? this.interpolate(content, {
metadata: submission.metadata || {},
submission,
data: this.rootValue,
row: this.data
})
: ''
}
}
8 changes: 6 additions & 2 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import address from './address'
import review from './review'
import columns from './columns'
import content from './content'
import htmlelement from './htmlelement'
import review from './review'
import signature from './signature'
import state from './state'
import zip from './zip'

export default {
address,
review,
columns,
content,
htmlelement,
review,
state,
signature,
zip
Expand Down

0 comments on commit 83429cc

Please sign in to comment.