Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: PFUN-26815

...

The block object has the following structure:

Property

Type

Required?

Description

element

String

Required

Location of the Groovy function which the block calls.

function

String

Required

Name of the function in the element specified by the element property, which the block calls.

params

List

Optional

List of parameter objects specifying the inputs of the block.

Each parameter object has the following properties:

  • name (String) – Unique name of the parameter.

  • type (String) – Type of the parameter, either number, string, or option.

  • label – (String) - Label of the parameter.

  • default – Default value supplied if the user does not provide the input; its type must correspond with the type property.

  • options – Specified only if the type is option. It is either a list of values, or a map where the key is the option’s value and value is the option’s label.

label

String

Required

Label rendered on the block. It can contain parameter placeholders like {1}, {2}, etc. If params are specified, each parameter will be rendered at the position of the corresponding placeholder, so the first parameter will be rendered at the {1} placeholder, the second at the {2} placeholder, and so on.

If no placeholders are specified, the parameters will be all added at the end of the block.

color

Integer or String

Optional

Color of the block. It can be either an integer value (0 to 360) representing HSV hue value, or a #rrggbb String representing a web color.

If no color is specified, the block will have the default color of the Functions toolbox category.

tooltip

String

Optional

Tooltip of the block which is displayed when the user hovers the pointer over the block. If empty, no tooltip will be displayed.

inlineParams

String

Optional

By default, params are displayed on a single line.

  • true - if set to true paramsare displayed on a single line.

    custom_block_inline_true.pngImage Added
  • false - if set to false params are displayed on multiple lines.

    custom_block_inline_false.pngImage Added

returns

String, either number or string

Required

Return type of the block. It should correspond with the type of the return value from the function defined by the element and function parameters.

Examples of Custom Blocks

...

  1. Create the Meta element and return a list with a single block configuration object from it, like this:

    Code Block
    languagegroovy
    return [
      [
        "element" : "Math",
        "function": "markupPct",
        "label"   : "{1} x (1 + {2})",
        "params"  : [
                ["name": "base", "type": "number", "label": "label_base"],
                ["name": "markup", "type": "number", "label": "label_markup", "default": 0]
        ],
        "inlineParams": true,
        "returns" : "number"
      ]
    ]

    Notice the label containing the placeholders that make the inputs render at the correct places.

  2. Create a Math element and in it create a function called markupPct with two parameters, like this:

    Code Block
    languagegroovy
    BigDecimal markupPct(BigDecimal base, BigDecimal markup) {
      if (base == null) {
        throw new Error("The base cannot be empty");
      }
      if (markup == null) {
        return base;
      }
      return base * (1 + markup)
    }

    You can name the element and function whatever you want as long as it is the same name as specified in the element and function properties in the block configuration object.

...