1919use Ibexa \Rest \Message ;
2020use Ibexa \Rest \Server \Controller as RestController ;
2121use Ibexa \Rest \Server \Values ;
22+ use JMS \TranslationBundle \Annotation \Ignore ;
2223use Symfony \Component \HttpFoundation \RedirectResponse ;
2324use Symfony \Component \HttpFoundation \Request ;
2425use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
26+ use Symfony \Contracts \Translation \TranslatorInterface ;
2527
2628final class FieldDefinitionController extends RestController
2729{
28- /** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */
29- private $ contentTypeService ;
30+ private ContentTypeService $ contentTypeService ;
3031
31- /** @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface */
32- private $ urlGenerator ;
32+ private UrlGeneratorInterface $ urlGenerator ;
3333
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+ ) {
3641 $ this ->contentTypeService = $ contentTypeService ;
3742 $ this ->urlGenerator = $ urlGenerator ;
43+ $ this ->translator = $ translator ;
3844 }
3945
4046 public function addFieldDefinitionAction (
@@ -59,7 +65,9 @@ public function addFieldDefinitionAction(
5965
6066 $ fieldDefinitionCreateStruct ->fieldGroup = $ input ->fieldGroupIdentifier ;
6167 $ fieldDefinitionCreateStruct ->names = [
62- $ language ->languageCode => 'New field type ' ,
68+ $ language ->languageCode => strtr ('New %name% ' , [
69+ '%name% ' => $ this ->getFieldTypeLabel ($ input ->fieldTypeIdentifier ),
70+ ]),
6371 ];
6472
6573 $ fieldDefinitionCreateStruct ->position = $ input ->position ?? $ this ->getNextFieldPosition ($ contentTypeDraft );
@@ -167,4 +175,19 @@ private function getNextFieldPosition(ContentType $contentType): int
167175
168176 return 0 ;
169177 }
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+ }
170193}
0 commit comments