New in 1.20.0

updateReferences(mapping)

Updates all references to other CMS objects, based on a mapping function.

Updates all references to other CMS objects in every attribute, including those of widgets. The given mapping function will be applied to each referenced target CMS object ID. References are found in attributes of the types reference, referencelist, link, linklist and html.

The returned Promise resolves, after all references have been updated.

Params

  • mapping (Function) – A function that receives the CMS object ID (String) for each reference of the object, including references inside its widgets. The function is expected to return either a valid CMS object ID (String) or undefined, the latter to indicate that the reference should not be changed.

Returns

Promise<void> – Resolves as soon as all new IDs have been set.

Throws

Nothing. Errors from the callback or invalid callback results are thrown asynchronously.

Remarks

The input CMS object ID does not necessarily need to refer to an existing CMS object.

The returned CMS object ID may refer to a CMS object not (yet) created. It must be a valid object ID though, i.e. a sixteen characters hex string.

Combine the call with finishSaving if the subsequent statements must not be executed before the changes have actually been persisted.

Examples

Replaces the links pointing to a soon-to-be-deleted CMS object with their new target:

Replaces references to a different site with their corresponding destinations from the source site. Additionally waits for the changes to be persisted, using finishSaving: