Jump to content

How to use InputfieldImage as Configurable input field under a module


Gayan Virajith
 Share

Recommended Posts

Hello Processwire, 

First of all thank you for a wonderful CMS. This would be my first question to the Processwire community as I started with it.

I am trying to create module which can keep site logo as a configurable input field. I use following code to create InputFieldImage and still no luck.  :( 

public static function getModuleConfigInputfields(array $data) {
   $field = wire('modules')->get('InputfieldImage');
   $field->name = 'siteLogo';
   $field->label = "Site Logo";
   $field->maxFiles = 1;

   if(isset($data['siteLogo'])) $field->value = $data['siteLogo'];

   $inputfields->add($field);

   return $inputfields;
}

Any advise will be greatly appreciated.

Thanks again.

  • Like 1
Link to comment
Share on other sites

Thanks Soma and RJay.

This would be my module script:

class SiteSettings extends WireData implements Module, ConfigurableModule {

    public static function getModuleInfo() {

        return array(
            'title' => 'Site settings',
            'version' => 0.01,
            'summary' => 'Store general site settings',
            'author' => 'Gayan Virajith',
            'singular' => true,
            'autoload' => true,
        );
    }

    static public function getDefaultData() {
        return array(
            'siteLogo' => '',
        );
    }

    public function __construct() {
        foreach(self::getDefaultData() as $key => $value) {
            $this->$key = $value;
        }
    }

    public function init() {
        //do it later
    }

    public static function getModuleConfigInputfields(array $data) {
        $inputfields = new InputfieldWrapper();

        // ask site logo image
        $field = wire('modules')->get('InputfieldImage');
        $field->name = 'siteLogo';
        $field->label = "Site Logo";
        $field->maxFiles = 1;

        if(isset($data['siteLogo'])) $field->value = $data['siteLogo'];
        $inputfields->add($field);

        return $inputfields;
    }

}

I have attached module preview as well. According to Soma's advise, I have to give up. :(

Thanks every one.

post-1911-0-05296500-1383881123_thumb.pn

  • Like 1
Link to comment
Share on other sites

In order to store a file, you need to associate it with a page. Each page has a dedicated location where it can store files. In your case, it may be better to accomplish the functionality you are after with a template (and a page using that template) rather than a module. Though if you wanted it to be a module, you could always create it as a Process module that can handle uploaded files. The ImportPagesCSV module is an example of that. But I honestly think the simplest path is to use a template.

  • Like 4
Link to comment
Share on other sites

  • 8 months later...

Hi Ryan,

this is an interesting functionality which PW can have or may need, like every website has some sort of settings.

One question is whether we can create a select of type ASM in the module configuration ?

  • Like 1
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

×
×
  • Create New...