Skip to content

Commit a63dbc4

Browse files
committed
fix(wordpress): fix using blocks in multiple contents
1 parent f7ba817 commit a63dbc4

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

packages/smooth-backend-wordpress/src/acf/config/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import oneBlock from './oneBlock'
1+
import isBlock from './isBlock'
22
import oneContent from './oneContent'
33

44
export function generateConfig(ast, helpers) {
55
const state = { ast }
6-
const layouts = ast.definitions
7-
.map(def => oneBlock(def, helpers, state))
8-
.filter(x => x)
96

10-
state.blockLayouts = layouts
7+
state.blockNodes = ast.definitions.filter(def => isBlock(def, helpers))
118

129
const contentFieldGroups = ast.definitions
1310
.map(def => oneContent(def, helpers, state))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function isBlock(node, helpers) {
2+
const { gql: g } = helpers
3+
if (!g.isObjectTypeDefinition(node)) return false
4+
if (!g.getDirective(node, 'block')) return false
5+
return true
6+
}

packages/smooth-backend-wordpress/src/acf/config/oneBlock.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import allFields from './allFields'
22

33
export default function oneBlock(node, helpers, state) {
44
const { gql: g, acf: a } = helpers
5-
if (!g.isObjectTypeDefinition(node)) return null
6-
if (!g.getDirective(node, 'block')) return null
75

86
const name = g.getName(node)
9-
const id = `blocks_${name}`
7+
const id = `${state.parentId}_blocks_${name}`
108
const description = node.description ? node.description.value : null
119
const fields = allFields(node, helpers, { ...state, parentId: id })
1210

packages/smooth-backend-wordpress/src/acf/config/oneField.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { singularize, humanize } from 'smooth/utils'
22
import allFields from './allFields'
3+
import oneBlock from './oneBlock'
34

45
function enumValuesToChoices(nodes, helpers) {
56
const { gql: g } = helpers
@@ -119,7 +120,7 @@ const handlers = {
119120
return {
120121
type: 'flexible_content',
121122
button_label: 'Add block',
122-
layouts: state.blockLayouts,
123+
layouts: state.blockNodes.map(node => oneBlock(node, helpers, state)),
123124
}
124125
},
125126
union({ list, name, type }, helpers, state) {

0 commit comments

Comments
 (0)