Skip to content

Commit 91444a3

Browse files
author
m.mezhensky
committed
Merge branch 'description-for-graphql-resolver-templates' of github.com:mmezhensky/magento2-phpstorm-plugin into description-for-graphql-resolver-templates
2 parents fe85be2 + 20d8e73 commit 91444a3

File tree

10 files changed

+419
-4
lines changed

10 files changed

+419
-4
lines changed

resources/META-INF/plugin.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@
131131
level="WARNING"
132132
implementationClass="com.magento.idea.magento2plugin.inspections.xml.ObserverDeclarationInspection"/>
133133

134+
<localInspection language="XML" groupPath="XML"
135+
shortName="PluginDeclarationInspection"
136+
displayName="Duplicated Plugin Usage in di XML"
137+
groupName="Magento 2"
138+
enabledByDefault="true"
139+
level="WARNING"
140+
implementationClass="com.magento.idea.magento2plugin.inspections.xml.PluginDeclarationInspection"/>
141+
134142
<localInspection language="XML" groupPath="XML"
135143
shortName="CacheableFalseInDefaultLayoutInspection"
136144
displayName="Inspection for disabled cache site-wide"

resources/fileTemplates/code/Magento Module Events Xml Observer.xml.html

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,46 @@
66
-->
77
<html>
88
<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+
Observers are a certain type of Magento class that can influence general behavior, performance, or change business logic.
13+
Observers are executed whenever the event they are configured to watch is dispatched by the eobservent manager.
14+
</font><br>
15+
</td>
16+
</tr>
17+
<tr>
18+
<td><font face="verdana" size="-1">
19+
A observer is declared (registered) for a class in the di.xml file.
20+
</font><br>
21+
</td>
22+
</tr>
23+
<tr>
24+
<td><font face="verdana" size="-1">
25+
<a href="https://devdocs.magento.com/guides/v2.3/extension-dev-guide/events-and-observers.html#observers">Read more</a> about Observer, including when those can be used.
26+
</font><br>
27+
</td>
28+
</tr>
29+
</table>
30+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
31+
<tr>
32+
<td colspan="3"><font face="verdana" size="-1">Predefined variables will take the following values:</font></td>
33+
</tr>
34+
<tr>
35+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${EVENT_NAME}</b></font></nobr></td>
36+
<td width="10">&nbsp;</td>
37+
<td width="100%" valign="top"><font face="verdana" size="-1">The name of the observer for the event definition.</font></td>
38+
</tr>
39+
<tr>
40+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${OBSERVER_NAME}</b></font></nobr></td>
41+
<td width="10">&nbsp;</td>
42+
<td width="100%" valign="top"><font face="verdana" size="-1">Observer name.</font></td>
43+
</tr>
44+
<tr>
45+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${OBSERVER_CLASS}</b></font></nobr></td>
46+
<td width="10">&nbsp;</td>
47+
<td width="100%" valign="top"><font face="verdana" size="-1">The fully qualified class name of the observer.</font></td>
48+
</tr>
49+
</table>
950
</body>
10-
</html>
51+
</html>

resources/fileTemplates/code/Magento Observer Execute Method.php.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,23 @@
66
-->
77
<html>
88
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">Your observer class should implement Magento\Framework\Event\ObserverInterface and define its execute function.
12+
One of the more powerful feature of observers is that they are able to use parameters passed into the event when it was dispatched
13+
</font><br>
14+
</td>
15+
</tr>
16+
</table>
17+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
18+
<tr>
19+
<td colspan="3"><font face="verdana" size="-1">Predefined variables will take the following values:</font></td>
20+
</tr>
21+
<tr>
22+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${EVENT_NAME}</b></font></nobr></td>
23+
<td width="10">&nbsp;</td>
24+
<td width="100%" valign="top"><font face="verdana" size="-1">The name of the observer for the event definition.</font></td>
25+
</tr>
26+
</table>
927
</body>
1028
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
2+
inspection.plugin.duplicateInOtherPlaces=The plugin name "{0}" for targeted "{1}" class is already used in the module "{2}" ({3} scope). For more details see Inspection Description.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.bundles;
7+
8+
public class InspectionBundle extends AbstractBundle {
9+
protected final String BUNDLE_NAME = "magento2.inspection";
10+
11+
public String getBundleName() {
12+
return BUNDLE_NAME;
13+
}
14+
}

src/com/magento/idea/magento2plugin/indexes/IndexManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.intellij.util.indexing.FileBasedIndexImpl;
88
import com.intellij.util.indexing.ID;
99
import com.magento.idea.magento2plugin.stubs.indexes.*;
10+
import com.magento.idea.magento2plugin.stubs.indexes.PluginIndex;
1011
import com.magento.idea.magento2plugin.stubs.indexes.js.MagentoLibJsIndex;
1112
import com.magento.idea.magento2plugin.stubs.indexes.js.RequireJsIndex;
1213
import com.magento.idea.magento2plugin.stubs.indexes.graphql.GraphQlResolverIndex;
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+
package com.magento.idea.magento2plugin.indexes;
6+
7+
import com.intellij.openapi.project.Project;
8+
import com.intellij.openapi.vfs.VirtualFile;
9+
import com.intellij.psi.PsiElement;
10+
import com.intellij.psi.PsiManager;
11+
import com.intellij.psi.search.GlobalSearchScope;
12+
import com.intellij.psi.xml.XmlAttributeValue;
13+
import com.intellij.psi.xml.XmlFile;
14+
import com.intellij.util.indexing.FileBasedIndex;
15+
import com.magento.idea.magento2plugin.magento.files.ModuleDiXml;
16+
import com.magento.idea.magento2plugin.xml.XmlPsiTreeUtil;
17+
18+
import java.util.ArrayList;
19+
import java.util.Collection;
20+
21+
public class PluginIndex {
22+
23+
private static PluginIndex INSTANCE;
24+
25+
private Project project;
26+
27+
private PluginIndex() {
28+
}
29+
30+
public static PluginIndex getInstance(final Project project) {
31+
if (null == INSTANCE) {
32+
INSTANCE = new PluginIndex();
33+
}
34+
INSTANCE.project = project;
35+
36+
return INSTANCE;
37+
}
38+
39+
public Collection<PsiElement> getPluginElements(final String name, final GlobalSearchScope scope) {
40+
Collection<PsiElement> result = new ArrayList<>();
41+
42+
Collection<VirtualFile> virtualFiles =
43+
FileBasedIndex.getInstance().getContainingFiles(
44+
com.magento.idea.magento2plugin.stubs.indexes.PluginIndex.KEY,
45+
name,
46+
scope
47+
);
48+
49+
for (VirtualFile virtualFile : virtualFiles) {
50+
XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(virtualFile);
51+
Collection<XmlAttributeValue> valueElements = XmlPsiTreeUtil
52+
.findAttributeValueElements(xmlFile, ModuleDiXml.PLUGIN_TYPE_ATTRIBUTE, ModuleDiXml.PLUGIN_TYPE_ATTR_NAME, name);
53+
result.addAll(valueElements);
54+
}
55+
return result;
56+
}
57+
}

0 commit comments

Comments
 (0)