Forked from adrianbj/ChangeImageSelectParent .module
Created
August 30, 2014 14:56
-
-
Save mr-fan/4751ea179334139d1f76 to your computer and use it in GitHub Desktop.
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 ChangeImageSelectParent extends WireData implements Module, ConfigurableModule { | |
/** | |
* Data as used by the get/set functions | |
* | |
*/ | |
protected $data = array(); | |
/** | |
* Default configuration for module | |
* | |
*/ | |
static public function getDefaultData() { | |
return array( | |
"rootParent" => "" | |
); | |
} | |
public static function getModuleInfo() { | |
return array( | |
'title' => 'Change Image Select Parent', | |
'version' => 1, | |
'singular' => true, | |
'autoload' => true | |
); | |
} | |
/** | |
* Populate the default config data | |
* | |
*/ | |
public function __construct() { | |
foreach(self::getDefaultData() as $key => $value) { | |
$this->$key = $value; | |
} | |
} | |
public function init() { | |
$this->addHookAfter('ProcessPageEditImageSelect::execute', $this, 'changeParent'); | |
} | |
public function changeParent(HookEvent $event) { | |
$event->replace = true; | |
$event->return = str_replace("rootPageID: 0", "rootPageID: ". $this->data['rootParent'], $event->return); | |
} | |
/** | |
* Return an InputfieldsWrapper of Inputfields used to configure the class | |
* | |
* @param array $data Array of config values indexed by field name | |
* @return InputfieldsWrapper | |
* | |
*/ | |
public static function getModuleConfigInputfields(array $data) { | |
$data = array_merge(self::getDefaultData(), $data); | |
$wrapper = new InputFieldWrapper(); | |
$f = wire('modules')->get('InputfieldPageListSelect'); | |
$f->attr('name+id', 'rootParent'); | |
$f->label = __('Root Parent', __FILE__); | |
$f->columnWidth = 50; | |
$f->description = __('The root page for the Image Select dialog to start from.', __FILE__); | |
$f->attr('title', __('Root Parent', __FILE__)); | |
if(isset($data['rootParent'])) $f->value = $data['rootParent']; | |
$wrapper->add($f); | |
return $wrapper; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment