Skip to content

pbOnAfterCreate

Triggers after creating a block or table. Getting the list of fields.

Parameters

ParameterDescription
typeType: pbBlock|pbTable
arrayArray of fields

Examples


Changing the field for the table

php
if ($modx->event->name === 'pbOnAfterCreate') {
    if ($type === 'pbTable' && $model_id === 234 && $constructor_id === 51) {
        $modx->event->params['array'] = array_map(function($field) {
            if ($field['name'] === 'title') {
                $field['type'] = 'displayfield';
                $field['required'] = false;
                $field['value'] = 'Custom title';
            }
            return $field;
        }, $array);
    }
}

Changing the field for the block

php
if ($modx->event->name === 'pbOnAfterCreate') {
    if ($type === 'pbBlock' && $model_id === 234 && $constructor_id === 93) {
        $modx->event->params['array'] = array_map(function($field) {
            if ($field['name'] === 'title') {
                $field['required'] = false;
                $field['default'] = 12;
            }
            return $field;
        }, $array);
    }
}

© PageBlocks 2019-present