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.

InputfieldPage does not render a selection UI by itself. Its inputfield property names a delegate Inputfield, such as InputfieldSelect, InputfieldAsmSelect, InputfieldPageListSelect, or InputfieldPageAutocomplete. InputfieldPage 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      API reference

Value

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);    // PageArray

Integer IDs and pipe-separated ID strings are converted to a PageArray. Passing a Page or PageArray stores that object as the value.

Properties
PropertyTypeDefaultDescription
inputfieldstring''Delegate Inputfield class used for selection. Required for rendering.
parent_idint0Selectable pages must be children of this parent ID.
template_idint0Selectable pages must use this template ID.
template_idsarray[]Additional selectable template IDs.
findPagesSelectorstring''Selector string used to find selectable pages.
findPagesSelectstring''Selector string built by InputfieldSelector; fallback for findPagesSelector.
findPagesCodestring''Deprecated PHP code path for selectable pages. Hook getSelectablePages() instead.
labelFieldNamestring''Field used for option labels. '.' means use labelFieldFormat.
labelFieldFormatstring''Markup format string passed to page markup APIs when labelFieldName='.'.
derefAsPageint0When truthy, value is a single Page rather than a PageArray.
addableint|boolfalseAllow inline creation of new selectable pages.
allowUnpubint|boolfalseAllow unpublished pages to be selected.
inputfieldClassesarraydefaultsDelegate Inputfield classes offered in configuration.
inputfieldClassstringread-only settingResolved 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.

Selectable Pages

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:

  1. findPagesSelector / findPagesSelect
  2. deprecated findPagesCode
  3. children of parent_id
  4. pages matching template_id / template_ids

The page currently being edited is removed from the selectable set to prevent a page from referencing itself.

Labels

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 . ')';
});
Selectors

createFindPagesSelector(array $options = [])

Builds the effective selector from configured properties.

$selector = $f->createFindPagesSelector([ 'page' => $editPage ]);
// Example: parent_id=1042, templates_id=29, include=hidden

Options:

OptionTypeDescription
pagePage|nullPage context for dynamic page.field selector values.
findRawboolAdd field information for $pages->findRaw() usage.
getArrayboolReturn 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);
Dynamic Selectors

findPagesSelector and findPagesSelect can reference values from the page being edited:

parent=page.section, template=article

page.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.

Delegate Inputfield

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.

Rendering and Processing

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
}
Inline Page Creation

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.

Notes
  • Access this inputfield with $modules->get('InputfieldPage').
  • It is normally created by FieldtypePage; manual construction is uncommon.
  • The inputfield property must identify a compatible delegate Inputfield.
  • findPagesCode is deprecated; hook getSelectablePages() instead.
  • isEmpty() returns true when no page is selected.
  • Companion classes include FieldtypePage, InputfieldSelect, InputfieldAsmSelect, InputfieldPageListSelect, InputfieldPageAutocomplete, and InputfieldTextTags.

Source file: wire/modules/Inputfield/InputfieldPage/InputfieldPage.module

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 InputfieldPage class also inherits all the methods and properties of: Inputfield, WireData and Wire.

Show class?     Show args?       Only hookable?    

Common

NameReturnSummary 
InputfieldPage::addClass($class)
InputfieldPage Inputfield

Add a CSS class name (extends Inputfield::addClass)

 
InputfieldPage::createFindPagesSelector()
string array

Create a page finding selector from all configured properties

 
InputfieldPage::getConfigInputfields()
InputfieldWrapper

Get field configuration Inputfields

InputfieldPage::getFieldSetups()
array

Get recommended setups for FieldtypePage/InputfieldPage

 
InputfieldPage::getInputfield()
Inputfield null

Get delegate Inputfield for page selection

 
InputfieldPage::getInputfieldOptions()
array

Get options available for page selection Inputfields

 
InputfieldPage::getPageLabel(Page $page)
string

Get a label for the given page

 
InputfieldPage::getSelectablePages(Page $page)
PageArray null

Return PageArray of selectable pages for this input

InputfieldPage::getSetting($key)
None 
InputfieldPage::getTemplateIDs()
array string

Return array or string of configured template IDs

 
InputfieldPage::has($key)
None 
InputfieldPage::isEmpty()
bool

Does this Inputfield have an empty value?

 
InputfieldPage::isValidPage(Page $page, $field)
bool

Is the given $page valid for the given $field?

 
InputfieldPage::processInput(WireInputData $input)
this Inputfield

Process input

InputfieldPage::render()
string

Render

InputfieldPage::renderReady()
bool

Called before render()

 
InputfieldPage::renderValue()
string

Render non-editable value

InputfieldPage::setAttribute($key, $value)
InputfieldPage Inputfield

Set an input attribute

 

For hooks

These methods are only useful for hooking and should not be called directly.

Properties

NameReturnSummary 
InputfieldPage::addable int bool Provide an option for creating new pages and adding them to selection?
DEFAULT: false
 
InputfieldPage::allowUnpub int bool Allow selection of unpublished pages?
DEFAULT: false
 
InputfieldPage::derefAsPage int Make the value attribute a single Page rather than PageArray?
DEFAULT: 0
 
InputfieldPage::findPagesSelect string Same as findPageSelector, but configured interactively with InputfieldSelector.
DEFAULT: ''
 
InputfieldPage::findPagesSelector string Selector string to use for finding selectable pages
DEFAULT: ''
 
InputfieldPage::inputfield string Inputfield class used for input, i.e. InputfieldSelect
DEFAULT: ''
 
InputfieldPage::inputfieldClasses array Class names of Inputfields that are allowed to be used for selection
DEFAULT: 9+ classes
 
InputfieldPage::labelFieldFormat string Formatting string to use (which is sent to $page->getMarkup() method) as alternative to $labelFieldName.
DEFAULT: ''
 
InputfieldPage::labelFieldName string Field name to use for label, i.e. “title”. Note that this will be "." if $labelFieldFormat is in use.
DEFAULT: ''
 
InputfieldPage::parent_id int Parent ID of pages you want to be selectable
DEFAULT: 0
 
InputfieldPage::template_id int Single template ID used by pages you want to be selectable.
DEFAULT: 0
 
InputfieldPage::template_ids 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, InputfieldPage also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.269