Skip to content

Commit 16312a1

Browse files
author
Vitaliy Boyko
committed
89: fixed controller generation
1 parent 5a855c8 commit 16312a1

File tree

5 files changed

+111
-5
lines changed

5 files changed

+111
-5
lines changed

resources/fileTemplates/internal/Magento Module Common Php Class.php.html

Whitespace-only changes.

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.form

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
<properties/>
327327
<border type="none"/>
328328
<children>
329-
<grid id="c8f38" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
329+
<grid id="c8f38" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
330330
<margin top="0" left="0" bottom="0" right="0"/>
331331
<constraints>
332332
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -363,14 +363,30 @@
363363
</component>
364364
<component id="4e6cb" class="javax.swing.JTextField" binding="formName">
365365
<constraints>
366-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
366+
<grid row="0" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
367367
<preferred-size width="150" height="-1"/>
368368
</grid>
369369
</constraints>
370370
<properties>
371371
<text value=""/>
372372
</properties>
373373
</component>
374+
<component id="3eed0" class="javax.swing.JLabel" binding="aclLabel">
375+
<constraints>
376+
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
377+
</constraints>
378+
<properties>
379+
<text value="ACL"/>
380+
</properties>
381+
</component>
382+
<component id="8ab6a" class="javax.swing.JTextField" binding="acl">
383+
<constraints>
384+
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
385+
<preferred-size width="150" height="-1"/>
386+
</grid>
387+
</constraints>
388+
<properties/>
389+
</component>
374390
</children>
375391
</grid>
376392
</children>

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public class NewUiComponentFormDialog extends AbstractDialog {
9393
private JLabel dataProviderClassNameLabel;
9494
private JLabel dataProviderDirectoryLabel;
9595
private JTextField dataProviderDirectory;
96+
private JLabel aclLabel;
97+
private JTextField acl;
9698

9799
/**
98100
* Open new dialog for adding new controller.
@@ -135,6 +137,8 @@ public void actionPerformed(final ActionEvent event) {
135137
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
136138
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
137139
);
140+
141+
formAreaSelect.addActionListener(e -> toggleAcl());
138142
}
139143

140144
protected void initButtonsTable() {
@@ -360,7 +364,7 @@ private PsiFile generateViewControllerFile() {
360364
getModuleName(),
361365
getArea(),
362366
HttpMethod.GET.toString(),
363-
null,
367+
getAcl(),
364368
true,
365369
namespace.getNamespace()
366370
), project).generate(NewUiComponentFormAction.ACTION_NAME, false);
@@ -374,7 +378,7 @@ private PsiFile generateSubmitControllerFile() {
374378
getModuleName(),
375379
getArea(),
376380
HttpMethod.POST.toString(),
377-
null,
381+
getAcl(),
378382
true,
379383
namespace.getNamespace()
380384
), project).generate(NewUiComponentFormAction.ACTION_NAME, false);
@@ -546,11 +550,26 @@ public String getDataProviderDirectory() {
546550
return dataProviderDirectory.getText().trim();
547551
}
548552

553+
public String getAcl() {
554+
return acl.getText().trim();
555+
}
556+
549557
private String getControllerDirectory() {
550558
final String area = getArea();
551559
String directory = area.equals(Areas.adminhtml.toString())
552560
? ControllerBackendPhp.DEFAULT_DIR : ControllerFrontendPhp.DEFAULT_DIR;
553561

554562
return directory + File.separator;
555563
}
564+
565+
private void toggleAcl() {
566+
final String area = getArea();
567+
if (area.equals(Areas.adminhtml.toString())) {
568+
acl.setVisible(true);
569+
aclLabel.setVisible(true);
570+
return;
571+
}
572+
acl.setVisible(false);
573+
aclLabel.setVisible(false);
574+
}
556575
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public PsiFile generate(final String actionName) {
8686
routeTag.addSubTag(moduleTag, false);
8787
routerTag.addSubTag(routeTag, false);
8888

89-
if (!routerTagIsGenerated) {
89+
if (routerTagIsGenerated) {
9090
rootTag.addSubTag(routerTag, false);
9191
}
9292
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.generator.util;
7+
8+
import com.intellij.openapi.project.Project;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
12+
import com.magento.idea.magento2plugin.magento.files.ModuleDiXml;
13+
import com.magento.idea.magento2plugin.magento.packages.Areas;
14+
import com.magento.idea.magento2plugin.magento.packages.Package;
15+
import com.magento.idea.magento2plugin.util.magento.FileBasedIndexUtil;
16+
import java.util.ArrayList;
17+
import java.util.Properties;
18+
19+
public final class FindOrCreateAclXml {
20+
private final Project project;
21+
22+
public FindOrCreateAclXml(final Project project) {
23+
this.project = project;
24+
}
25+
26+
/**
27+
* Finds or creates module acl.xml.
28+
*
29+
* @param actionName String
30+
* @param moduleName String
31+
* @param area String
32+
* @return PsiFile
33+
*/
34+
public PsiFile execute(final String actionName, final String moduleName, final String area) {
35+
final DirectoryGenerator directoryGenerator = DirectoryGenerator.getInstance();
36+
final FileFromTemplateGenerator fileFromTemplateGenerator =
37+
FileFromTemplateGenerator.getInstance(project);
38+
39+
PsiDirectory parentDirectory = ModuleIndex.getInstance(project)
40+
.getModuleDirectoryByModuleName(moduleName);
41+
final ArrayList<String> fileDirectories = new ArrayList<>();
42+
fileDirectories.add(Package.moduleBaseAreaDir);
43+
if (!getArea(area).equals(Areas.base)) {
44+
fileDirectories.add(getArea(area).toString());
45+
}
46+
for (final String fileDirectory: fileDirectories) {
47+
parentDirectory = directoryGenerator
48+
.findOrCreateSubdirectory(parentDirectory, fileDirectory);
49+
}
50+
final ModuleDiXml moduleDiXml = new ModuleDiXml();
51+
PsiFile diXml = FileBasedIndexUtil.findModuleConfigFile(
52+
moduleDiXml.getFileName(),
53+
getArea(area),
54+
moduleName,
55+
project
56+
);
57+
if (diXml == null) {
58+
diXml = fileFromTemplateGenerator.generate(
59+
moduleDiXml,
60+
new Properties(),
61+
parentDirectory,
62+
actionName
63+
);
64+
}
65+
return diXml;
66+
}
67+
68+
private Areas getArea(final String area) {
69+
return Areas.getAreaByString(area);
70+
}
71+
}

0 commit comments

Comments
 (0)