Process Module (ProcessWire): Unterschied zwischen den Versionen
| Zeile 7: | Zeile 7: | ||
* Process Module erweitern die Funktionalität im Admin Bereich. | * Process Module erweitern die Funktionalität im Admin Bereich. | ||
* In der Regel erstellt das Modul eine Seite im Admin Zweig des Seitenbaums. So kann man über das Menü zugreifen. | * In der Regel erstellt das Modul eine Seite im Admin Zweig des Seitenbaums. So kann man über das Menü zugreifen. | ||
| − | === execute() === | + | === Seitenausgabe mit execute() === |
* eine execute (oder ___execute mit Hook) Funktion gibt den Output der Seite | * eine execute (oder ___execute mit Hook) Funktion gibt den Output der Seite | ||
* Output für Unterseiten erzeugt man mit executeUnterseite (ergibt dann z.B. setup/meinModul/Unterseite | * Output für Unterseiten erzeugt man mit executeUnterseite (ergibt dann z.B. setup/meinModul/Unterseite | ||
Version vom 30. November 2020, 20:48 Uhr
Links
ProcessWire - Module schreiben https://github.com/ryancramerdesign/ProcessHello/blob/master/ProcessHello.info.php - Beispiel Process Modul https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/ - Gutes Tutorial von Bernhard Baumrock
Basics
- Process Module erweitern die Funktionalität im Admin Bereich.
- In der Regel erstellt das Modul eine Seite im Admin Zweig des Seitenbaums. So kann man über das Menü zugreifen.
Seitenausgabe mit execute()
- eine execute (oder ___execute mit Hook) Funktion gibt den Output der Seite
- Output für Unterseiten erzeugt man mit executeUnterseite (ergibt dann z.B. setup/meinModul/Unterseite
executeMySecondPage translates to my-second-page in the URL executeMysecondpage translates to mysecondpage in the URL
Admin Bereich anpassen
Vorsicht mit dem Namespace. Wenn er sich in den Dateien unterscheidet, verarbeitet PW die config Dateien nicht richtig. Bei mir hat es ohne Namespace in allen Dateien funktioniert.
Seiten im Admin Hinzufügen
Geht über die getModuleInfo Funktion oder über die MeinModul.Info.php Konfigurationsdatei (siehe Beispiel Modul)
// page that you want created to execute this module 'page' => array( 'name' => 'helloworld', 'parent' => 'setup', 'title' => 'Hello World' ),
Wie bei zusätzlicher Seite
// optional extra navigation that appears in admin // if you change this, you'll need to a Modules > Refresh to see changes 'nav' => array( array( 'url' => '', 'label' => 'Hello', 'icon' => 'smile-o', ), array( 'url' => 'something/', 'label' => 'Something', 'icon' => 'beer', ), )
Man kann auch die Option
'useNavJSON' => true,
setzen, dann kann man über die Funktion
public function ___executeNavJSON(array $options = array())
aufwändigere Dinge realisieren (Beispiel in Adrians ProcessAdminActions)
Zugriff regeln
Ebenso lassen sich Permissions definieren
// name of permission required of users to execute this Process (optional) 'permission' => 'helloworld', // permissions that you want automatically installed/uninstalled with this module (name => description) 'permissions' => array( 'helloworld' => 'Run the HelloWorld module' ),
Modul Konfiguration hinzufügen
Seit 2.5.5 über eine .config.php Datei möglich. Die Datei lautet wie die Moduldatei aber mit angehängtem .config und die Klasse darin erweitert die Klasse ModuleConfig.
https://processwire.com/blog/posts/new-module-configuration-options/#enter-the-new-moduleconfig-class
Beispiel mit Funktionen
class TestConfig extends ModuleConfig {
public function getDefaults() {
return array(
'fullname' => '',
'color' => 'blue',
'age' => 40,
);
}
public function getInputfields() {
$inputfields = parent::getInputfields();
$f = $this->modules->get('InputfieldText');
$f->attr('name', 'fullname');
$f->label = 'Full Name';
$f->required = true;
$inputfields->add($f);
$f = $this->modules->get('InputfieldSelect');
$f->attr('name', 'color');
$f->label = 'Favorite Color';
$f->options = array(
'red' => 'Red',
'green' => 'Green',
'blue' => 'Blue'
);
$inputfields->add($f);
$f = $this->modules->get('InputfieldInteger');
$f->attr('name', 'age');
$f->label = 'Your Age';
$inputfields->add($f);
return $inputfields;
}
}
Beispiel aus dem ProcessHello Modul mit assoziativem Array
ProcessHello.config.php
<?php
/**
* Configure the Hello World module
*
* This type of configuration method requires ProcessWire 2.5.5 or newer.
* For backwards compatibility with older versions of PW, you'll want to
* instead want to look into the getModuleConfigInputfields() method, which
* is specified with the .module file. So we are assuming you only need to
* support PW 2.5.5 or newer here.
*
* For more about configuration methods, see here:
* http://processwire.com/blog/posts/new-module-configuration-options/
*
*
*/
class ProcessHelloConfig extends ModuleConfig {
public function __construct() {
$this->add(array(
// Text field: greeting
array(
'name' => 'greeting', // name of field
'type' => 'text', // type of field (any Inputfield module name)
'label' => $this->_('Hello Greeting'), // field label
'description' => $this->_('What would you like to say to people using this module?'),
'required' => true,
'value' => $this->_('A very happy hello world to you.'), // default value
),
// Radio buttons: greetingType
array(
'name' => 'greetingType',
'type' => 'radios',
'label' => $this->_('Greeting Type'),
'options' => array(
// options array of value => label
'message' => $this->_('Message'),
'warning' => $this->_('Warning'),
'error' => $this->_('Error'),
),
'value' => 'warning', // default value
'optionColumns' => 1, // make options display on one line
'notes' => $this->_('Choose wisely'), // like description but appears under field
)
));
}
}