Skip to content

Commit 8ff6339

Browse files
author
Vitaliy Boyko
committed
Merge remote-tracking branch 'origin/models-generation' into models-generation
2 parents 9f5d614 + 64d8b6a commit 8ff6339

File tree

28 files changed

+301
-160
lines changed

28 files changed

+301
-160
lines changed

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

Lines changed: 6 additions & 1 deletion
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

resources/fileTemplates/code/Magento Module UI Component Form Field Xml.xml.html

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,5 @@
66
-->
77
<html lang="en">
88
<body>
9-
<p face="verdana" size="-1">
10-
The <a href="https://devdocs.magento.com/guides/v2.4/ui_comp_guide/components/ui-form.html">Form component</a> configuration.
11-
</p>
12-
13-
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
14-
<tr>
15-
<td colspan="3"><font face="verdana" size="-1">Predefined variables will take the following values:</font></td>
16-
</tr>
17-
<tr>
18-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAME}</b></font></nobr></td>
19-
<td width="10">&nbsp;</td>
20-
<td width="100%" valign="top"><font face="verdana" size="-1">Name for the UI Component Form. The name will be used for configuration file.</font></td>
21-
</tr>
22-
<tr>
23-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${LABEL}</b></font></nobr></td>
24-
<td width="10">&nbsp;</td>
25-
<td width="100%" valign="top"><font face="verdana" size="-1">Label for form elements (fieldset, button, input, etc..)</font></td>
26-
</tr>
27-
<tr>
28-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${BUTTONS}</b></font></nobr></td>
29-
<td width="10">&nbsp;</td>
30-
<td width="100%" valign="top"><font face="verdana" size="-1">Buttons that should be added to form.</font></td>
31-
</tr>
32-
<tr>
33-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${ROUTE}</b></font></nobr></td>
34-
<td width="10">&nbsp;</td>
35-
<td width="100%" valign="top"><font face="verdana" size="-1">Route name</font></td>
36-
</tr>
37-
<tr>
38-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${SUBMIT_CONTROLLER}</b></font></nobr></td>
39-
<td width="10">&nbsp;</td>
40-
<td width="100%" valign="top"><font face="verdana" size="-1">Class name for the controller.</font></td>
41-
</tr>
42-
<tr>
43-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${SUBMIT_ACTION}</b></font></nobr></td>
44-
<td width="10">&nbsp;</td>
45-
<td width="100%" valign="top"><font face="verdana" size="-1">Specifies the action class name.</font></td>
46-
</tr>
47-
<tr>
48-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${DATA_PROVIDER}</b></font></nobr></td>
49-
<td width="10">&nbsp;</td>
50-
<td width="100%" valign="top"><font face="verdana" size="-1">Class name for the data provider class.</font></td>
51-
</tr>
52-
<tr>
53-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${PRIMARY_FIELD}</b></font></nobr></td>
54-
<td width="10">&nbsp;</td>
55-
<td width="100%" valign="top"><font face="verdana" size="-1">Resource model primary field name.</font></td>
56-
</tr>
57-
</table>
589
</body>
59-
</html>
10+
</html>

resources/fileTemplates/internal/Magento Form Button Block Class.php.html

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,5 @@
66
-->
77
<html lang="en">
88
<body>
9-
<p face="verdana" size="-1">
10-
The <a href="https://devdocs.magento.com/guides/v2.4/ui_comp_guide/components/ui-form.html">Form component</a> configuration.
11-
</p>
12-
13-
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
14-
<tr>
15-
<td colspan="3"><font face="verdana" size="-1">Predefined variables will take the following values:</font></td>
16-
</tr>
17-
<tr>
18-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAME}</b></font></nobr></td>
19-
<td width="10">&nbsp;</td>
20-
<td width="100%" valign="top"><font face="verdana" size="-1">Name for the UI Component Form. The name will be used for configuration file.</font></td>
21-
</tr>
22-
<tr>
23-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${LABEL}</b></font></nobr></td>
24-
<td width="10">&nbsp;</td>
25-
<td width="100%" valign="top"><font face="verdana" size="-1">Label for form elements (fieldset, button, input, etc..)</font></td>
26-
</tr>
27-
<tr>
28-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${BUTTONS}</b></font></nobr></td>
29-
<td width="10">&nbsp;</td>
30-
<td width="100%" valign="top"><font face="verdana" size="-1">Buttons that should be added to form.</font></td>
31-
</tr>
32-
<tr>
33-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${ROUTE}</b></font></nobr></td>
34-
<td width="10">&nbsp;</td>
35-
<td width="100%" valign="top"><font face="verdana" size="-1">Route name</font></td>
36-
</tr>
37-
<tr>
38-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${SUBMIT_CONTROLLER}</b></font></nobr></td>
39-
<td width="10">&nbsp;</td>
40-
<td width="100%" valign="top"><font face="verdana" size="-1">Class name for the controller.</font></td>
41-
</tr>
42-
<tr>
43-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${SUBMIT_ACTION}</b></font></nobr></td>
44-
<td width="10">&nbsp;</td>
45-
<td width="100%" valign="top"><font face="verdana" size="-1">Specifies the action class name.</font></td>
46-
</tr>
47-
<tr>
48-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${DATA_PROVIDER}</b></font></nobr></td>
49-
<td width="10">&nbsp;</td>
50-
<td width="100%" valign="top"><font face="verdana" size="-1">Class name for the data provider class.</font></td>
51-
</tr>
52-
<tr>
53-
<td valign="top"><nobr><font face="verdana" size="-2"><b>${PRIMARY_FIELD}</b></font></nobr></td>
54-
<td width="10">&nbsp;</td>
55-
<td width="100%" valign="top"><font face="verdana" size="-1">Resource model primary field name.</font></td>
56-
</tr>
57-
</table>
589
</body>
5910
</html>

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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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
}

src/com/magento/idea/magento2plugin/reference/provider/EventNameReferenceProvider.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.reference.provider;
67

78
import com.intellij.openapi.util.text.StringUtil;
@@ -15,52 +16,63 @@
1516
import com.intellij.util.indexing.FileBasedIndex;
1617
import com.jetbrains.php.lang.PhpFileType;
1718
import com.jetbrains.php.lang.psi.PhpFile;
18-
import com.magento.idea.magento2plugin.util.php.PhpPatternsHelper;
1919
import com.magento.idea.magento2plugin.reference.xml.PolyVariantReferenceBase;
2020
import com.magento.idea.magento2plugin.stubs.indexes.EventNameIndex;
21-
import org.jetbrains.annotations.NotNull;
22-
21+
import com.magento.idea.magento2plugin.util.php.PhpPatternsHelper;
2322
import java.util.ArrayList;
2423
import java.util.Collection;
2524
import java.util.List;
25+
import org.jetbrains.annotations.NotNull;
2626

2727
public class EventNameReferenceProvider extends PsiReferenceProvider {
2828

2929
@NotNull
3030
@Override
31-
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
32-
String value = StringUtil.unquoteString(element.getText());
33-
Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance()
34-
.getContainingFiles(EventNameIndex.KEY, value,
35-
GlobalSearchScope.getScopeRestrictedByFileTypes(
36-
GlobalSearchScope.allScope(element.getProject()),
37-
PhpFileType.INSTANCE
38-
)
39-
);
31+
public PsiReference[] getReferencesByElement(
32+
@NotNull final PsiElement element,
33+
@NotNull final ProcessingContext context
34+
) {
35+
final String value = StringUtil.unquoteString(element.getText());
36+
final List<PsiReference> psiReferences = new ArrayList<>();
37+
final Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance()
38+
.getContainingFiles(
39+
EventNameIndex.KEY,
40+
value,
41+
GlobalSearchScope.getScopeRestrictedByFileTypes(
42+
GlobalSearchScope.allScope(element.getProject()),
43+
PhpFileType.INSTANCE
44+
)
45+
);
4046

41-
PsiManager psiManager = PsiManager.getInstance(element.getProject());
42-
for (VirtualFile virtualFile: containingFiles) {
43-
PhpFile phpFile = (PhpFile) psiManager.findFile(virtualFile);
47+
final PsiManager psiManager = PsiManager.getInstance(element.getProject());
48+
final List<PsiElement> psiElements = new ArrayList<>();
49+
for (final VirtualFile virtualFile: containingFiles) {
50+
final PhpFile phpFile = (PhpFile) psiManager.findFile(virtualFile);
4451
if (phpFile != null) {
45-
List<PsiElement> psiElements = new ArrayList<>();
4652
recursiveFill(psiElements, phpFile, value);
47-
if (psiElements.size() > 0) {
48-
return new PsiReference[] {new PolyVariantReferenceBase(element, psiElements)};
53+
if (!psiElements.isEmpty()) {
54+
psiReferences.add(new PolyVariantReferenceBase(element, psiElements));//NOPMD
55+
break;
4956
}
5057
}
5158
}
52-
return PsiReference.EMPTY_ARRAY;
59+
60+
return psiReferences.toArray(new PsiReference[0]);
5361
}
5462

55-
private void recursiveFill(List<PsiElement> psiElements, PsiElement psiElement, String typeName) {
63+
private void recursiveFill(
64+
final List<PsiElement> psiElements,
65+
final PsiElement psiElement,
66+
final String typeName
67+
) {
5668
if (PhpPatternsHelper.STRING_METHOD_ARGUMENT.accepts(psiElement)) {
5769
if (StringUtil.unquoteString(psiElement.getText()).equals(typeName)) {
5870
psiElements.add(psiElement);
5971
}
6072
return;
6173
}
6274

63-
for (PsiElement child: psiElement.getChildren()) {
75+
for (final PsiElement child: psiElement.getChildren()) {
6476
recursiveFill(psiElements, child, typeName);
6577
}
6678
}

src/com/magento/idea/magento2plugin/reference/provider/PhpJobMethodReferenceProvider.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ public class PhpJobMethodReferenceProvider extends PsiReferenceProvider {
2828

2929
@NotNull
3030
@Override
31-
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
32-
if (!(element instanceof XmlElement)) {
33-
return PsiReference.EMPTY_ARRAY;
34-
}
35-
36-
List<PsiReference> psiReferences = new ArrayList<>();
37-
38-
String methodName = StringUtil.unquoteString(element.getText());
31+
public PsiReference[] getReferencesByElement(
32+
@NotNull final PsiElement element,
33+
@NotNull final ProcessingContext context
34+
) {
35+
final List<PsiReference> psiReferences = new ArrayList<>();
36+
final String methodName = StringUtil.unquoteString(element.getText());
37+
final PhpClass phpClass = DiIndex.getPhpClassOfJobMethod((XmlElement) element);
3938

40-
PhpClass phpClass = DiIndex.getPhpClassOfJobMethod((XmlElement) element);
4139
if (phpClass != null) {
42-
Collection<Method> methods = phpClass.getMethods();
43-
methods.removeIf(method -> !method.getName().contains(methodName));
44-
psiReferences.add(new PolyVariantReferenceBase(element, methods));
40+
final Collection<Method> methods = phpClass.getMethods();
41+
methods.removeIf(method -> !method.getName().matches(methodName));
42+
if (!methods.isEmpty()) {
43+
psiReferences.add(new PolyVariantReferenceBase(element, methods));
44+
}
4545
}
4646

47-
return psiReferences.toArray(new PsiReference[psiReferences.size()]);
47+
return psiReferences.toArray(new PsiReference[0]);
4848
}
4949
}

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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 4 additions & 2 deletions
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>

0 commit comments

Comments
 (0)