Skip to content

Commit 55147af

Browse files
committed
Fixed code by recommendation
1 parent dbb70c2 commit 55147af

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

resources/fileTemplates/internal/Magento Entity New Action Controller Class.php.ft

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ class ${CLASS_NAME} extends ${EXTENDS} implements ${IMPLEMENTS}
2323
/**
2424
* Create new ${ENTITY_NAME} action.
2525
*
26-
* @return ${RESULT_INTERFACE}|${FORWARD}
26+
* @return ${RESULT_PAGE}|${RESULT_INTERFACE}
2727
*/
2828
public function execute()
2929
{
30-
/** @var ${FORWARD} $resultForward */
31-
$resultForward = $this->resultFactory->create(${RESULT_FACTORY}::TYPE_FORWARD);
32-
$resultForward->forward('edit');
30+
/** @var ${RESULT_PAGE} $resultPage */
31+
$resultPage = $this->resultFactory->create(${RESULT_FACTORY}::TYPE_FORWARD);
32+
$resultPage->setActiveMenu('${MENU_IDENTIFIER}');
33+
$resultPage->getConfig()->getTitle()->prepend(__('New ${ENTITY_NAME}'));
3334

34-
return $resultForward;
35+
return $resultPage;
3536
}
3637
}

src/com/magento/idea/magento2plugin/actions/generation/data/NewActionEntityControllerFileData.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class NewActionEntityControllerFileData {
1313
private final String moduleName;
1414
private final String namespace;
1515
private final String acl;
16+
private final String menuIdentifier;
1617

1718
/**
1819
* Controller NewAction file constructor.
@@ -25,12 +26,14 @@ public NewActionEntityControllerFileData(
2526
final @NotNull String entityName,
2627
final @NotNull String moduleName,
2728
final @NotNull String namespace,
28-
final @NotNull String acl
29+
final @NotNull String acl,
30+
final @NotNull String menuIdentifier
2931
) {
3032
this.entityName = entityName;
3133
this.moduleName = moduleName;
3234
this.namespace = namespace;
3335
this.acl = acl;
36+
this.menuIdentifier = menuIdentifier;
3437
}
3538

3639
/**
@@ -68,4 +71,13 @@ public String getNamespace() {
6871
public String getAcl() {
6972
return acl;
7073
}
74+
75+
/**
76+
* Get menu.
77+
*
78+
* @return String
79+
*/
80+
public String getMenu() {
81+
return menuIdentifier;
82+
}
7183
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,8 @@ private void generateFormNewActionControllerFile() {
12121212
getEntityName(),
12131213
getModuleName(),
12141214
namespace.getNamespace(),
1215-
getAcl()
1215+
getAcl(),
1216+
getMenuIdentifier()
12161217
), project).generate(ACTION_NAME, false);
12171218
}
12181219

src/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityControllerFileGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ protected void fillAttributes(final @NotNull Properties attributes) {
7676
addProperty(attributes, "EXTENDS", BackendModuleType.EXTENDS.getType());
7777
addProperty(attributes, "IMPLEMENTS", HttpMethod.GET.getInterfaceFqn());
7878
attributes.setProperty("ADMIN_RESOURCE", fileData.getAcl());
79+
attributes.setProperty("MENU_IDENTIFIER", fileData.getMenu());
7980
addProperty(attributes, "RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType());
8081
addProperty(attributes, "RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType());
81-
addProperty(attributes, "FORWARD", BackendModuleType.FORWARD.getType());
82+
addProperty(attributes, "RESULT_PAGE", BackendModuleType.RESULT_PAGE.getType());
8283

8384
attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses));
8485
}

src/com/magento/idea/magento2plugin/magento/packages/code/BackendModuleType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public enum BackendModuleType {
1212
CONTEXT("Magento\\Backend\\App\\Action\\Context"),
1313
EXTENDS("Magento\\Backend\\App\\Action"),
14-
FORWARD("Magento\\Backend\\Model\\View\\Result\\Forward");
14+
RESULT_PAGE("Magento\\Backend\\Model\\View\\Result\\Page");
1515

1616
/**
1717
* Backend module type.

tests/com/magento/idea/magento2plugin/actions/generation/generator/NewActionEntityGeneratorTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class NewActionEntityGeneratorTest extends BaseGeneratorTestCase {
1717
private static final String NAMESPACE =
1818
"Foo\\Bar\\Controller\\Adminhtml\\" + ENTITY_NAME;
1919
private static final String ACL = "Foo_Bar::company_id";
20+
private static final String MENU = "Foo_Bar::menu_id";
2021

2122

2223
/**
@@ -28,7 +29,8 @@ public void testGenerateNewActionEntityFile() {
2829
ENTITY_NAME,
2930
MODULE_NAME,
3031
NAMESPACE,
31-
ACL
32+
ACL,
33+
MENU
3234
);
3335
final NewActionEntityControllerFileGenerator newActionEntityControllerFileGenerator =
3436
new NewActionEntityControllerFileGenerator(

0 commit comments

Comments
 (0)