Skip to content

Commit 8a8c391

Browse files
977: Added system.xml file in context generation
1 parent 3997a01 commit 8a8c391

File tree

15 files changed

+212
-17
lines changed

15 files changed

+212
-17
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<action id="MagentoCreateWebapiFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewWebapiXmlAction"/>
6565
<action id="MagentoCreateAclFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewAclXmlAction"/>
6666
<action id="MagentoCreateConfigFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewConfigXmlAction"/>
67+
<action id="MagentoCreateSystemFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewSystemXmlAction"/>
6768
<!-- Context dependent actions -->
6869
<separator/>
6970
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
#parse("XML File Header.xml")
3+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
5+
<system>
6+
</system>
7+
</config>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">
12+
The system.xml file allows you to manage the Magento system configuration. Use this topic as a general reference for the system.xml file.
13+
The system.xml file is located under etc/adminhtml/system.xml in a given Magento 2 extension.
14+
</font><br>
15+
</td>
16+
</tr>
17+
<tr>
18+
<td><font face="verdana" size="-1">
19+
Read more about the system.xml in the
20+
<a href="https://devdocs.magento.com/guides/v2.4/config-guide/prod/config-reference-systemxml.html">
21+
DevDocs</a>.
22+
</font><br>
23+
</td>
24+
</tr>
25+
</table>
26+
</body>
27+
</html>

src/com/magento/idea/magento2plugin/actions/context/AbstractContextAction.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.intellij.psi.PsiFile;
2121
import com.magento.idea.magento2plugin.MagentoIcons;
2222
import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface;
23+
import com.magento.idea.magento2plugin.magento.packages.Package;
2324
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
2425
import org.jetbrains.annotations.NotNull;
2526
import org.jetbrains.annotations.Nullable;
@@ -154,6 +155,18 @@ protected FileTemplate getTemplate(
154155
return template;
155156
}
156157

158+
protected @Nullable PsiDirectory getGlobalScopeDir(final @NotNull PsiDirectory directory) {
159+
PsiDirectory globalScopeDir;
160+
161+
if (Package.moduleBaseAreaDir.equals(directory.getName())) {
162+
globalScopeDir = directory;
163+
} else {
164+
globalScopeDir = directory.getParentDirectory();
165+
}
166+
167+
return globalScopeDir;
168+
}
169+
157170
@Override
158171
public boolean isDumbAware() {
159172
return false;

src/com/magento/idea/magento2plugin/actions/context/xml/NewAclXmlAction.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ protected boolean isVisible(
3333
final @NotNull PsiDirectory targetDirectory,
3434
final PsiFile targetFile
3535
) {
36+
final PsiDirectory configDir = moduleData.getConfigDir();
37+
38+
if (configDir == null) {
39+
return false;
40+
}
41+
3642
return targetDirectory.getName().equals(Package.moduleBaseAreaDir)
43+
&& targetDirectory.equals(configDir)
3744
&& moduleData.getType().equals(ComponentType.module);
3845
}
3946

src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ protected boolean isVisible(
3333
final @NotNull PsiDirectory targetDirectory,
3434
final PsiFile targetFile
3535
) {
36+
final PsiDirectory configDir = moduleData.getConfigDir();
37+
38+
if (configDir == null) {
39+
return false;
40+
}
41+
3642
return targetDirectory.getName().equals(Package.moduleBaseAreaDir)
43+
&& targetDirectory.equals(configDir)
3744
&& moduleData.getType().equals(ComponentType.module);
3845
}
3946

src/com/magento/idea/magento2plugin/actions/context/xml/NewDiXmlAction.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ protected boolean isVisible(
4545
Areas.graphql.toString(),
4646
Areas.crontab.toString()
4747
);
48+
final PsiDirectory configDir = moduleData.getConfigDir();
49+
final PsiDirectory globalScopeDir = getGlobalScopeDir(targetDirectory);
50+
51+
if (configDir == null || globalScopeDir == null) {
52+
return false;
53+
}
4854

4955
return allowedDirectories.contains(targetDirectory.getName())
56+
&& globalScopeDir.equals(configDir)
5057
&& moduleData.getType().equals(ComponentType.module);
5158
}
5259

src/com/magento/idea/magento2plugin/actions/context/xml/NewRoutesXmlAction.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ protected boolean isVisible(
3636
final @NotNull PsiDirectory targetDirectory,
3737
final PsiFile targetFile
3838
) {
39+
final PsiDirectory configDir = moduleData.getConfigDir();
40+
final PsiDirectory globalScopeDir = getGlobalScopeDir(targetDirectory);
41+
42+
if (configDir == null || globalScopeDir == null) {
43+
return false;
44+
}
3945
final List<String> allowedDirectories = Arrays.asList(
4046
Package.moduleBaseAreaDir,
4147
Areas.adminhtml.toString(),
4248
Areas.frontend.toString()
4349
);
4450

4551
return allowedDirectories.contains(targetDirectory.getName())
52+
&& globalScopeDir.equals(configDir)
4653
&& moduleData.getType().equals(ComponentType.module);
4754
}
4855

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.context.xml;
7+
8+
import com.intellij.ide.fileTemplates.actions.AttributesDefaults;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.actions.context.AbstractContextAction;
12+
import com.magento.idea.magento2plugin.magento.files.ModuleSystemXmlFile;
13+
import com.magento.idea.magento2plugin.magento.packages.Areas;
14+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
15+
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
16+
import org.jetbrains.annotations.NotNull;
17+
18+
public class NewSystemXmlAction extends AbstractContextAction {
19+
20+
public static final String ACTION_NAME = "Magento 2 System File";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 system.xml file";
22+
23+
/**
24+
* New system.xml file generation action constructor.
25+
*/
26+
public NewSystemXmlAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleSystemXmlFile());
28+
}
29+
30+
@Override
31+
protected boolean isVisible(
32+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
33+
final @NotNull PsiDirectory targetDirectory,
34+
final PsiFile targetFile
35+
) {
36+
final PsiDirectory parentDir = targetDirectory.getParentDirectory();
37+
final PsiDirectory configDir = moduleData.getConfigDir();
38+
39+
if (parentDir == null || configDir == null) {
40+
return false;
41+
}
42+
43+
return targetDirectory.getName().equals(Areas.adminhtml.toString())
44+
&& parentDir.equals(configDir)
45+
&& moduleData.getType().equals(ComponentType.module);
46+
}
47+
48+
@Override
49+
protected AttributesDefaults getProperties(
50+
final @NotNull AttributesDefaults defaults,
51+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
52+
final PsiDirectory targetDirectory,
53+
final PsiFile targetFile
54+
) {
55+
return defaults;
56+
}
57+
}

src/com/magento/idea/magento2plugin/actions/context/xml/NewWebapiXmlAction.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ protected boolean isVisible(
3333
final @NotNull PsiDirectory targetDirectory,
3434
final PsiFile targetFile
3535
) {
36+
final PsiDirectory configDir = moduleData.getConfigDir();
37+
38+
if (configDir == null) {
39+
return false;
40+
}
41+
3642
return targetDirectory.getName().equals(Package.moduleBaseAreaDir)
43+
&& targetDirectory.equals(configDir)
3744
&& moduleData.getType().equals(ComponentType.module);
3845
}
3946

0 commit comments

Comments
 (0)