Skip to content

Commit a4ad38d

Browse files
authored
Merge pull request #389 from drpayyne/issue-385
Fixed plugin generation sort order requirement
2 parents 4bf8869 + 62bd050 commit a4ad38d

File tree

10 files changed

+58
-14
lines changed

10 files changed

+58
-14
lines changed

resources/fileTemplates/code/Magento Module DI Xml Plugin.xml.ft

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
<type name="${TYPE}">
33
#end
44
<plugin name="${NAME}"
5-
type="${PLUGIN_TYPE}" sortOrder="${SORT_ORDER}" />
5+
#if (${SORT_ORDER})
6+
type="${PLUGIN_TYPE}"
7+
sortOrder="${SORT_ORDER}" />
8+
#else
9+
type="${PLUGIN_TYPE}" />
10+
#end
611
#if (${TYPE})
712
</type>
813
#end

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

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
</grid>
132132
</constraints>
133133
<properties>
134-
<text value="10"/>
135134
<toolTipText value="Plugin sort order in di.xml"/>
136135
</properties>
137136
<clientProperties>

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

-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ public class CreateAPluginDialog extends AbstractDialog {
8282
message = {DirectoryRule.MESSAGE, DIRECTORY})
8383
private JTextField pluginDirectory;
8484

85-
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
86-
message = {NotEmptyRule.MESSAGE, SORT_ORDER})
8785
@FieldValidation(rule = RuleRegistry.NUMERIC,
8886
message = {NumericRule.MESSAGE, SORT_ORDER})
8987
private JTextField pluginSortOrder;

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ protected void fillAttributes(final Properties attributes) {
161161
attributes.setProperty("NAME", pluginFileData.getPluginName());
162162
attributes.setProperty("PLUGIN_TYPE", pluginFileData.getPluginFqn());
163163
attributes.setProperty("PLUGIN_NAME", pluginFileData.getPluginName());
164-
attributes.setProperty("SORT_ORDER", pluginFileData.getSortOrder());
164+
final String sortOrder = pluginFileData.getSortOrder();
165+
if (!sortOrder.isEmpty()) {
166+
attributes.setProperty("SORT_ORDER", sortOrder);
167+
}
165168
}
166169
}

testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneDiXml/di.xml

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<type name="Foo\Bar\Model\PluginTargetClassOne">
55
<plugin name="test_plugin_name_1"
6-
type="Foo\Bar\Plugin\TestOnePlugin" sortOrder="10"/>
6+
type="Foo\Bar\Plugin\TestOnePlugin"
7+
sortOrder="10"/>
78
</type>
89
<type name="Foo\Bar\Model\PluginTargetClassTwo">
910
<plugin name="test_plugin_name_2"
10-
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
11+
type="Foo\Bar\Plugin\TestTwoPlugin"
12+
sortOrder="20"/>
1113
</type>
1214
</config>

testData/actions/generation/generator/PluginDiXmlGenerator/addTwoPluginsToOneTargetClass/di.xml

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<type name="Foo\Bar\Model\PluginTargetClassOne">
55
<plugin name="test_plugin_name_1"
6-
type="Foo\Bar\Plugin\TestOnePlugin" sortOrder="10"/>
6+
type="Foo\Bar\Plugin\TestOnePlugin"
7+
sortOrder="10"/>
78
<plugin name="test_plugin_name_2"
8-
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
9+
type="Foo\Bar\Plugin\TestTwoPlugin"
10+
sortOrder="20"/>
911
</type>
1012
</config>

testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForAdminhtmlArea/di.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<type name="Foo\Bar\Model\PluginTargetClassTwo">
55
<plugin name="test_plugin_name_2"
6-
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
6+
type="Foo\Bar\Plugin\TestTwoPlugin"
7+
sortOrder="20"/>
78
</type>
89
</config>

testData/actions/generation/generator/PluginDiXmlGenerator/generatePluginDiXmlFileForBaseArea/di.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<type name="Foo\Bar\Model\PluginTargetClassOne">
55
<plugin name="test_plugin_name_1"
6-
type="Foo\Bar\Plugin\TestOnePlugin" sortOrder="10"/>
6+
type="Foo\Bar\Plugin\TestOnePlugin"
7+
sortOrder="10"/>
78
</type>
89
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
4+
<type name="Foo\Bar\Model\PluginTargetClassOne">
5+
<plugin name="test_plugin_name_1"
6+
type="Foo\Bar\Plugin\TestOnePlugin"/>
7+
</type>
8+
</config>

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

+28-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ public class PluginDiXmlGeneratorTest extends BaseGeneratorTestCase {
2424
private static final String PLUGIN_CLASS_TWO_FNQ = "Foo\\Bar\\Plugin\\TestTwoPlugin";
2525
private static final String MODULE = "Foo_Bar";
2626
private static final String MODULE_DIR = "src/app/code/Foo/Bar/";
27+
private static final String TEST_PLUGIN_NAME = "test_plugin_name_1";
28+
29+
/**
30+
* Test checks whether di.xml is generated correctly for the base area
31+
*/
32+
public void testGeneratePluginDiXmlFileWithoutSortOrder() {
33+
final PsiFile expectedFile = myFixture.configureByFile(
34+
this.getFixturePath(ModuleDiXml.FILE_NAME)
35+
);
36+
final String area = Areas.base.toString();
37+
38+
final PsiFile diXml = addPluginDiXml(
39+
PLUGIN_TARGET_CLASS_ONE_FNQ,
40+
area,
41+
"",
42+
TEST_PLUGIN_NAME,
43+
PLUGIN_CLASS_ONE_FNQ
44+
);
45+
46+
assertGeneratedFileIsCorrect(
47+
expectedFile,
48+
getExpectedDirectory(area),
49+
diXml
50+
);
51+
}
2752

2853
/**
2954
* Test checks whether di.xml is generated correctly for the base area
@@ -37,7 +62,7 @@ public void testGeneratePluginDiXmlFileForBaseArea() {
3762
PLUGIN_TARGET_CLASS_ONE_FNQ,
3863
area,
3964
"10",
40-
"test_plugin_name_1",
65+
TEST_PLUGIN_NAME,
4166
PLUGIN_CLASS_ONE_FNQ
4267
);
4368

@@ -82,7 +107,7 @@ public void testAddTwoPluginsToOneDiXml() {
82107
PLUGIN_TARGET_CLASS_ONE_FNQ,
83108
area,
84109
"10",
85-
"test_plugin_name_1",
110+
TEST_PLUGIN_NAME,
86111
PLUGIN_CLASS_ONE_FNQ
87112
);
88113
final PsiFile diXml = addPluginDiXml(
@@ -111,7 +136,7 @@ public void testAddTwoPluginsToOneTargetClass() {
111136
PLUGIN_TARGET_CLASS_ONE_FNQ,
112137
area,
113138
"10",
114-
"test_plugin_name_1",
139+
TEST_PLUGIN_NAME,
115140
PLUGIN_CLASS_ONE_FNQ
116141
);
117142
final PsiFile diXml = addPluginDiXml(

0 commit comments

Comments
 (0)