19
19
use Ibexa \Rest \Message ;
20
20
use Ibexa \Rest \Server \Controller as RestController ;
21
21
use Ibexa \Rest \Server \Values ;
22
+ use JMS \TranslationBundle \Annotation \Ignore ;
22
23
use Symfony \Component \HttpFoundation \RedirectResponse ;
23
24
use Symfony \Component \HttpFoundation \Request ;
24
25
use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
26
+ use Symfony \Contracts \Translation \TranslatorInterface ;
25
27
26
28
final class FieldDefinitionController extends RestController
27
29
{
28
- /** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */
29
- private $ contentTypeService ;
30
+ private ContentTypeService $ contentTypeService ;
30
31
31
- /** @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface */
32
- private $ urlGenerator ;
32
+ private UrlGeneratorInterface $ urlGenerator ;
33
33
34
- public function __construct (ContentTypeService $ contentTypeService , UrlGeneratorInterface $ urlGenerator )
35
- {
34
+ private TranslatorInterface $ translator ;
35
+
36
+ public function __construct (
37
+ ContentTypeService $ contentTypeService ,
38
+ UrlGeneratorInterface $ urlGenerator ,
39
+ TranslatorInterface $ translator
40
+ ) {
36
41
$ this ->contentTypeService = $ contentTypeService ;
37
42
$ this ->urlGenerator = $ urlGenerator ;
43
+ $ this ->translator = $ translator ;
38
44
}
39
45
40
46
public function addFieldDefinitionAction (
@@ -59,7 +65,9 @@ public function addFieldDefinitionAction(
59
65
60
66
$ fieldDefinitionCreateStruct ->fieldGroup = $ input ->fieldGroupIdentifier ;
61
67
$ fieldDefinitionCreateStruct ->names = [
62
- $ language ->languageCode => 'New field type ' ,
68
+ $ language ->languageCode => strtr ('New %name% ' , [
69
+ '%name% ' => $ this ->getFieldTypeLabel ($ input ->fieldTypeIdentifier ),
70
+ ]),
63
71
];
64
72
65
73
$ fieldDefinitionCreateStruct ->position = $ input ->position ?? $ this ->getNextFieldPosition ($ contentTypeDraft );
@@ -167,4 +175,19 @@ private function getNextFieldPosition(ContentType $contentType): int
167
175
168
176
return 0 ;
169
177
}
178
+
179
+ /**
180
+ * Generate a human-readable name for field type identifier.
181
+ */
182
+ private function getFieldTypeLabel (string $ fieldTypeIdentifier ): string
183
+ {
184
+ $ name = $ this ->translator ->trans (
185
+ /** @Ignore */
186
+ $ fieldTypeIdentifier . '.name ' ,
187
+ [],
188
+ 'ibexa_fieldtypes '
189
+ );
190
+
191
+ return mb_strtolower ($ name );
192
+ }
170
193
}
0 commit comments