1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-14 02:34:24 +02:00
This commit is contained in:
Ryan Cramer
2023-08-22 11:13:02 -04:00
parent 359c048862
commit 8292e7d8f0

View File

@@ -7,7 +7,7 @@
* Code by Ryan Cramer * Code by Ryan Cramer
* Sponsored by Avoine * Sponsored by Avoine
* *
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
*/ */
@@ -20,22 +20,19 @@ class FieldtypeSelector extends Fieldtype {
'version' => 13, 'version' => 13,
'summary' => 'Build a page finding selector visually.', 'summary' => 'Build a page finding selector visually.',
'author' => 'Avoine + ProcessWire', 'author' => 'Avoine + ProcessWire',
); );
}
public function init() {
parent::init();
} }
public function getInputfield(Page $page, Field $field) { 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'); $inputfield->initValue = $field->get('initValue');
return $inputfield; return $inputfield;
} }
public function ___getCompatibleFieldtypes(Field $field) { public function ___getCompatibleFieldtypes(Field $field) {
$fieldtypes = $this->wire(new Fieldtypes()); $fieldtypes = $this->wire(new Fieldtypes());
foreach($this->wire('fieldtypes') as $fieldtype) { foreach($this->wire()->fieldtypes as $fieldtype) {
if($fieldtype instanceof FieldtypeText || $fieldtype instanceof FieldtypeSelector) { if($fieldtype instanceof FieldtypeText || $fieldtype instanceof FieldtypeSelector) {
$fieldtypes->add($fieldtype); $fieldtypes->add($fieldtype);
} }
@@ -52,15 +49,16 @@ class FieldtypeSelector extends Fieldtype {
} }
public function ___sleepValue(Page $page, Field $field, $value) { 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) { 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); return parent::___sleepValue($page, $field, $value);
} }
public function ___wakeupValue(Page $page, Field $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')); $initValue = trim((string) $field->get('initValue'));
if(strlen($initValue) && strpos($value, $initValue) === false) { if(strlen($initValue) && strpos($value, $initValue) === false) {
$value = "$initValue, $value"; $value = "$initValue, $value";
@@ -77,7 +75,7 @@ class FieldtypeSelector extends Fieldtype {
*/ */
public function getDatabaseSchema(Field $field) { public function getDatabaseSchema(Field $field) {
$schema = parent::getDatabaseSchema($field); $schema = parent::getDatabaseSchema($field);
$len = $this->wire('database')->getMaxIndexLength(); $len = $this->wire()->database->getMaxIndexLength();
$schema['data'] = 'text NOT NULL'; $schema['data'] = 'text NOT NULL';
$schema['keys']['data_exact'] = "KEY `data_exact` (`data`($len))"; $schema['keys']['data_exact'] = "KEY `data_exact` (`data`($len))";
$schema['keys']['data'] = 'FULLTEXT KEY `data` (`data`)'; $schema['keys']['data'] = 'FULLTEXT KEY `data` (`data`)';