thei Posted 1 hour ago Posted 1 hour ago Hello, i am trying to develop a simple Fieldtype module and followed Tutorial on developing a Fieldtype module. I installed the module (Fieldtype and Inputfield) created a field of that type, add such a field to a template and edited a page. After entering values and click save button the method processInput() is invoked but then nothing happens, sleepValue() and wakeupValue() are never invoked, the resulting editor page ends up showing empty entry fields. What i'm getting wrong? <?php namespace ProcessWire; class InputfieldTimeframe extends Inputfield { /** * getModuleInfo is a module required by all modules to tell ProcessWire about them. * Information about your module and some settings and definition of module dependcies * @return array */ public static function getModuleinfo() { return [ 'title' => __('Inputfield Timeframe', __FILE__), 'summary' => __('Inputfield for start date and end date', __FILE__), 'author' => 'T. Heinlein', 'version' => "0.1.2", 'icon' => 'calendar', 'permanent' => false, 'requires' => [ 'PHP>=8.0.0', 'ProcessWire>=3.0.244', 'FieldtypeTimeframe' ], ]; } public function __construct() { parent::__construct(); } public function ___render() { $value = $this->attr('value'); $field = $this->field; $html = "<div class='interval'>" . "<input type='date' name='datefrom'>" . "<input type='date' name='dateto'>" . "</div>"; return "<div style='border:solid 1px red;'>$html</div>"; } public function renderValue() { $value = $this->attr('value'); return "$value"; // TODO: locale format } public function ___processInput(WireInputData $input) :self { $value = $this->attr('value'); $input->datefrom = trim($input->datefrom); $input->dateto = trim($input->dateto); $value['datefrom'] = $input->datefrom; $value['dateto'] = $input->dateto; bd($value, "processInput"); return $this; } } <?php namespace ProcessWire; class FieldtypeTimeframe extends Fieldtype { /** * getModuleInfo is a module required by all modules to tell ProcessWire about them. * Information about your module and some settings and definition of module dependcies * @return array */ public static function getModuleinfo() { return [ 'title' => __('Timeframe', __FILE__), 'summary' => __('Fieldtype representing a timeframe with start and end date', __FILE__), 'author' => 'T. Heinlein', 'version' => "0.1.1", 'icon' => 'calendar', 'installs' => 'InputfieldTimeframe', 'requires' => [ 'PHP>=8.0.0', 'ProcessWire>=3.0.244' ] ]; } public function __construct() { parent::__construct(); } /** * define the table columns needed for that field type AND an additional column 'data' for a primary key. * (this is low level input for the database) * *** this method MUST be implemented when writing a custom fieldtype */ public function getDatabaseSchema(Field $field) : array { $schema = parent::getDatabaseSchema($field); $schema['data'] = 'varchar(64) NOT NULL'; /* data is required field for system purposes */ $schema['datefrom'] = 'date'; $schema['dateto'] = 'date'; return $schema; } public function ___sleepValue(Page $page, Field $field, $value) { bd($value, "sleepValue"); $df = $value['datefrom']; $dt = $value['dateto']; $res = ['datefrom'=> $df, 'dateto' => $dt]; return $res; } public function wakeupValue(Page $page, Field $field, $value) { bd($value, "wakeupValue"); return $value; } public function getBlankValue(Page $page, Field $field) { return array(); } public function getInputfield(Page $page, Field $field) { $inputfield = $this->wire('modules')->get('InputfieldTimeframe'); $inputfield->class = $this->className(); /* adds the class name as a css class to the wrapper element */ $pageValue = $page->get($field->name); $inputfield->setAttribute('value', $pageValue); return $inputfield; } /** * @param Page $page * @param Field $field * @param int|object|WireArray|string $value * @return int|null|object|OpeningHours|WireArray|string * will be called on before sleepValue and after wakeupValue */ public function sanitizeValue(Page $page, Field $field, $value) { if (! is_array($value) ) { $value = $this->getBlankValue($page, $field); } return $value; } }
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now