Skip to content

Commit d92d96b

Browse files
committed
remove old locale api
1 parent fe436a1 commit d92d96b

31 files changed

+133
-350
lines changed

bundles/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/symfony/SymfonyBundleGenerator.xtend

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import org.zikula.modulestudio.generator.cartridges.symfony.controller.bundle.Me
1818
import org.zikula.modulestudio.generator.cartridges.symfony.controller.bundle.ServiceDefinitions
1919
import org.zikula.modulestudio.generator.cartridges.symfony.models.Entities
2020
import org.zikula.modulestudio.generator.cartridges.symfony.models.EntityInitializer
21-
import org.zikula.modulestudio.generator.cartridges.symfony.models.Factory
2221
import org.zikula.modulestudio.generator.cartridges.symfony.models.Repository
2322
import org.zikula.modulestudio.generator.cartridges.symfony.models.UuidStringGenerator
2423
import org.zikula.modulestudio.generator.cartridges.symfony.models.business.ListEntryValidator
@@ -94,10 +93,6 @@ class SymfonyBundleGenerator implements IGenerator {
9493
'Generating repository classes'.printIfNotTesting(fsa)
9594
new Repository().generate(it, fsa)
9695

97-
pm?.subTask('Model: Entity factory class')
98-
'Generating entity factory class'.printIfNotTesting(fsa)
99-
new Factory().generate(it, fsa)
100-
10196
pm?.subTask('Model: Entity initializer class')
10297
'Generating entity initializer class'.printIfNotTesting(fsa)
10398
new EntityInitializer().generate(it, fsa)

bundles/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/symfony/controller/ControllerLayer.xtend

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import de.guite.modulestudio.metamodel.StringRole
1010
import java.util.List
1111
import org.zikula.modulestudio.generator.application.IMostFileSystemAccess
1212
import org.zikula.modulestudio.generator.application.ImportList
13+
import org.zikula.modulestudio.generator.cartridges.symfony.controller.action.AjaxController
1314
import org.zikula.modulestudio.generator.cartridges.symfony.controller.action.InlineRedirect
1415
import org.zikula.modulestudio.generator.cartridges.symfony.controller.action.LoggableHistory
1516
import org.zikula.modulestudio.generator.cartridges.symfony.controller.action.LoggableUndelete
1617
import org.zikula.modulestudio.generator.cartridges.symfony.controller.action.MassHandling
17-
import org.zikula.modulestudio.generator.cartridges.symfony.controller.additions.AjaxController
1818
import org.zikula.modulestudio.generator.cartridges.symfony.controller.config.ConfigureActions
1919
import org.zikula.modulestudio.generator.cartridges.symfony.controller.config.ConfigureCrud
2020
import org.zikula.modulestudio.generator.cartridges.symfony.controller.config.ConfigureFields
@@ -89,14 +89,10 @@ class ControllerLayer {
8989

9090
public function __construct(
9191
TranslatorInterface $translator,
92-
protected readonly EntityFactory $entityFactory,
9392
protected readonly EntityInitializer $entityInitializer,
9493
«IF !getAllEntityFields.filter(StringField).filter[#[StringRole.COUNTRY, StringRole.CURRENCY, StringRole.LANGUAGE, StringRole.LOCALE, StringRole.TIME_ZONE].contains(role)].empty»
9594
protected readonly RequestStack $requestStack,
9695
«ENDIF»
97-
«IF hasLocaleFieldsEntity»
98-
protected readonly LocaleApiInterface $localeApi,
99-
«ENDIF»
10096
«IF hasDetailAction || hasEditAction»
10197
protected readonly EntityDisplayHelper $entityDisplayHelper,
10298
«ENDIF»
@@ -119,6 +115,10 @@ class ControllerLayer {
119115
«IF hasVisibleWorkflow»
120116
protected readonly WorkflowHelper $workflowHelper,
121117
«ENDIF»
118+
«IF hasLocaleFieldsEntity»
119+
#[Autowire(param: 'kernel.enabled_locales')]
120+
protected readonly array $enabledLocales,
121+
«ENDIF»
122122
) {
123123
$this->setTranslator($translator);
124124
}
@@ -161,7 +161,6 @@ class ControllerLayer {
161161
imports.add(entityClassName('', false))
162162
if (loggable) {
163163
imports.add(app.appNamespace + '\\Entity\\' + name.formatForCodeCapital + 'LogEntry')
164-
imports.add(app.appNamespace + '\\Entity\\Factory\\EntityFactory')
165164
}
166165
if (hasEditAction) {
167166
imports.add(app.appNamespace + '\\Form\\Handler\\' + name.formatForCodeCapital + '\\EditHandler')
@@ -208,7 +207,6 @@ class ControllerLayer {
208207
'function Symfony\\Component\\Translation\\t',
209208
'Symfony\\Contracts\\Translation\\TranslatorInterface',
210209
'Zikula\\CoreBundle\\Translation\\TranslatorTrait',
211-
app.appNamespace + '\\Entity\\Factory\\EntityFactory',
212210
app.appNamespace + '\\Entity\\Initializer\\EntityInitializer'
213211
])
214212
if (hasIndexAction || hasEditAction) {
@@ -241,7 +239,7 @@ class ControllerLayer {
241239
}
242240
imports.addAll(commonAppImports)
243241
if (hasLocaleFieldsEntity) {
244-
imports.add('Zikula\\CoreBundle\\Api\\ApiInterface\\LocaleApiInterface')
242+
imports.add('Symfony\\Component\\DependencyInjection\\Attribute\\Autowire')
245243
}
246244
if (hasListFieldsEntity) {
247245
imports.add(app.appNamespace + '\\Helper\\ListEntriesHelper')

bundles/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/symfony/controller/EventSubscribers.xtend

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ class EventSubscribers {
387387
use Symfony\Component\Workflow\WorkflowEvents;
388388
use Symfony\Contracts\Translation\TranslatorInterface;
389389
use «appNamespace»\Entity\EntityInterface;
390-
use «appNamespace»\Entity\Factory\EntityFactory;
391390
use «appNamespace»\Helper\PermissionHelper;
392391
«IF needsApproval»
393392
use «appNamespace»\Helper\NotificationHelper;

bundles/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/symfony/controller/FormHandler.xtend

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class FormHandler {
102102
def private collectCommonBaseImports(Application it) {
103103
val imports = new ImportList
104104
imports.addAll(#[
105+
'Doctrine\\OEM\\EntityManagerInterface',
105106
'Doctrine\\ORM\\EntityRepository',
106107
'Psr\\Log\\LoggerInterface',
107108
'RuntimeException',
@@ -116,7 +117,7 @@ class FormHandler {
116117
'Symfony\\Contracts\\Translation\\TranslatorInterface',
117118
'Zikula\\CoreBundle\\Translation\\TranslatorTrait',
118119
appNamespace + '\\Entity\\EntityInterface',
119-
appNamespace + '\\Entity\\Factory\\EntityFactory',
120+
appNamespace + '\\Entity\\Initializer\\EntityInitializer',
120121
appNamespace + '\\Helper\\ControllerHelper',
121122
appNamespace + '\\Helper\\ModelHelper',
122123
appNamespace + '\\Helper\\PermissionHelper',
@@ -132,7 +133,6 @@ class FormHandler {
132133
imports.add('function Symfony\\Component\\String\\s')
133134
}
134135
if (hasTranslatable) {
135-
imports.add('Zikula\\CoreBundle\\Api\\ApiInterface\\LocaleApiInterface')
136136
imports.add(appNamespace + '\\Helper\\TranslatableHelper')
137137
}
138138
if (needsApproval) {
@@ -230,13 +230,11 @@ class FormHandler {
230230
protected readonly RouterInterface $router,
231231
protected readonly LoggerInterface $logger,
232232
protected readonly Security $security,
233-
«IF hasTranslatable»
234-
protected readonly LocaleApiInterface $localeApi,
235-
«ENDIF»
236233
«IF hasNonNullableUserFields»
237234
protected readonly UserManager $userManager,
238235
«ENDIF»
239-
protected readonly EntityFactory $entityFactory,
236+
protected readonly EntityManagerInterface $entityManager,
237+
protected readonly EntityInitializer $entityInitializer,
240238
«FOR entity : entities.sortBy[name]»
241239
protected readonly «entity.name.formatForCodeCapital»RepositoryInterface $«entity.name.formatForCode»Repository,
242240
«ENDFOR»
@@ -317,7 +315,9 @@ class FormHandler {
317315
// store current uri for repeated creations
318316
$this->repeatReturnUrl = $request->getUri();
319317

320-
$this->idField = $this->entityFactory->getIdField($this->objectType);
318+
$objectType = $this->objectType;
319+
«entityMatchBlock(entities.filter[hasEditAction])»
320+
$this->idField = $this->entityManager->getClassMetadata($entityFqcn)->getSingleIdentifierFieldName();
321321

322322
// retrieve identifier of the object we wish to edit
323323
$routeParams = $request->get('_route_params', []);
@@ -533,8 +533,11 @@ class FormHandler {
533533
}
534534
535535
if (null === $entity) {
536-
$createMethod = 'create' . ucfirst($this->objectType);
537-
$entity = $this->entityFactory->$createMethod();
536+
$objectType = $this->objectType;
537+
«entityMatchBlock(entities.filter[hasEditAction])»
538+
$entity = new $entityFqcn();
539+
$initMethod = 'init' . ucfirst($objectType);
540+
$this->entityInitializer->$initMethod($entity);
538541
«IF hasTrees»
539542
if (in_array($this->objectType, ['«getTreeEntities.map[name.formatForCode].join('\', \'''], true)) {
540543
$parentId = $request->query->getInt('parent');
@@ -574,7 +577,7 @@ class FormHandler {
574577
return;
575578
}
576579
577-
if (!$this->localeApi->multilingual() || 2 > count($supportedLanguages)) {
580+
if (2 > count($supportedLanguages)) {
578581
$this->templateParameters['translationsEnabled'] = false;
579582
580583
return;

bundles/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/symfony/controller/action/ActionRoute.xtend

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class ActionRoute {
1919
extension Utils = new Utils
2020

2121
def generate(Action it) '''
22-
«actionRoute(false
23-
«actionRoute(true
22+
«/*actionRoute(false
23+
«actionRoute(true)*/»
2424
'''
2525

2626
def private dispatch actionRoute(Action it, Boolean isAdmin) '''

bundles/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/symfony/controller/additions/AjaxController.xtend renamed to bundles/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/symfony/controller/action/AjaxController.xtend

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.zikula.modulestudio.generator.cartridges.symfony.controller.additions
1+
package org.zikula.modulestudio.generator.cartridges.symfony.controller.action
22

33
import de.guite.modulestudio.metamodel.Application
44
import org.zikula.modulestudio.generator.application.IMostFileSystemAccess
@@ -43,8 +43,13 @@ class AjaxController {
4343

4444
def private commonAppImports(Application it) {
4545
val imports = newArrayList
46+
if (hasTrees || hasSortable) {
47+
imports.add('Doctrine\\ORM\\EntityManagerInterface')
48+
}
49+
if (hasTrees) {
50+
imports.add(appNamespace + '\\Entity\\Initializer\\EntityInitializer')
51+
}
4652
if (needsDuplicateCheck || hasTrees || hasSortable) {
47-
imports.add(appNamespace + '\\Entity\\Factory\\EntityFactory')
4853
for (entity : entities) {
4954
imports.add(appNamespace + '\\Repository\\' + entity.name.formatForCodeCapital + 'RepositoryInterface')
5055
}
@@ -134,13 +139,13 @@ class AjaxController {
134139
* Checks whether a field value is a duplicate or not.
135140
*/
136141
#[IsGranted('ROLE_EDITOR')]
137-
«ELSE»
142+
«/*ELSE»
138143
#[Route('/checkForDuplicate',
139144
name: '«appName.formatForDB»_ajax_checkforduplicate',
140145
methods: ['GET'],
141146
options: ['expose' => true]
142147
)]
143-
«ENDIF»
148+
*/»«ENDIF»
144149
'''
145150
146151
def private checkForDuplicateSignature(Application it) '''
@@ -220,21 +225,21 @@ class AjaxController {
220225
* Performs different operations on tree hierarchies.
221226
*/
222227
#[IsGranted('ROLE_EDITOR')]
223-
«ELSE»
228+
«/*ELSE»
224229
#[Route('/handleTreeOperation',
225230
name: '«appName.formatForDB»_ajax_handletreeoperation',
226231
methods: ['POST'],
227232
options: ['expose' => true]
228233
)]
229-
«ENDIF»
234+
*/»«ENDIF»
230235
'''
231236

232237
def private handleTreeOperationSignature(Application it) '''
233238
public function handleTreeOperation(
234239
Request $request,
235240
RouterInterface $router,
236241
LoggerInterface $logger,
237-
EntityFactory $entityFactory,
242+
EntityManagerInterface $entityManager,
238243
EntityDisplayHelper $entityDisplayHelper,
239244
#[CurrentUser] ?UserInterface $currentUser,
240245
WorkflowHelper $workflowHelper
@@ -261,7 +266,8 @@ class AjaxController {
261266
262267
«prepareTreeOperationParameters»
263268
264-
$createMethod = 'create' . ucfirst($objectType);
269+
«entityMatchBlock(entities.filter[tree])»
270+
$initMethod = 'init' . ucfirst($objectType);
265271
«repositoryMatchBlock(treeEntities)»
266272
267273
$rootId = 1;
@@ -275,7 +281,6 @@ class AjaxController {
275281
}
276282
}
277283
278-
$entityManager = $entityFactory->getEntityManager();
279284
$titleFieldName = $entityDisplayHelper->getTitleFieldName($objectType);
280285
$descriptionFieldName = $entityDisplayHelper->getDescriptionFieldName($objectType);
281286
@@ -346,7 +351,8 @@ class AjaxController {
346351
'''
347352

348353
def private treeOperationAddRootNode(Application it) '''
349-
$entity = $entityFactory->$createMethod();
354+
$entity = new $entityFqcn();
355+
$entityInitializer->$initMethod($entity);
350356
if (!empty($titleFieldName)) {
351357
$setter = 'set' . ucfirst($titleFieldName);
352358
$entity->$setter($this->trans('New root node'));
@@ -392,7 +398,8 @@ class AjaxController {
392398
return $this->json($returnValue);
393399
}
394400
395-
$childEntity = $entityFactory->$createMethod();
401+
$childEntity = new $entityFqcn();
402+
$entityInitializer->$initMethod($childEntity);
396403
$setter = 'set' . ucfirst($titleFieldName);
397404
$childEntity->$setter($this->trans('New child node'));
398405
if (!empty($descriptionFieldName)) {
@@ -567,19 +574,19 @@ class AjaxController {
567574
* Updates the sort positions for a given list of entities.
568575
*/
569576
#[IsGranted('ROLE_EDITOR')]
570-
«ELSE»
577+
«/*ELSE»
571578
#[Route('/updateSortPositions',
572579
name: '«appName.formatForDB»_ajax_updatesortpositions',
573580
methods: ['POST'],
574581
options: ['expose' => true]
575582
)]
576-
«ENDIF»
583+
*/»«ENDIF»
577584
'''
578585

579586
def private updateSortPositionsSignature(Application it) '''
580587
public function updateSortPositions(
581588
Request $request,
582-
EntityFactory $entityFactory
589+
EntityManagerInterface $entityManager
583590
): JsonResponse'''
584591

585592
def private updateSortPositionsBaseImpl(Application it) '''
@@ -617,7 +624,7 @@ class AjaxController {
617624
}
618625
619626
// save entities back to database
620-
$entityFactory->getEntityManager()->flush();
627+
$entityManager->flush();
621628
622629
// return response
623630
return $this->json([
@@ -657,7 +664,7 @@ class AjaxController {
657664
$request,
658665
$router,
659666
$logger,
660-
$entityFactory,
667+
$entityManager,
661668
$entityDisplayHelper,
662669
$currentUser,
663670
$workflowHelper
@@ -670,7 +677,7 @@ class AjaxController {
670677
«updateSortPositionsSignature» {
671678
return parent::updateSortPositions(
672679
$request,
673-
$entityFactory
680+
$entityManager
674681
);
675682
}
676683
'''

bundles/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/symfony/controller/action/InlineRedirect.xtend

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class InlineRedirect {
3939
/**
4040
* This method cares for a redirect within an inline frame.
4141
*/
42-
«ELSE»
42+
«/*ELSE»
4343
#[Route('«IF isAdmin»/admin«ENDIF»/«name.formatForCode»/handleInlineRedirect/{idPrefix}/{commandName}/{id}',
4444
name: '«application.appName.formatForDB»«IF isAdmin»_admin«ENDIF»_«name.formatForDB»_handleinlineredirect',
4545
requirements: ['id' => '\d+'],
4646
defaults: ['commandName' => '', 'id' => 0],
4747
methods: ['GET']
4848
)]
49-
«ENDIF»
49+
*/»«ENDIF»
5050
'''
5151
5252
def private handleInlineRedirectSignature(Entity it) '''

bundles/org.zikula.modulestudio.generator/src/org/zikula/modulestudio/generator/cartridges/symfony/controller/action/LoggableHistory.xtend

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ class LoggableHistory {
3434
$permissionHelper,
3535
$repository,
3636
$logEntryRepository,
37-
$loggableHelper,«IF hasTranslatableFields»
38-
$translatableHelper,«ENDIF»
37+
$loggableHelper,
38+
«IF hasTranslatableFields»
39+
$translatableHelper,
40+
«ENDIF»
3941
$workflowHelper,
4042
«IF hasSluggableFields»$slug«ELSE»$id«ENDIF»
4143
);
@@ -51,7 +53,7 @@ class LoggableHistory {
5153
* @throws NotFoundHttpException Thrown if invalid identifier is given or the «name.formatForDisplay» isn't found
5254
* @throws AccessDeniedException Thrown if the user doesn't have required permissions
5355
*/
54-
«ELSE»
56+
«/*ELSE»
5557
#[Route('«IF isAdmin»/admin«ENDIF»/«name.formatForCode»/history/{«IF hasSluggableFields»slug«ELSE»id«ENDIF»}',
5658
name: '«application.appName.formatForDB»«IF isAdmin»_admin«ENDIF»_«name.formatForDB»_loggablehistory',
5759
«IF hasSluggableFields»
@@ -62,7 +64,7 @@ class LoggableHistory {
6264
«ENDIF»
6365
methods: ['GET']
6466
)]
65-
«ENDIF»
67+
*/»«ENDIF»
6668
'''
6769
6870
def private loggableHistoryArguments(Entity it) '''

0 commit comments

Comments
 (0)