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"
- Copyright:
- Copyright (C) 2005-2020 Alfresco Software Limited
- License:
- GNU Lesser General Public License, see: Open Source Licensing
- Source:
Examples
{
name: "alfresco/menus/AlfMenuItem",
config: {
label: "Configured payload",
publishTopic: "CUSTOM_TOPIC",
publishPayloadType: "CONFIGURED",
publishPayload: {
value: "one"
}
}
}
{
name: "alfresco/menus/AlfMenuItem",
config: {
label: "Configured payload with current item data",
publishTopic: "CUSTOM_TOPIC",
publishPayloadType: "CONFIGURED",
publishPayload: {
value: "one"
},
publishPayloadItemMixin: true
}
}
{
name: "alfresco/menus/AlfMenuItem",
config: {
label: "Current item as payload",
publishTopic: "CUSTOM_TOPIC",
publishPayloadType: "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"]
}
}
{
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
- Source:
Properties:
Name Type Default Description CONFIGURED
string CONFIGURED CURRENT_ITEM
string CURRENT_ITEM PROCESS
string PROCESS BUILD
string BUILD -
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 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" 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. 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 Returns:
The processed value.- Type
- object