Jump to content

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? 

Posted

Aside from not skipping this line 

if(!$this->page) throw new WireException("No page specified"); 

within the core module's init() method, this works (it just displays that error message on every other page due to autoloading when inapplicable):


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

Replace last line in hook___execute method with this:


		$event->replace = true;
		$event->return = "<div id='ProcessPageEditImageSelect'>" . $out . "\n</div>";

 

 

 

Posted (edited)

I thought I could make an accessory module to conditionally load the core-module-extension site-module, or do so in init.php, but I can't determine whether the core module has been loaded. 

I tried:

  • $modulesLoader->getAutoloadOrders() in ready.php and it says call to member function on null.
  • class_exists('ProcessPageEditImageSelect', false) says false

This works without 'noInit', but then the same problem message when inapplicable, so still need the condition check:

$this->wire()->addHook('ProcessPageEditImageSelect::execute', 
	$this->wire()->modules->getModule('ProcessPageEditImageSelect_Pickpage', 
	['noInit' => true]), 'hook___execute');

 

Edited by hellomoto
Posted

It needed the 'noThrow': 

$this->wire()->addHook('ProcessPageEditImageSelect::execute', 
	$this->wire()->modules->getModule('ProcessPageEditImageSelect_Pickpage', 
	['noThrow' => true]), 'hook___execute');

 

Posted (edited)

Because the code module is permanent, despite setting permanent=false in the site module, it won't uninstall. Attempting to do so only deletes the settings.

Edited by hellomoto

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...