Skip to content

Commit 0bb5046

Browse files
Rewrited edit action generation, added test case for edit action generation
1 parent 9c54773 commit 0bb5046

File tree

10 files changed

+484
-18
lines changed

10 files changed

+484
-18
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
<internalFileTemplate name="Magento PHP Form Generic Button Block Class"/>
239239
<internalFileTemplate name="Magento Entity New Action Controller Class"/>
240240
<internalFileTemplate name="Magento New Entity Layout XML"/>
241+
<internalFileTemplate name="Magento Entity Edit Action Controller Class"/>
241242

242243
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
243244

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
namespace ${NAMESPACE};
5+
6+
#set($uses = ${USES})
7+
#foreach ($use in $uses.split(","))
8+
use $use;
9+
#end
10+
11+
/**
12+
* Edit ${ENTITY_NAME} entity backend controller.
13+
*/
14+
class ${CLASS_NAME} extends ${EXTENDS} implements ${IMPLEMENTS}
15+
{
16+
/**
17+
* Authorization level of a basic admin session.
18+
*
19+
* @see _isAllowed()
20+
*/
21+
const ADMIN_RESOURCE = '${ADMIN_RESOURCE}';
22+
23+
/**
24+
* Edit ${ENTITY_NAME} action.
25+
*
26+
* @return ${RESULT_PAGE}|${RESULT_INTERFACE}
27+
*/
28+
public function execute()
29+
{
30+
/** @var ${RESULT_PAGE} $resultPage */
31+
$resultPage = $this->resultFactory->create(${RESULT_FACTORY}::TYPE_PAGE);
32+
$resultPage->setActiveMenu('${MENU_IDENTIFIER}');
33+
$resultPage->getConfig()->getTitle()->prepend(__('Edit ${ENTITY_NAME}'));
34+
35+
return $resultPage;
36+
}
37+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<html lang="en">
2+
<body>
3+
<p face="verdana" size="-1">
4+
5+
</p>
6+
7+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
8+
<tr>
9+
<td colspan="3"><font face="verdana" size="-1">Template's predefined variables:</font></td>
10+
</tr>
11+
<tr>
12+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAMESPACE}</b></font></nobr></td>
13+
<td width="10">&nbsp;</td>
14+
<td width="100%" valign="top"><font face="verdana" size="-1"></font></td>
15+
</tr>
16+
</table>
17+
</body>
18+
</html>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
import org.jetbrains.annotations.NotNull;
9+
10+
public class EditEntityActionData {
11+
12+
private final String entityName;
13+
private final String moduleName;
14+
private final String classFqn;
15+
private final String namespace;
16+
private final String acl;
17+
private final String menuIdentifier;
18+
19+
/**
20+
* Edit action data constructor.
21+
*
22+
* @param entityName String
23+
* @param moduleName String
24+
* @param classFqn String
25+
* @param namespace String
26+
* @param acl String
27+
* @param menuIdentifier String
28+
*/
29+
public EditEntityActionData(
30+
final @NotNull String entityName,
31+
final @NotNull String moduleName,
32+
final @NotNull String classFqn,
33+
final @NotNull String namespace,
34+
final @NotNull String acl,
35+
final @NotNull String menuIdentifier
36+
) {
37+
this.entityName = entityName;
38+
this.moduleName = moduleName;
39+
this.classFqn = classFqn;
40+
this.namespace = namespace;
41+
this.acl = acl;
42+
this.menuIdentifier = menuIdentifier;
43+
}
44+
45+
/**
46+
* Get entity name.
47+
*
48+
* @return String
49+
*/
50+
public String getEntityName() {
51+
return entityName;
52+
}
53+
54+
/**
55+
* Get module name.
56+
*
57+
* @return String
58+
*/
59+
public String getModuleName() {
60+
return moduleName;
61+
}
62+
63+
/**
64+
* Get class FQN.
65+
*
66+
* @return String
67+
*/
68+
public String getClassFqn() {
69+
return classFqn;
70+
}
71+
72+
/**
73+
* Get namespace.
74+
*
75+
* @return String
76+
*/
77+
public String getNamespace() {
78+
return namespace;
79+
}
80+
81+
/**
82+
* Get acl.
83+
*
84+
* @return String
85+
*/
86+
public String getAcl() {
87+
return acl;
88+
}
89+
90+
/**
91+
* Get menu.
92+
*
93+
* @return String
94+
*/
95+
public String getMenu() {
96+
return menuIdentifier;
97+
}
98+
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.magento.idea.magento2plugin.actions.generation.data.DataModelData;
2121
import com.magento.idea.magento2plugin.actions.generation.data.DataModelInterfaceData;
2222
import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData;
23+
import com.magento.idea.magento2plugin.actions.generation.data.EditEntityActionData;
2324
import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData;
2425
import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData;
2526
import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData;
@@ -56,6 +57,7 @@
5657
import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator;
5758
import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaWhitelistJsonGenerator;
5859
import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator;
60+
import com.magento.idea.magento2plugin.actions.generation.generator.EditEntityActionGenerator;
5961
import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator;
6062
import com.magento.idea.magento2plugin.actions.generation.generator.FormGenericButtonBlockGenerator;
6163
import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator;
@@ -87,6 +89,7 @@
8789
import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp;
8890
import com.magento.idea.magento2plugin.magento.files.UiComponentDataProviderPhp;
8991
import com.magento.idea.magento2plugin.magento.files.actions.AdminListViewActionFile;
92+
import com.magento.idea.magento2plugin.magento.files.actions.EditEntityActionFile;
9093
import com.magento.idea.magento2plugin.magento.files.actions.NewActionFile;
9194
import com.magento.idea.magento2plugin.magento.files.actions.SaveActionFile;
9295
import com.magento.idea.magento2plugin.magento.files.commands.SaveEntityCommandFile;
@@ -365,12 +368,12 @@ private void onOK() {
365368
generateDataProviderFile();
366369
generateUiComponentGridActionColumnFile();
367370
generateUiComponentGridFile();
368-
generateFormViewControllerFile();
369371
generateFormLayoutFile();
370372
generateNewEntityLayoutFile();
371373
generateSaveEntityCommandFile();
372-
generateFormSaveControllerFile();
373374
generateFormUiComponentGenericButtonFile();
375+
generateFormEditControllerFile();
376+
generateFormSaveControllerFile();
374377
generateFormNewActionControllerFile();
375378
generateUiComponentFormFile();
376379
}
@@ -645,12 +648,22 @@ public String getRoute() {
645648
return route.getText().trim();
646649
}
647650

648-
private String getViewActionName() {
651+
/**
652+
* Get edit action name.
653+
*
654+
* @return String
655+
*/
656+
private String getEditActionName() {
649657
return "Edit";
650658
}
651659

660+
/**
661+
* Get submit action name.
662+
*
663+
* @return String
664+
*/
652665
private String getSubmitActionName() {
653-
return "Save";//NOPMD
666+
return "Save";
654667
}
655668

656669
private String getControllerDirectory() {
@@ -1117,24 +1130,24 @@ private String getDeleteAction() {
11171130
}
11181131

11191132
/**
1120-
* Generate form view controller file.
1133+
* Generate form edit controller file.
11211134
*/
1122-
private void generateFormViewControllerFile() {
1123-
final NamespaceBuilder namespace = new NamespaceBuilder(
1135+
private void generateFormEditControllerFile() {
1136+
final EditEntityActionFile file = new EditEntityActionFile(getEntityName());
1137+
final NamespaceBuilder editActionNamespaceBuilder = new NamespaceBuilder(
11241138
getModuleName(),
1125-
getViewActionName(),
1126-
getControllerDirectory().concat(getEntityName())
1139+
file.getClassName(),
1140+
file.getDirectory()
11271141
);
1128-
new ModuleControllerClassGenerator(new ControllerFileData(
1129-
getControllerDirectory().concat(getEntityName()),
1130-
getViewActionName(),
1142+
final EditEntityActionData data = new EditEntityActionData(
1143+
getEntityName(),
11311144
getModuleName(),
1132-
Areas.adminhtml.toString(),
1133-
HttpMethod.GET.toString(),
1145+
editActionNamespaceBuilder.getClassFqn(),
1146+
editActionNamespaceBuilder.getNamespace(),
11341147
getAcl(),
1135-
true,
1136-
namespace.getNamespace()
1137-
), project).generate(ACTION_NAME, false);
1148+
getMenuIdentifier()
1149+
);
1150+
new EditEntityActionGenerator(data, project).generate(ACTION_NAME, false);
11381151
}
11391152

11401153
/**
@@ -1146,7 +1159,7 @@ private void generateFormLayoutFile() {
11461159
getRoute(),
11471160
getModuleName(),
11481161
getEntityName(),
1149-
getViewActionName(),
1162+
getEditActionName(),
11501163
getFormName()
11511164
), project).generate(ACTION_NAME, false);
11521165
}

0 commit comments

Comments
 (0)