From 8292e7d8f0361e884a03e87056a00802e819da9e Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Tue, 22 Aug 2023 11:13:02 -0400 Subject: [PATCH] Update for processwire/processwire-issues#1467 --- .../Fieldtype/FieldtypeSelector.module | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/wire/modules/Fieldtype/FieldtypeSelector.module b/wire/modules/Fieldtype/FieldtypeSelector.module index 6fd7a911..202f24c0 100644 --- a/wire/modules/Fieldtype/FieldtypeSelector.module +++ b/wire/modules/Fieldtype/FieldtypeSelector.module @@ -7,7 +7,7 @@ * Code by Ryan Cramer * Sponsored by Avoine * - * ProcessWire 3.x, Copyright 2016 by Ryan Cramer + * ProcessWire 3.x, Copyright 2023 by Ryan Cramer * https://processwire.com * */ @@ -20,22 +20,19 @@ class FieldtypeSelector extends Fieldtype { 'version' => 13, 'summary' => 'Build a page finding selector visually.', 'author' => 'Avoine + ProcessWire', - ); - } - - public function init() { - parent::init(); + ); } public function getInputfield(Page $page, Field $field) { - $inputfield = $this->wire('modules')->get('InputfieldSelector'); + /** @var InputfieldSelector $inputfield */ + $inputfield = $this->wire()->modules->get('InputfieldSelector'); $inputfield->initValue = $field->get('initValue'); return $inputfield; } public function ___getCompatibleFieldtypes(Field $field) { $fieldtypes = $this->wire(new Fieldtypes()); - foreach($this->wire('fieldtypes') as $fieldtype) { + foreach($this->wire()->fieldtypes as $fieldtype) { if($fieldtype instanceof FieldtypeText || $fieldtype instanceof FieldtypeSelector) { $fieldtypes->add($fieldtype); } @@ -52,15 +49,16 @@ class FieldtypeSelector extends Fieldtype { } public function ___sleepValue(Page $page, Field $field, $value) { - $initValue = trim($field->get('initValue')); + $initValue = trim((string) $field->get('initValue')); + $value = (string) $value; if(strlen($initValue) && strpos($value, $initValue) === 0) { - $value = trim(substr($value, strlen($initValue)+1), ', '); + $value = trim((string) substr($value, strlen($initValue)+1), ', '); } return parent::___sleepValue($page, $field, $value); } public function ___wakeupValue(Page $page, Field $field, $value) { - $value = parent::___wakeupValue($page, $field, $value); + $value = (string) parent::___wakeupValue($page, $field, $value); $initValue = trim((string) $field->get('initValue')); if(strlen($initValue) && strpos($value, $initValue) === false) { $value = "$initValue, $value"; @@ -77,7 +75,7 @@ class FieldtypeSelector extends Fieldtype { */ public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); - $len = $this->wire('database')->getMaxIndexLength(); + $len = $this->wire()->database->getMaxIndexLength(); $schema['data'] = 'text NOT NULL'; $schema['keys']['data_exact'] = "KEY `data_exact` (`data`($len))"; $schema['keys']['data'] = 'FULLTEXT KEY `data` (`data`)';