Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unpublish to shouldPublish option of transformEntry function #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ The transform function is expected to return an object with the desired target f
- `fields` is an object containing each of the `from` fields. Each field will contain their current localized values (i.e. `from == {myField: {'en-US': 'my field value'}}`)
- `locale` one of the locales in the space being transformed
The return value must be an object with the same keys as specified in `to`. Their values will be written to the respective entry fields for the current locale (i.e. `{nameField: 'myNewValue'}`). If it returns `undefined`, this the values for this locale on the entry will be left untouched.
- **`shouldPublish : boolean`** _(optional)_ – If `true`, the transformed entries will be published. If `false`, both will remain in draft state (default `true`)
- **`shouldPublish : boolean | 'unpublish'`** _(optional)_ – If `true`, the transformed entries will be published. If `false`, both will remain in updated state, and if `unpublish`, they will be unpublished to a draft state (default `true`)

##### `transformEntries` Example

Expand Down
4 changes: 3 additions & 1 deletion src/lib/action/entry-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EntryTransformAction extends APIAction {
private contentTypeId: string
private fromFields: string[]
private transformEntryForLocale: Function
private shouldPublish: boolean|'preserve'
private shouldPublish: boolean|'preserve'|'unpublish'

constructor (contentTypeId: string, fromFields: string[], transformation: Function, shouldPublish: boolean|'preserve' = true) {
super()
Expand Down Expand Up @@ -52,6 +52,8 @@ class EntryTransformAction extends APIAction {
await api.saveEntry(entry.id)
if (this.shouldPublish === true || (this.shouldPublish === 'preserve' && entry.isPublished) ) {
await api.publishEntry(entry.id)
} else if (this.shouldPublish === 'unpublish') {
await api.unpublishEntry(entry.id)
}
}
}
Expand Down