InputfieldPage
InputfieldPage is the input controller for selecting one or more ProcessWire
pages as relational references
It is most often used by FieldtypePage, which
creates and configures it automatically for Page reference fields.
Inputfield does not render a selection UI by itself. Its inputfield
property names a delegate Inputfield, such as InputfieldSelect,
InputfieldAsmSelect, Inputfield, or
Inputfield. Inputfield determines selectable pages,
generates option labels, validates submitted selections, and normalizes selected
IDs into a PageArray or Page.
$f = $modules->get('InputfieldPage');
$f->name = 'category';
$f->label = 'Category';
$f->inputfield = 'InputfieldSelect';
$f->parent_id = $pages->get('/categories/')->id;
$f->labelFieldName = 'title';
$form->add($f); For shared Inputfield behavior, see the main Inputfield API documentation.
Expand all Collapse all API reference
The value attribute is a PageArray by default, even for a single selection.
When derefAsPage is enabled, the value is a single Page.
$value = $f->attr('value'); // PageArray by default
foreach($value as $page) {
echo $page->title;
}Accepted assignment formats include:
$f->attr('value', 1234); // page ID
$f->attr('value', '123|456|789'); // pipe-separated page IDs
$f->attr('value', $page); // Page
$f->attr('value', $pageArray); // PageArrayInteger IDs and pipe-separated ID strings are converted to a PageArray. Passing
a Page or PageArray stores that object as the value.
| Property | Type | Default | Description |
|---|---|---|---|
inputfield | string | '' | Delegate Inputfield class used for selection. Required for rendering. |
parent_id | int | 0 | Selectable pages must be children of this parent ID. |
template_id | int | 0 | Selectable pages must use this template ID. |
template_ids | array | [] | Additional selectable template IDs. |
findPagesSelector | string | '' | Selector string used to find selectable pages. |
findPagesSelect | string | '' | Selector string built by InputfieldSelector; fallback for findPagesSelector. |
findPagesCode | string | '' | Deprecated PHP code path for selectable pages. Hook getSelectablePages() instead. |
labelFieldName | string | '' | Field used for option labels. '.' means use labelFieldFormat. |
labelFieldFormat | string | '' | Markup format string passed to page markup APIs when labelFieldName='.'. |
derefAsPage | int | 0 | When truthy, value is a single Page rather than a PageArray. |
addable | int|bool | false | Allow inline creation of new selectable pages. |
allowUnpub | int|bool | false | Allow unpublished pages to be selected. |
inputfieldClasses | array | defaults | Delegate Inputfield classes offered in configuration. |
inputfieldClass | string | read-only setting | Resolved delegate class name, available through $f->getSetting('inputfieldClass'). |
At least one selectable-page constraint should usually be configured:
parent_id, template_id / template_ids, findPagesSelector, or
findPagesSelect.
getSelectablePages($page, $filterSelector = '')
Returns a PageArray of pages selectable for the page being edited. This is the
preferred hook point for custom selectable-page logic.
$wire->addHookAfter('InputfieldPage::getSelectablePages', function(HookEvent $event) {
$inputfield = $event->object; /** @var InputfieldPage $inputfield */
$page = $event->arguments(0);
if($inputfield->hasField == 'related_products') {
$event->return = $event->pages->find('template=product, featured=1');
}
}); The optional $filterSelector argument was added in ProcessWire 3.0.245 and
narrows the result with an additional selector.
Selectable pages can come from, in broad precedence order:
findPagesSelector/findPagesSelect- deprecated
findPagesCode - children of
parent_id - pages matching
template_id/template_ids
The page currently being edited is removed from the selectable set to prevent a page from referencing itself.
getPageLabel(Page $page, $allowMarkup = false)
Returns the option label for a page, using labelFieldName or
labelFieldFormat. Unpublished pages receive an (unpublished) suffix.
$label = $f->getPageLabel($somePage);renderPageLabel(Page $page, $allowMarkup = false)
Hookable implementation used by getPageLabel() when hooks are present.
$wire->addHookAfter('InputfieldPage::renderPageLabel', function(HookEvent $event) {
$page = $event->arguments(0);
$event->return = $page->title . ' (' . $page->parent->title . ')';
}); createFindPagesSelector(array $options = [])
Builds the effective selector from configured properties.
$selector = $f->createFindPagesSelector([ 'page' => $editPage ]);
// Example: parent_id=1042, templates_id=29, include=hiddenOptions:
| Option | Type | Description |
|---|---|---|
page | Page|null | Page context for dynamic page.field selector values. |
findRaw | bool | Add field information for $pages->findRaw() usage. |
getArray | bool | Return an associative array instead of a selector string. |
getTemplateIDs($getString = false)
Returns configured template IDs as an array, or as a 1|2|3 string when
$getString is true.
$ids = $f->getTemplateIDs();
$str = $f->getTemplateIDs(true);findPagesSelector and findPagesSelect can reference values from the page
being edited:
parent=page.section, template=articlepage.field and item.field placeholders are populated at render/process time.
When the placeholder refers to a page ID value and that value is empty, the value
is replaced with -1 so the selector intentionally matches nothing. Empty
non-ID subfields are replaced with an empty value.
getInputfield()
Returns the configured delegate Inputfield instance, populated with current value,
selectable options, selector information, and relevant settings. Returns null
if inputfield does not name a valid Inputfield module.
render()
Renders the delegate Inputfield and inline-add UI when enabled. If no valid
delegate is configured, it returns the input name and records an error during
renderReady().
renderValue()
Renders selected page labels for non-editable display. Multiple values render as
a <ul class="PageArray pw-bullets">.
processInput(WireInputData $input)
Delegates processing to the configured inputfield, validates submitted page IDs,
normalizes the value to PageArray or Page, and processes inline-added pages
when enabled.
isValidPage(Page $page, $field, ?Page $editPage = null)
Static validation helper used primarily by FieldtypePage. It validates parent,
template, selector, and self-reference constraints, but does not validate
deprecated findPagesCode results.
if(InputfieldPage::isValidPage($page, $field, $editPage)) {
// page may be selected
} When addable is enabled, parent_id and template_id are configured, and
labelFieldName is empty or title, the rendered input may include controls for
creating new selectable pages. Access is checked against the parent and new page.
Existing sibling pages with matching titles are reused rather than duplicated.
- Access this inputfield with
$modules->get('Inputfield.Page') - It is normally created by
FieldtypePage; manual construction is uncommon. - The
inputfieldproperty must identify a compatible delegate Inputfield. findPagesCodeis deprecated; hookgetSelectablePages()instead.isEmpty()returns true when no page is selected.- Companion classes include
FieldtypePage,InputfieldSelect,InputfieldAsmSelect,Inputfield,PageListSelect Inputfield, andPageAutocomplete InputfieldTextTags.
Source file: wire/modules/Inputfield/Inputfield
API reference: methods, properties, hooks
Note that this Inputfield does not collect input on its own and instead requires its inputfield property
to contain the class name of the Inputfield module that will be collecting input. It must be either
InputfieldSelect or another Inputfield that extends it, such as InputfieldRadios, InputfieldCheckboxes,
InputfieldAsmSelect, etc.
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Inputfield class also inherits all the methods and properties of: Inputfield, WireData and Wire.
Common
For hooks
These methods are only useful for hooking and should not be called directly.
| Name | Return | Summary | |
|---|---|---|---|
Inputfield Inputfield Inputfield | string | Render a label for the given page |
Properties
| Name | Return | Summary | |
|---|---|---|---|
| Inputfield | int bool | Provide an option for creating new pages and adding them to selection? DEFAULT: false | |
| Inputfield | int bool | Allow selection of unpublished pages? DEFAULT: false | |
| Inputfield | int | Make the value attribute a single Page rather than PageArray? DEFAULT: 0 | |
| Inputfield | string | Same as findPageSelector, but configured interactively with InputfieldSelector. DEFAULT: '' | |
| Inputfield | string | Selector string to use for finding selectable pages DEFAULT: '' | |
| Inputfield | string | Inputfield class used for input, i.e. InputfieldSelectDEFAULT: '' | |
| Inputfield | array | Class names of Inputfields that are allowed to be used for selection DEFAULT: 9+ classes | |
| Inputfield | string | Formatting string to use (which is sent to $page->getMarkup() method) as alternative to $labelFieldName. DEFAULT: '' | |
| Inputfield | string | Field name to use for label, i.e. “title”. Note that this will be "." if $labelFieldFormat is in use. DEFAULT: '' | |
| Inputfield | int | Parent ID of pages you want to be selectable DEFAULT: 0 | |
| Inputfield | int | Single template ID used by pages you want to be selectable. DEFAULT: 0 | |
| Inputfield | array | Multiple template IDs used by pages you want to be selectable. DEFAULT: [] |
Additional methods and properties
In addition to the methods and properties above, Inputfield
API reference based on ProcessWire core version 3.0.269