Created
October 3, 2012 21:07
-
-
Save somatonic/3829852 to your computer and use it in GitHub Desktop.
custom page name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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