Skip to content

Instantly share code, notes, and snippets.

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 mr-fan/4751ea179334139d1f76 to your computer and use it in GitHub Desktop.
Save mr-fan/4751ea179334139d1f76 to your computer and use it in GitHub Desktop.
<?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