Skip to content

Instantly share code, notes, and snippets.

@somatonic
Created October 3, 2012 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somatonic/3829852 to your computer and use it in GitHub Desktop.
Save somatonic/3829852 to your computer and use it in GitHub Desktop.
custom page name
<?php
class Helloworld extends WireData implements Module {
public static function getModuleInfo() {
return array(
'title' => 'Hello World',
'version' => 101,
'summary' => 'An example module used for demonstration purposes. See the /site/modules/Helloworld.module file for details.',
'href' => 'http://www.processwire.com',
'singular' => true,
'autoload' => true,
);
}
public function init() {
$this->addHookBefore('InputfieldPageName::render', $this, 'hookRender');
}
public function hookRender(HookEvent $event) {
// if process isn't ProcessPageAdd, exit now
if($this->process != 'ProcessPageAdd') return;
// if the GET var 'parent_id' isn't the one we want, exit now
$parent = $this->pages->get($this->input->get->parent_id);
if($parent->template != "basic-page") return;
$inputfield = $event->object;
// if the input already has a populated value, exit now
if(strlen($inputfield->attr('value'))) return;
// if we made it here, populate the value attribute
$inputfield->attr('value', 'the-page-name-you-want');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment