RepeaterMatrixField::addMatrixType()

Add a new matrix type

Please note that the Field must also be saved after calling this in order to commit it to the database.

Example

$field = $fields->get('my_matrix_field');
$field->addMatrixType('mailing_address', [
  'label' => 'Mailing address',
  'fields' => [ 'street', 'city', 'state', 'zip' ];
]);
$field->save();

Usage

// basic usage
$array = $repeaterMatrixField->addMatrixType(string $name);

// usage with all arguments
$array = $repeaterMatrixField->addMatrixType(string $name, array $options = []);

Arguments

NameType(s)Description
$namestring

Name for new matrix type

$options (optional)array

One or more of:

  • label (string): Human-readable label shown in the editor.
  • fields (array): Array of Field objects, names or IDs to add.
  • sort (int): Sort order for this new type or omit for auto (append).
  • head (string): Item header format string in the editor. Supports {field_name} placeholders, icon-{name} for a FontAwesome icon, and #rrggbb for a color accent. Omit for default {matrix_type} [• {matrix_summary}].

Return value

array

Info for the type added

Exceptions

Method can throw exceptions on error:

  • WireException - If given invalid name for type, or if name is already in use


RepeaterMatrixField methods and properties

API reference based on ProcessWire core version 3.0.260