Jump to content

How to extend a core module class and just overwrite one method?


Recommended Posts

Posted (edited)

I enabled a site module extending a core module:

class ProcessPageEditImageSelect_Pickpage extends ProcessPageEditImageSelect implements Module, ConfigurableModule {
    public static function getModuleinfo() {
        return [
            'title' => 'Page Edit Image pickfrompage',
            'summary' => 'Extends core module: Enables specifying a default page to pick images from if the page being edited has no image fields.',
			'autoload' => true,
			'permission' => 'page-edit',
        ];
    }

	public function __construct() {
		parent::__construct();
	}

	public function init() {
		parent::init();
		bd($this->data);
	}

	public function ___execute() {}

	public function getModuleConfigInputfields(array $data) {
		$inputfields = $this->wire(new InputfieldWrapper());
		$modules = $this->wire()->modules;

		/** @var InputfieldPageListSelect $f */
        $f = $modules->get('InputfieldPageListSelect');
		$f->attr('name', 'defaultPage');
		$f->attr('value', @$data['defaultPage']);
		$f->label = $this->_('Default page for images if no image fields');
		$f->value = @$data['defaultPage'];
		$inputfields->add($f);

        /** @var InputfieldPageListSelect $f */
        $f = $modules->get('InputfieldTextarea');
		$f->attr('name', 'templateDefaultPage');
		$f->attr('value', @$data['templateDefaultPage']);
		$f->label = $this->_('Default page by template for images if no image fields');
		$f->notes = "1 pair of selectors `{template}:{page}` per line, e.g.,: `1:/home/`, or `home:1`, or `contact:template=home`";
		$f->value = @$data['templateDefaultPage'];
		$inputfields->add($f);

		return $inputfields;
	}
}

where the execute method is the one here and the init method returns the core module's data but my execute method has no effect. What's wrong with how I'm doing it?

Thank you

On pages where it doesn't apply, there's an error notice from the init method of the core module:  

Modules: Failed to init module: ProcessPageEditImageSelect_Pickpage - No page specified

but nothing shows (Tracy debugging) if not autoloaded, and ___execute has no effect either way.

Edited by hellomoto
autoload comment
Posted

I guess the class needs to be called instead of the native one to implement its execute method. 

I added this in its construct:


		foreach ($this->defaultDataAddl as $k => $v) {
			if (!array_key_exists($k, $this->data)) $this->data[$k] = $v;
		}
		$this->addHook('ProcessPageEditImageSelect::execute', $this, '___execute');

and it has the data from the config, and the $this->page assignment changing, but it's not being called during instantiation in context, so it doesn't call any other of the object's methods needed to execute? 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...