Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Processwire module for changing the default Image Select parent when inserting an image into an RTE
<?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
You can’t perform that action at this time.