1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 18:24:57 +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
* Sponsored by Avoine
*
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com
*
*/
@@ -23,19 +23,16 @@ class FieldtypeSelector extends Fieldtype {
);
}
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`)';