Skip to content

Commit 7b19f16

Browse files
committed
Added inspection error for invalid disabled observer name
1 parent de2a60c commit 7b19f16

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

resources/magento2/inspection.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ inspection.plugin.error.redundantParameter=Redundant parameter
1515
inspection.plugin.error.typeIncompatibility=Possible type incompatibility. Consider changing the parameter according to the target method.
1616
inspection.observer.duplicateInSameFile=The observer name already used in this file. For more details see Inspection Description.
1717
inspection.observer.duplicateInOtherPlaces=The observer name "{0}" for event "{1}" is already used in the module "{2}" ({3} scope). For more details see Inspection Description.
18+
inspection.observer.disabledObserverDoesNotExist=This observer does not exist to be disabled. For more details, see Inspection Description.
1819
inspection.cache.disabledCache=Cacheable false attribute on the default layout will disable cache site-wide
1920
inspection.moduleDeclaration.warning.wrongModuleName=Provided module name "{0}" does not match expected "{1}"
2021
inspection.moduleDeclaration.fix=Fix module name

src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ public void visitFile(final PsiFile file) {
9494
final XmlAttribute observerDisabledAttribute =
9595
observerXmlTag.getAttribute("disabled");
9696

97-
if (observerNameAttribute == null || (
98-
observerDisabledAttribute != null//NOPMD
99-
&& observerDisabledAttribute.getValue().equals("true"))
100-
) {
97+
if (observerNameAttribute == null) {
10198
continue;
10299
}
103100

@@ -122,6 +119,21 @@ public void visitFile(final PsiFile file) {
122119
eventIndex,
123120
file
124121
);
122+
123+
if (observerDisabledAttribute != null
124+
&& observerDisabledAttribute.getValue() != null
125+
&& observerDisabledAttribute.getValue().equals("true")
126+
&& modulesWithSameObserverName.isEmpty()
127+
) {
128+
problemsHolder.registerProblem(
129+
observerNameAttribute.getValueElement(),
130+
inspectionBundle.message(
131+
"inspection.observer.disabledObserverDoesNotExist"
132+
),
133+
errorSeverity
134+
);
135+
}
136+
125137
for (final HashMap<String, String> moduleEntry:
126138
modulesWithSameObserverName) {
127139
final Map.Entry<String, String> module = moduleEntry

0 commit comments

Comments
 (0)