Sean Dinwiddie

Text input in ProcessHello

Recommended Posts

Hi Sean:

This is a basic example of how to create a module that has configurable fields.

<?php

class Example extends Process implements Module, ConfigurableModule {
	

    private static $pathDir;
    
	/**
	 * getModuleInfo is a module required by all modules to tell ProcessWire about them
	 *
	 * @return array
	 *
	 */
	public static function getModuleInfo() {

		return array(

			// The module's title, typically a little more descriptive than the class name
			'title' => 'Example Module', 

			// version number 
			'version' => '0.0.1', 

			// summary is brief description of what this module is
			'summary' => 'This module descripton.',
			
			// author
			'author' => 'Author Name',
			
			// singular=true: indicates that only one instance of the module is allowed.
			// This is usually what you want for modules that attach hooks. 
			'singular' => true, 

			// autoload=true: indicates the module should be started with ProcessWire.
			// This is necessary for any modules that attach runtime hooks, otherwise those
			// hooks won't get attached unless some other code calls the module on it's own.
			// Note that autoload modules are almost always also 'singular' (seen above).
			'autoload' => true,
			
			// If true, the module may not be uninstalled once installed.
            'permanent' => false,
            
			'page' => array( 			// optionally install/uninstall a page for this process automatically
                'name' => 'example-module', 	// name of page to create
                'parent' => '', 	// parent name (under admin) or omit or blank to assume admin root
                'title' => 'Example Module', 	// title of page, or omit to use the title already specified above
            ),
			
			'permission' => 'example-module',
			
			'requires' => array('PHP>=5.4.1', 'ProcessWire>=2.7.0'),
			
			'icon' => 'film', // module icon
			
		);
	}
    
    public static function getModuleConfigInputfields(array $data) {
        
        // ------------------------------------------------------------------------
        // Initialize InputField wrapper
        // ------------------------------------------------------------------------
        $fields             = new InputfieldWrapper(); 
        
        // ------------------------------------------------------------------------
        // Define text input field for the directory path.
        // ------------------------------------------------------------------------
        $field              = wire('modules')->get('InputfieldText');
        $field->name        = 'pathDirectory';
        $field->label       = __('Directory Videos');
        $field->required    = true; 
        $field->columnWidth = 50;
        $field->value       = (!empty($data['pathDirectory']) ? rtrim($data['pathDirectory'],"/")."/" : '/var/www/html/videos/');
        $field->description = __('Description Field.');
        $fields->add($field); 
        
        
        // ------------------------------------------------------------------------
        // Return of the fields.
        // ------------------------------------------------------------------------
        return $fields; 
    }
	
	public function ___install() {
		parent::___install();
	}
	
	/**
	 * Initialize the module
	 *
	 * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called
	 * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. 
	 *
	 */
	public function init() {
        
        // Variable from module settings
		self::$pathDir = $this->pathDirectory;
		
	}
	
	/**
	 * Executed when root url for module is accessed
	 *
	 */
	public function ___execute() {

        $preview = $this->modules->get("InputfieldMarkup");
        $preview->value .= "<h2>echo " . $this->pathDirectory . "</h2>";
        return $preview->render();
        
	}
}

 

  • Like 3

Share this post


Link to post
Share on other sites

Okay, so the Processhello module does have a savable text input field, but the input field is at the module's settings page; that might be good enough for now.

Share this post


Link to post
Share on other sites
9 hours ago, theo said:

Hello,

What is the purpose of this module?

This module eventually( as it gets developed ) will be for company/brand details. :rolleyes:

We have been using a special page with lots of custom fields.

This will be more standardized.

Thank you for asking.

Share this post


Link to post
Share on other sites

Or use SettingsFactory for your settings page if it can support the fields you need.

 

  • Like 1

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.