Jump to content

Module config with image upload?


Karl_T
 Share

Recommended Posts

I am developing a SEO module with the latest industry standard. I want to upload some images such as logos and used by the module as default setting, while everything is configurable inside the module config page. I know the fact that module configuration page is not allowed to have file/image upload field due to the module fields are only inputfields but no fieldtypes. I would like to adopt an approach to solve this issue.

The approach is that, in module installation, I create a page somewhere inside admin with file/image field. And then inside the module config page, the needed fields can be referenced and rendered for image upload. Any similar modules has used similar approach? This approach can also be used for complex fields like repeater field for hreflang, open graph and twitter card too.

I don't know if the above setup is possible. Please feel free to share any thoughts or advise another approach.

  • Like 1
Link to comment
Share on other sites

On 29/01/2018 at 7:56 AM, Karl_T said:

The approach is that, in module installation, I create a page somewhere inside admin with file/image field. And then inside the module config page, the needed fields can be referenced and rendered for image upload. Any similar modules has used similar approach?

An admin page to hold a module's config itself is not new and has been done. The bit about image upload via the module's config page, that I've not seen/heard of before. I'm wondering whether it is really worth the effort since you'd have to hook into the module class (I think), to catch the upload and save it to your admin page. Maybe it is easier to let your SEO be a process module and in there, create the interface for uploading images? The images will still be saved in your hidden admin page. You wouldn't have to hook into anything in this case. Will this module be accessible to non-superusers? In that case, you don't want them to be mucking about in ProcessWire's module pages. I'd go for a process module and save  all text setting as one chunk of JSON in a text field in the hidden admin page. I use a similar approach in several of my modules, including menu builder.

Just my 2p.

  • Like 3
Link to comment
Share on other sites

7 hours ago, kongondo said:

I'm wondering whether it is really worth the effort since you'd have to hook into the module class (I think), to catch the upload and save it to your admin page.

After reading a bit the source code, I found that the module edit form can be altered by hooking to ProcessModule::executeEdit and append the hidden admin page fields to the output form. For saving the module, we can hook to Modules::saveModuleConfigData to save the hidden page fields there. But for the below reason, I would stick to process module instead. I may try this approach next time.

 

8 hours ago, kongondo said:

Will this module be accessible to non-superusers?

I get your point. I can give process module a permission, but individual module edit page cannot (is it correct?). This is a real benefit of using process modules. Modules like SEO module should be able to let digital marketing team to edit while have them away from other module configs. 

 

8 hours ago, kongondo said:

save all text setting as one chunk of JSON in a text field in the hidden admin page.

I would use the native inputfields as I want the module to be multilingual. I am not sure should I output the ProcessPageEdit or use something else.

  • Like 1
Link to comment
Share on other sites

5 hours ago, Karl_T said:

I would use the native inputfields as I want the module to be multilingual.

Yes, makes sense.

5 hours ago, Karl_T said:

I am not sure should I output the ProcessPageEdit or use something else.

Since the site is multilingual (but also depending on the number of fields and their complexity), no need to reinvent the wheel here, IMO. I'd output the ProcessPageEdit form. I can show you how if you don't know how to do this.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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