Skip to content

Commit ae84e39

Browse files
Merge pull request #996 from doninAtwix/991-new-context-fieldset-xml-file-action
991: Added fieldset.xml file in context generation.
2 parents f6d0407 + 12f9c38 commit ae84e39

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<action id="MagentoCreateMviewFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewMviewXmlAction"/>
7171
<action id="MagentoCreateIndexerFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewIndexerXmlAction"/>
7272
<action id="MagentoCreateViewFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewViewXmlAction"/>
73+
<action id="MagentoCreateFieldsetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewFieldsetXmlAction"/>
7374
<!-- Context dependent actions -->
7475
<separator/>
7576
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
@@ -579,6 +580,7 @@
579580
<internalFileTemplate name="Magento Mview XML"/>
580581
<internalFileTemplate name="Magento Indexer XML"/>
581582
<internalFileTemplate name="Magento View XML"/>
583+
<internalFileTemplate name="Magento Fieldset XML"/>
582584

583585
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
584586

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
#parse("XML File Header.xml")
3+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
5+
</config>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html lang="en">
8+
<body>
9+
<font face="verdana" size="-1">
10+
<p>
11+
The fieldset.xml file configures which the copy fields from quote to order.
12+
The fieldset.xml file is located under etc/fieldset.xml in a given Magento 2 extension.
13+
</p>
14+
<p>
15+
Read more about fieldset.xml in the
16+
<a href="https://devdocs.magento.com/guides/v2.4/ext-best-practices/tutorials/copy-fieldsets.html">DevDocs</a>.
17+
</p>
18+
</font>
19+
</body>
20+
</html>
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.ModuleFieldsetXmlFile;
13+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
14+
import com.magento.idea.magento2plugin.magento.packages.Package;
15+
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
16+
import org.jetbrains.annotations.NotNull;
17+
18+
public class NewFieldsetXmlAction extends AbstractContextAction {
19+
20+
public static final String ACTION_NAME = "Magento 2 Fieldset File";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 fieldset.xml file";
22+
23+
/**
24+
* New fieldset.xml file generation action constructor.
25+
*/
26+
public NewFieldsetXmlAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleFieldsetXmlFile());
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 configDir = moduleData.getConfigDir();
37+
38+
if (configDir == null) {
39+
return false;
40+
}
41+
42+
return targetDirectory.getName().equals(Package.moduleBaseAreaDir)
43+
&& targetDirectory.equals(configDir)
44+
&& moduleData.getType().equals(ComponentType.module);
45+
}
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.magento.files;
7+
8+
import com.intellij.lang.Language;
9+
import com.intellij.lang.xml.XMLLanguage;
10+
11+
public final class ModuleFieldsetXmlFile implements ModuleFileInterface {
12+
13+
public static final String FILE_NAME = "fieldset.xml";
14+
public static final String TEMPLATE = "Magento Fieldset XML";
15+
16+
@Override
17+
public String getFileName() {
18+
return FILE_NAME;
19+
}
20+
21+
@Override
22+
public String getTemplate() {
23+
return TEMPLATE;
24+
}
25+
26+
@Override
27+
public Language getLanguage() {
28+
return XMLLanguage.INSTANCE;
29+
}
30+
}

0 commit comments

Comments
 (0)