PagesExportImport::arrayToPage() method

Import an array of page data to a new Page (or update existing page)

Provided array ($a) must originate from the pageToArray() method format.

Returns a Page on success or a NullPage on failure. Errors, warnings and messages related to the import can be pulled from $page->errors(), $page->warnings() and $page->messages().

The following options may be used with the $options argument:

  • commit (bool): Commit/save the changes now? (default=true). Specify false to perform a test run.
  • update (bool): Allow update of existing pages? (default=true)
  • create (bool): Allow creation of new pages? (default=true)
  • parent (Page|string|int): Parent Page, path or ID. Omit to use import data (default=0).
  • template (Template|string|int): Template object, name or ID. Omit to use import data (default=0).
  • fieldNames (array): Import only these field names, or omit to use all import data (default=[]).
  • changeStatus (bool): Allow status to be changed aon existing pages? (default=true)
  • changeSort (bool): Allow sort and sortfield to be changed on existing pages? (default=true)
  • replaceTemplates (array): Array of import-data template name to replacement template name (default=[])
  • replaceFields (array): Array of import-data field name to replacement field name (default=[])
  • originalRootUrl (string): Original root URL (not including hostname)
  • originalHost (string): Original hostname

The following options are for future use and not currently applicable:

  • changeTemplate (bool): Allow template to be changed on existing pages? (default=false)
  • changeParent (bool): Allow parent to be changed on existing pages? (default=false)
  • changeName (bool): Allow name to be changed on existing pages? (default=false)
  • replaceParents (array): Array of import-data parent path to replacement parent path (default=[])

Usage

// basic usage
$page = $pagesExportImport->arrayToPage(array $a);

// usage with all arguments
$page = $pagesExportImport->arrayToPage(array $a, array $options = []);

Arguments

NameType(s)Description
aarray
options (optional)array

Options to modify default behavior, see method description.

Return value

Exceptions

Method can throw exceptions on error:

  • WireException


PagesExportImport methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #553
    In the 553rd issue of ProcessWire Weekly we'll check out the latest weekly update from Ryan, introduce a new third party module called Text Synthesis, and more. Read on!
    Weekly.pw / 14 December 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK