FieldtypeModule class

Stores a reference to a ProcessWire module

The value is either a module class name string or a live module instance, depending on the instantiateModule field setting. This is an advanced fieldtype, visible in the field editor only when advanced mode is enabled.

Value type

Depends on the instantiateModule field setting:

instantiateModuleValue when setValue when empty
false (default)string — module class namesee blankType
trueModule — instantiated module objectsee blankType

The empty/blank value is controlled by the blankType field setting:

blankTypeEmpty value
'null' (default)null
'zero'0
'false'false
'placeholder'ModulePlaceholder instance
Getting and setting values
// When instantiateModule=false (default): value is a class name string
$className = $page->module_field;  // e.g. 'InputfieldText' or null if not set
if($className) {
    $module = $modules->get($className);
}

// When instantiateModule=true: value is a live Module instance
$module = $page->module_field;
if($module instanceof Module) {
    // use the module directly
}

// Set by class name (works regardless of instantiateModule setting)
$page->module_field = 'InputfieldText';
$page->save('module_field');

// Set by Module instance (also works regardless of setting)
$page->module_field = $modules->get('InputfieldText');
$page->save('module_field');

// Clear the value
$page->module_field = null;
$page->save('module_field');
Selectors
// Match by module class name
$pages->find('module_field=InputfieldText');
$pages->find('module_field!=InputfieldText');

Supports = and != operators only. Both module class names and numeric module IDs are accepted as selector values.

Notes
  • This fieldtype is only visible in advanced mode in the field editor (isAdvanced() === true).
  • moduleTypes: array of type prefixes or class names to filter which modules are selectable.
  • matchType: 'prefix' matches modules by name prefix (faster); 'verbose' matches by class inheritance (more flexible).
  • instantiateModule: when true, the field value is a live Module instance; when false (default), it is the module class name string.
  • blankType: controls what an empty/unset field returns — null (default), 0, false, or a ModulePlaceholder instance.
  • Database column: data INT NOT NULL (stores the module's numeric ID).
  • Compatible fieldtypes: FieldtypeModule only.
API reference: methods, hooks

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the FieldtypeModule class also inherits all the methods and properties of: Fieldtype, WireData and Wire.

Show class?     Show args?       Only hookable?    

Common

NameReturnSummary 
FieldtypeModule::getBlankValue(Page $page, Field $field)
bool int null ModulePlaceholder

Get blank value

 
FieldtypeModule::getCompatibleFieldtypes(Field $field)
Fieldtypes

Get compatible Fieldtypes

FieldtypeModule::getConfigInputfields(Field $field)
InputfieldWrapper

Configure field

FieldtypeModule::getDatabaseSchema(Field $field)
array

Get database schema

 
FieldtypeModule::getFieldClass()
string

Get the Field class to use for fields of this type

 
FieldtypeModule::getInputfield(Page $page, Field $field)
Inputfield

Get Inputfield

 
FieldtypeModule::getMatchQuery(PageFinderDatabaseQuerySelect $query, string $table, string $subfield, string $operator, mixed $value)
PageFinderDatabaseQuerySelect DatabaseQuerySelect

Get the database query that matches a Fieldtype table’s data with a given value.

 
FieldtypeModule::getSelectableModules(Field $field)
array

Get all selectable modules for given field

 
FieldtypeModule::getSelectorInfo(Field $field)
array

Return array with information about what properties and operators can be used with this field.

FieldtypeModule::isAdvanced()
bool

Should this Fieldtype only be allowed for new fields in advanced mode?

 
FieldtypeModule::markupValue(Page $page, Field $field)
string

Render a markup string of the value.

FieldtypeModule::sanitizeValue(Page $page, Field $field, $value)
int bool null Module

Sanitize value

 
FieldtypeModule::sleepValue(Page $page, Field $field, $value)
int

Sleep value

FieldtypeModule::wakeupValue(Page $page, Field $field, $value)
string

Wakeup value

Additional methods and properties

In addition to the methods and properties above, FieldtypeModule also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.259