Skip to content

Commit cb4d358

Browse files
committed
Fixed override interface by preference bug
1 parent e73d50b commit cb4d358

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

resources/fileTemplates/internal/Magento Preference Class.php.ft

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ namespace ${NAMESPACE};
99
use ${USE};
1010
#end
1111

12-
class ${NAME} #if (${EXTENDS})extends ${EXTENDS}#end {
12+
#if (${INTERFACE})interface#else class#end ${NAME} #if (${EXTENDS})extends ${EXTENDS}#end {
1313

1414
}

src/com/magento/idea/magento2plugin/actions/generation/OverrideClassByAPreferenceAction.java

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
public class OverrideClassByAPreferenceAction extends DumbAwareAction {
2323
public static final String ACTION_NAME = "Override this class by a new Preference";
2424
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Preference";
25+
public static final String INTERFACE_ACTION = "Override this interface by a new Preference";
2526
private final GetFirstClassOfFile getFirstClassOfFile;
2627
private PhpClass targetClass;
2728

@@ -44,6 +45,9 @@ public void update(final AnActionEvent event) {
4445
targetClass = phpClass;
4546
if (psiFile instanceof PhpFile && phpClass != null) {
4647
this.setStatus(event, true);
48+
if (phpClass.isInterface()) {
49+
event.getPresentation().setText(INTERFACE_ACTION);
50+
}
4751
} else {
4852
this.setStatus(event, false);
4953
}

src/com/magento/idea/magento2plugin/actions/generation/data/PreferenceFileData.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class PreferenceFileData {
1414
private String preferenceFqn;
1515
private String namespace;
1616
private boolean inheritClass;
17+
private boolean isInterface;
1718

1819
public PreferenceFileData(
1920
String preferenceDirectory,
@@ -22,7 +23,8 @@ public PreferenceFileData(
2223
PhpClass targetClass,
2324
String preferenceFqn,
2425
String namespace,
25-
boolean inheritClass
26+
boolean inheritClass,
27+
boolean isInterface
2628
) {
2729
this.preferenceDirectory = preferenceDirectory;
2830
this.preferenceClassName = preferenceClassName;
@@ -31,6 +33,7 @@ public PreferenceFileData(
3133
this.preferenceFqn = preferenceFqn;
3234
this.namespace = namespace;
3335
this.inheritClass = inheritClass;
36+
this.isInterface = isInterface;
3437
}
3538

3639
public String getPreferenceClassName() {
@@ -60,4 +63,8 @@ public String getNamespace() {
6063
public boolean isInheritClass() {
6164
return inheritClass;
6265
}
66+
67+
public boolean isInterface() {
68+
return isInterface;
69+
}
6370
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class OverrideClassByAPreferenceDialog extends AbstractDialog { //NOPMD
4848
@NotNull
4949
private final Project project;
5050
private final PhpClass targetClass;
51+
private boolean isInterface;
5152
private JPanel contentPane;
5253
private JButton buttonOK;
5354
private JButton buttonCancel;
@@ -98,6 +99,7 @@ public OverrideClassByAPreferenceDialog(
9899
this.targetClass = targetClass;
99100
this.validatorBundle = new ValidatorBundle();
100101
this.commonBundle = new CommonBundle();
102+
this.isInterface = false;
101103

102104
setContentPane(contentPane);
103105
setModal(true);
@@ -108,6 +110,9 @@ public OverrideClassByAPreferenceDialog(
108110
inheritClass.setVisible(false);
109111
inheritClassLabel.setVisible(false);
110112
}
113+
if (targetClass.isInterface()) {
114+
this.isInterface = true;
115+
}
111116
suggestPreferenceClassName(targetClass);
112117
suggestPreferenceDirectory(targetClass);
113118

@@ -188,7 +193,8 @@ protected void onOK() {
188193
targetClass,
189194
getPreferenceClassFqn(),
190195
getNamespace(),
191-
isInheritClass()
196+
isInheritClass(),
197+
isInterface
192198
), project).generate(OverrideClassByAPreferenceAction.ACTION_NAME, true);
193199

194200
this.setVisible(false);

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

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ protected void fillAttributes(Properties attributes) {
7979
String preferenceClassName = preferenceFileData.getPreferenceClassName();
8080
attributes.setProperty("NAME", preferenceClassName);
8181
attributes.setProperty("NAMESPACE", preferenceFileData.getNamespace());
82+
if (preferenceFileData.isInterface()) {
83+
attributes.setProperty("INTERFACE", "interface");
84+
}
8285
if (!preferenceFileData.isInheritClass()) {
8386
return;
8487
}

0 commit comments

Comments
 (0)