Module: alfresco/renderers/_PublishPayloadMixin

alfresco/renderers/_PublishPayloadMixin

The _PublishPayloadMixin should be mixed into all modules that perform publications. It provides a consistent way of generating the payload body. There are several different ways of generating a payload which include the following:

  • configured payload
  • the current item
  • the configured payload processed through one or more modifier functions
  • a new payload built from properties in the current item or a triggering publication payload
  • any of the above with the current item "mixed in"

Author:
  • Richard Smith
  • Martin Doyle
License:
Source:

Examples

Standard configured payload

{
  name: "alfresco/menus/AlfMenuItem",
  config: {
    label: "Configured payload",
    publishTopic: "CUSTOM_TOPIC",
    publishPayloadType: "CONFIGURED",
    publishPayload: {
      value: "one"
    }
  }
}

Standard configured payload with current item mixed in

{
  name: "alfresco/menus/AlfMenuItem",
  config: {
    label: "Configured payload with current item data",
    publishTopic: "CUSTOM_TOPIC",
    publishPayloadType: "CONFIGURED",
    publishPayload: {
      value: "one"
    },
    publishPayloadItemMixin: true
  }
}

Current item payload

{
  name: "alfresco/menus/AlfMenuItem",
  config: {
    label: "Current item as payload",
    publishTopic: "CUSTOM_TOPIC",
    publishPayloadType: "CURRENT_ITEM"
  }
}

Processed payload using values from current item

{
  name: "alfresco/menus/AlfMenuItem",
  config: {
    label: "Configured payload with current item data",
    publishTopic: "CUSTOM_TOPIC",
    publishPayloadType: "PROCESS",
    publishPayload: {
      value: "{value.on.currentItem}"
    },
    publishPayloadModifiers: ["processCurrentItemTokens"]
  }
}

Build payload (using data from both the currentItem and the received payload)

{
  name: "alfresco/menus/AlfMenuItem",
  config: {
    label: "Configured payload with current item data",
    publishTopic: "CUSTOM_TOPIC",
    publishPayloadType: "BUILD",
    publishPayload: {
      shortName: {
        alfType: "item",
        alfProperty: "shortName"
      },
      visibility: {
        alfType: "payload",
        alfProperty: "value"
     }
   }
}

Extends

  • alfresco/core/ObjectProcessingMixin

Members

_generatedPayload :object

This variable references payloads generated by calls to getGeneratedPayload.
Type:
  • object
Default Value:
  • null
Source:

<readonly> PayloadTypes :string

The default payload types
Type:
  • string
Properties:
Name Type Default Description
CONFIGURED string CONFIGURED
CURRENT_ITEM string CURRENT_ITEM
PROCESS string PROCESS
BUILD string BUILD
Source:

publishGlobal :boolean

Whether to publish the topic globally
Type:
  • boolean
Default Value:
  • false
Source:

publishPayload :object

The payload to publish when this menu item is selected
Type:
  • object
Default Value:
  • null
Source:

publishPayloadItemMixin :boolean

Whether to mix the current item into the generated payload
Type:
  • boolean
Default Value:
  • false
Source:

publishPayloadModifiers :string[]

An array of modifier functions to apply when the type is PROCESS
Type:
  • string[]
Default Value:
  • null
Source:

publishPayloadType :module:alfresco/renderers/_PublishPayloadMixin#PayloadTypes

The type of payload to generate. When specified, should comprise one or more of the default values defined by the PayloadTypes enum
Type:
Default Value:
  • null
Source:

publishToParent :boolean

Whether to publish the topic using the parent pubSubScope
Type:
  • boolean
Default Value:
  • false
Source:

publishTopic :string

The topic to publish when this menu item is selected
Type:
  • string
Default Value:
  • null
Source:

Methods

buildPayload(configuredPayload, currentItem, receivedPayload) → {object}

This function is used to process configurable payloads. If a publishPayload property is available on the configuration object it iterates over the first-level of attributes of the defined payload and checks to see if the attribute is an object featuring both 'alfType' and 'alfProperty' properties. If the attribute does match this criteria then the payload will be processed to attempt to retrieve the defined 'alfProperty' from a specific type. Currently two types are supported:

  • 'item' which indicates the property is of the item object
  • 'payload' which indicates the property is of the payload object

A defReturn attribute provides the option for the default return to be defined should there be no publishPayload provided on the configuration object.

Parameters:
Name Type Description
configuredPayload object The configured payload - this is used to generate a new payload
currentItem object The current item
receivedPayload object The payload that triggered the request to generate a new payload
Source:
Returns:
The payload to be published
Type
object

generatePayload(configuredPayload, currentItem, receivedPayload, payloadType, mixinCurrentItem, publishPayloadModifiers) → {object}

Generates the payload based on the supplied attributes.
Parameters:
Name Type Argument Description
configuredPayload object The configured payload
currentItem object The current item
receivedPayload object A payload that may have been received to trigger the request to generate a new payload (set as null if not applicable)
payloadType string <optional>
The type of payload to generate (one of "CONFIGURED", "CURRENT_ITEM", "PROCESS" or "BUILD")
mixinCurrentItem boolean <optional>
Whether to mixin the current item into the generated payload
publishPayloadModifiers Array An array of modifier functions to apply when the type is "PROCESS"
Source:
Returns:
The generated payload
Type
object

getGeneratedPayload(regenerate, receivedPayload) → {object}

This function will retrieve the generated payload (and will generate it if this is the first time that it has been requested).
Parameters:
Name Type Argument Description
regenerate boolean <optional>
If this is passed as true then any previously generated payload will be regenerated.
receivedPayload object <optional>
A payload that has been received that triggers the generation.
Source:
Returns:
The generated payload.
Type
object

processValue(configuredPayload, currentItem, receivedPayload) → {object}

Called from buildPayload on requests to build a new payload item.
Parameters:
Name Type Description
configuredPayload object The configured payload - this is used to generate a new payload
currentItem object The current item
receivedPayload object The payload that triggered the request to generate a new payload
Source:
Returns:
The processed value.
Type
object