Skip to content

Commit 12530b4

Browse files
thomasrawielmschwemer
authored andcommitted
[FEATURE] Provide autocomplete functionality
Forward port from v12 to v13 Thanks to Thomas Rawiel for all the work Related: #789 Related: #1233
1 parent d888bbf commit 12530b4

File tree

17 files changed

+875
-95
lines changed

17 files changed

+875
-95
lines changed

Classes/Domain/Model/Field.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ class Field extends AbstractEntity
8585

8686
protected string $mandatoryText = '';
8787

88+
/**
89+
* @var string
90+
*/
91+
protected string $autocompleteToken = '';
92+
93+
/**
94+
* @var string
95+
*/
96+
protected string $autocompleteSection = '';
97+
98+
/**
99+
* @var string
100+
*/
101+
protected string $autocompleteType = '';
102+
103+
/**
104+
* @var string
105+
*/
106+
protected string $autocompletePurpose = '';
107+
88108
/**
89109
* @var Page
90110
* This property can hold Page|int|null (depending on the context). "@var" must set to Page for property mapping.
@@ -643,4 +663,78 @@ protected function getExportableTypesFromTypoScript(): array
643663

644664
return $types;
645665
}
666+
667+
/**
668+
* @return string
669+
*/
670+
public function getAutocompleteToken(): string
671+
{
672+
return $this->autocompleteToken;
673+
}
674+
675+
/**
676+
* @param string $autocompleteToken
677+
*
678+
* @return void
679+
*/
680+
public function setAutocompleteToken(string $autocompleteToken): void
681+
{
682+
$this->autocompleteToken = $autocompleteToken;
683+
}
684+
685+
/**
686+
* @return string
687+
*/
688+
public function getAutocompleteSection(): string
689+
{
690+
return $this->autocompleteSection;
691+
}
692+
693+
/**
694+
* @param string $autocompleteSection
695+
*
696+
* @return void
697+
*/
698+
public function setAutocompleteSection(string $autocompleteSection): void
699+
{
700+
$this->autocompleteSection = $autocompleteSection;
701+
}
702+
703+
/**
704+
* @return string
705+
*/
706+
public function getAutocompleteType(): string
707+
{
708+
return $this->autocompleteType;
709+
}
710+
711+
/**
712+
* @param string $autocompleteType
713+
*
714+
* @return void
715+
*/
716+
public function setAutocompleteType(string $autocompleteType): void
717+
{
718+
$this->autocompleteType = $autocompleteType;
719+
}
720+
721+
/**
722+
* @return string
723+
*/
724+
public function getAutocompletePurpose(): string
725+
{
726+
return $this->autocompletePurpose;
727+
}
728+
729+
/**
730+
* @param string $autocompletePurpose
731+
*
732+
* @return void
733+
*/
734+
public function setAutocompletePurpose(string $autocompletePurpose): void
735+
{
736+
$this->autocompletePurpose = $autocompletePurpose;
737+
}
738+
739+
646740
}

Classes/Domain/Model/Form.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class Form extends AbstractEntity
4040
*/
4141
protected array $pagesByUid = [];
4242

43+
protected string $autocompleteToken = '';
44+
45+
/**
46+
* @return string
47+
*/
4348
public function getTitle(): string
4449
{
4550
return $this->title;
@@ -195,4 +200,22 @@ protected function isCorrectFieldType(Field $field, string $fieldType): bool
195200

196201
return false;
197202
}
203+
204+
/**
205+
* @return string
206+
*/
207+
public function getAutocompleteToken(): string
208+
{
209+
return $this->autocompleteToken;
210+
}
211+
212+
/**
213+
* @param string $autocompleteToken
214+
*
215+
* @return void
216+
*/
217+
public function setAutocompleteToken(string $autocompleteToken): void
218+
{
219+
$this->autocompleteToken = $autocompleteToken;
220+
}
198221
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace In2code\Powermail\Tca;
5+
6+
/**
7+
* Class AddAutocompleteTokens
8+
* @package In2code\Powermail\Tca
9+
*/
10+
class AddAutocompleteTokens
11+
{
12+
/**
13+
* @var string
14+
*/
15+
public static string $LLL = 'LLL:EXT:powermail/Resources/Private/Language/locallang_db.xlf:autocomplete_token.';
16+
17+
/**
18+
* @param array $config
19+
*
20+
* @return void
21+
*/
22+
public function getAutocompleteTokens(array &$config)
23+
{
24+
if ($config['config']['itemsProcConfig']['useDefaultItems'] ?? true) {
25+
$defaultSelectItems = self::getDefaultAutocompleteTokens();
26+
$config['items'] = array_merge(
27+
$config['items'],
28+
$defaultSelectItems
29+
);
30+
}
31+
}
32+
33+
/**
34+
* https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field
35+
* @return array[]
36+
*/
37+
public static function getDefaultAutocompleteTokens(): array
38+
{
39+
return [
40+
['label' => self::$LLL . 'name', 'value' => 'name', 'icon' => '', 'group' => 'name'],
41+
['label' => self::$LLL . 'honorific-prefix', 'value' => 'honorific-prefix', 'icon' => '', 'group' => 'name'],
42+
['label' => self::$LLL . 'given-name', 'value' => 'given-name', 'icon' => '', 'group' => 'name'],
43+
['label' => self::$LLL . 'additional-name', 'value' => 'additional-name', 'icon' => '', 'group' => 'name'],
44+
['label' => self::$LLL . 'family-name', 'value' => 'family-name', 'icon' => '', 'group' => 'name'],
45+
['label' => self::$LLL . 'honorific-suffix', 'value' => 'honorific-suffix', 'icon' => '', 'group' => 'name'],
46+
['label' => self::$LLL . 'nickname', 'value' => 'nickname', 'icon' => '', 'group' => 'name'],
47+
['label' => self::$LLL . 'sex', 'value' => 'sex', 'icon' => '', 'group' => 'name'],
48+
['label' => self::$LLL . 'email', 'value' => 'email', 'icon' => '', 'group' => 'contact'],
49+
['label' => self::$LLL . 'impp', 'value' => 'impp', 'icon' => '', 'group' => 'contact'],
50+
['label' => self::$LLL . 'url', 'value' => 'url', 'icon' => '', 'group' => 'contact'],
51+
['label' => self::$LLL . 'organization-title', 'value' => 'organization-title', 'icon' => '', 'group' => 'contact'],
52+
['label' => self::$LLL . 'organization', 'value' => 'organization', 'icon' => '', 'group' => 'contact'],
53+
['label' => self::$LLL . 'street-address', 'value' => 'street-address', 'icon' => '', 'group' => 'contact'],
54+
['label' => self::$LLL . 'country', 'value' => 'country', 'icon' => '', 'group' => 'contact'],
55+
['label' => self::$LLL . 'country-name', 'value' => 'country-name', 'icon' => '', 'group' => 'contact'],
56+
['label' => self::$LLL . 'postal-code', 'value' => 'postal-code', 'icon' => '', 'group' => 'contact'],
57+
['label' => self::$LLL . 'address-line1', 'value' => 'address-line1', 'icon' => '', 'group' => 'address'],
58+
['label' => self::$LLL . 'address-line2', 'value' => 'address-line2', 'icon' => '', 'group' => 'address'],
59+
['label' => self::$LLL . 'address-line3', 'value' => 'address-line3', 'icon' => '', 'group' => 'address'],
60+
['label' => self::$LLL . 'address-level1', 'value' => 'address-level1', 'icon' => '', 'group' => 'address'],
61+
['label' => self::$LLL . 'address-level2', 'value' => 'address-level2', 'icon' => '', 'group' => 'address'],
62+
['label' => self::$LLL . 'address-level3', 'value' => 'address-level3', 'icon' => '', 'group' => 'address'],
63+
['label' => self::$LLL . 'address-level4', 'value' => 'address-level4', 'icon' => '', 'group' => 'address'],
64+
['label' => self::$LLL . 'tel', 'value' => 'tel', 'icon' => '', 'group' => 'tel'],
65+
['label' => self::$LLL . 'tel-country-code', 'value' => 'tel-country-code', 'icon' => '', 'group' => 'tel'],
66+
['label' => self::$LLL . 'tel-area-code', 'value' => 'tel-area-code', 'icon' => '', 'group' => 'tel'],
67+
['label' => self::$LLL . 'tel-national', 'value' => 'tel-national', 'icon' => '', 'group' => 'tel'],
68+
['label' => self::$LLL . 'tel-local', 'value' => 'tel-local', 'icon' => '', 'group' => 'tel'],
69+
['label' => self::$LLL . 'tel-local-prefix', 'value' => 'tel-local-prefix', 'icon' => '', 'group' => 'tel'],
70+
['label' => self::$LLL . 'tel-local-suffix', 'value' => 'tel-local-suffix', 'icon' => '', 'group' => 'tel'],
71+
['label' => self::$LLL . 'tel-extension', 'value' => 'tel-extension', 'icon' => '', 'group' => 'tel'],
72+
['label' => self::$LLL . 'username', 'value' => 'username', 'icon' => '', 'group' => 'user'],
73+
['label' => self::$LLL . 'new-password', 'value' => 'new-password', 'icon' => '', 'group' => 'user'],
74+
['label' => self::$LLL . 'current-password', 'value' => 'current-password', 'icon' => '', 'group' => 'user'],
75+
['label' => self::$LLL . 'one-time-code', 'value' => 'one-time-code', 'icon' => '', 'group' => 'user'],
76+
['label' => self::$LLL . 'bday', 'value' => 'bday', 'icon' => '', 'group' => 'bday'],
77+
['label' => self::$LLL . 'bday-day', 'value' => 'bday-day', 'icon' => '', 'group' => 'bday'],
78+
['label' => self::$LLL . 'bday-month', 'value' => 'bday-month', 'icon' => '', 'group' => 'bday'],
79+
['label' => self::$LLL . 'bday-year', 'value' => 'bday-year', 'icon' => '', 'group' => 'bday'],
80+
['label' => self::$LLL . 'cc-name', 'value' => 'cc-name', 'icon' => '', 'group' => 'cc'],
81+
['label' => self::$LLL . 'cc-given-name', 'value' => 'cc-given-name', 'icon' => '', 'group' => 'cc'],
82+
['label' => self::$LLL . 'cc-additional-name', 'value' => 'cc-additional-name', 'icon' => '', 'group' => 'cc'],
83+
['label' => self::$LLL . 'cc-family-name', 'value' => 'cc-family-name', 'icon' => '', 'group' => 'cc'],
84+
['label' => self::$LLL . 'cc-number', 'value' => 'cc-number', 'icon' => '', 'group' => 'cc'],
85+
['label' => self::$LLL . 'cc-exp', 'value' => 'cc-exp', 'icon' => '', 'group' => 'cc'],
86+
['label' => self::$LLL . 'cc-exp-month', 'value' => 'cc-exp-month', 'icon' => '', 'group' => 'cc'],
87+
['label' => self::$LLL . 'cc-exp-year', 'value' => 'cc-exp-year', 'icon' => '', 'group' => 'cc'],
88+
['label' => self::$LLL . 'cc-csc', 'value' => 'cc-csc', 'icon' => '', 'group' => 'cc'],
89+
['label' => self::$LLL . 'cc-type', 'value' => 'cc-type', 'icon' => '', 'group' => 'cc'],
90+
['label' => self::$LLL . 'transaction-currency', 'value' => 'transaction-currency', 'icon' => '', 'group' => 'cc'],
91+
['label' => self::$LLL . 'transaction-amount', 'value' => 'transaction-amount', 'icon' => '', 'group' => 'cc'],
92+
['label' => self::$LLL . 'language', 'value' => 'language', 'icon' => '', 'group' => 'other'],
93+
['label' => self::$LLL . 'photo', 'value' => 'photo', 'icon' => '', 'group' => 'other'],
94+
];
95+
}
96+
}

0 commit comments

Comments
 (0)