PagesNames::uniquePageName() method

Get a unique page name

  1. If given no arguments, it returns a random globally unique page name.
  2. If given just a $name, it returns that name (if globally unique), or an incremented version of it that is globally unique.
  3. If given both $page and $name, it returns given name if unique in parent, or incremented version that is.
  4. If given just a $page, the name is pulled from $page and behavior is the same as #3 above.

The returned value is not yet assigned to the given $page, so if it is something different than what is already on $page, you’ll want to assign it manually after this.

Usage

// basic usage
$string = $pagesNames->uniquePageName();

// usage with all arguments
$string = $pagesNames->uniquePageName($name = '', $page = null, array $options = []);

Arguments

NameType(s)Description
name (optional)string, Page, array

Name to make unique You may optionally substitute the $page argument or $options arguments here, if that is all you need.

page (optional)
options (optional)array
  • parent (Page|null): Optionally specify a different parent if $page does not currently have the parent you want to use.
  • language (Language|int): Get unique for this language (if multi-language page names active).
  • page (Page|null): If you specified no $page argument, you can optionally bundle it in the $options array.
  • name (string): If you specified no $name argument, you can optionally bundle it in the $options array.

Return value

string

Returns unique name


PagesNames methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #520
    In the 520th issue of ProcessWire Weekly we'll check out some of the latest additions to the ProcessWire module's directory, share some highlights from the latest weekly update from Ryan, and more. Read on!
    Weekly.pw / 27 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits