Skip to content

Commit 83fc536

Browse files
Merge branch '4.3.0-develop' of github.com:magento/magento2-phpstorm-plugin into 967-add-context-action-to-create-layout-xml-file
2 parents 66394a6 + 2dd6eac commit 83fc536

File tree

33 files changed

+3054
-4
lines changed

33 files changed

+3054
-4
lines changed

resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
<action id="MagentoCreateAWebApiInterfaceForService.Menu" class="com.magento.idea.magento2plugin.actions.generation.NewWebApiInterfaceAction">
128128
<add-to-group group-id="EditorPopupMenu"/>
129129
</action>
130+
<action id="MagentoInjectConstructorArgumentAction.Menu" class="com.magento.idea.magento2plugin.actions.generation.InjectConstructorArgumentAction">
131+
<add-to-group group-id="EditorPopupMenu"/>
132+
</action>
130133

131134
<action id="CopyMagentoPath"
132135
class="com.magento.idea.magento2plugin.actions.CopyMagentoPath"

resources/magento2/validation.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ validator.alphaAndDashCharacters=The {0} field must contain alphabets and dashes
99
validator.alreadyDeclared={0} is already declared in the {1} module
1010
validator.startWithNumberOrCapitalLetter=The {0} field must start with a number or a capital letter
1111
validator.onlyNumbers=The {0} field must contain numbers only
12+
validator.onlyIntegerOrFloatNumbers=The {0} field must contain only integer or float numbers
1213
validator.mustNotBeNegative={0} must not be negative
1314
validator.identifier=The {0} field must contain letters, numbers, dashes, and underscores only
1415
validator.identifier.colon=The {0} field must contain letters, numbers, colons, dashes, and underscores only
@@ -41,5 +42,8 @@ validator.lowerSnakeCase=The {0} field must be of the lower snake case format
4142
validator.menuIdentifierInvalid=The menu identifier is invalid
4243
validator.someFieldsHaveErrors=Please, check the dialog. Some fields have errors
4344
validator.dbSchema.invalidColumnType=Invalid ''{0}'' column type specified
45+
validator.arrayValuesDialog.invalidValueForRowWithName=Invalid value ''{0}'' specified for the row with name ''{1}''
46+
validator.arrayValuesDialog.namesMustBeUnique=Duplicated items names
47+
validator.arrayValuesDialog.nameMustNotBeEmpty=The array name cannot be empty
4448
validator.layoutNameRuleInvalid=The layout name is invalid
4549
validator.layoutNameUnderscoreQtyInvalid=Wrong layout name, please check
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.openapi.actionSystem.AnAction;
9+
import com.intellij.openapi.actionSystem.AnActionEvent;
10+
import com.intellij.openapi.project.Project;
11+
import com.jetbrains.php.lang.psi.elements.Method;
12+
import com.jetbrains.php.lang.psi.elements.Parameter;
13+
import com.jetbrains.php.lang.psi.elements.PhpClass;
14+
import com.magento.idea.magento2plugin.MagentoIcons;
15+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewArgumentInjectionDialog;
16+
import com.magento.idea.magento2plugin.magento.packages.MagentoPhpClass;
17+
import com.magento.idea.magento2plugin.project.Settings;
18+
import com.magento.idea.magento2plugin.util.RegExUtil;
19+
import com.magento.idea.magento2plugin.util.php.PhpPsiElementsUtil;
20+
import org.jetbrains.annotations.NotNull;
21+
22+
public class InjectConstructorArgumentAction extends AnAction {
23+
24+
public static final String ACTION_NAME = "Inject argument";
25+
public static final String ACTION_DESCRIPTION = "Inject argument through the DI";
26+
public static final String GATHER_ARRAY_VALUES_ACTION_DESCRIPTION = "Specify array values";
27+
private PhpClass currentPhpClass;
28+
private Parameter currentParameter;
29+
30+
/**
31+
* Inject constructor argument action constructor.
32+
*/
33+
public InjectConstructorArgumentAction() {
34+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
35+
}
36+
37+
@Override
38+
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
39+
public void update(final @NotNull AnActionEvent event) {
40+
setIsAvailableForEvent(event, false);
41+
final Project project = event.getProject();
42+
43+
if (project == null || !Settings.isEnabled(project)) {
44+
return;
45+
}
46+
final PhpClass phpClass = PhpPsiElementsUtil.getPhpClass(event);
47+
48+
if (phpClass == null) {
49+
return;
50+
}
51+
// Excluding argument injection generators for Test/ and *Test.php files
52+
// in order to not overload the context menu.
53+
final String filename = phpClass.getContainingFile().getName();
54+
55+
if (filename.matches(RegExUtil.Magento.TEST_FILE_NAME)
56+
|| phpClass.getPresentableFQN().matches(RegExUtil.Magento.TEST_CLASS_FQN)) {
57+
return;
58+
}
59+
final Parameter parameter = PhpPsiElementsUtil.getMethodArgument(event);
60+
61+
if (parameter == null) {
62+
return;
63+
}
64+
final Method method = parameter.getParent().getParent() instanceof Method
65+
? (Method) parameter.getParent().getParent() : null;
66+
67+
if (method == null) {
68+
return;
69+
}
70+
71+
if (!method.getAccess().isPublic()
72+
|| !MagentoPhpClass.CONSTRUCT_METHOD_NAME.equals(method.getName())) {
73+
return;
74+
}
75+
currentPhpClass = phpClass;
76+
currentParameter = parameter;
77+
setIsAvailableForEvent(event, true);
78+
}
79+
80+
@Override
81+
public void actionPerformed(final @NotNull AnActionEvent event) {
82+
if (event.getProject() == null
83+
|| currentPhpClass == null
84+
|| currentParameter == null) {
85+
return;
86+
}
87+
88+
NewArgumentInjectionDialog.open(
89+
event.getProject(),
90+
currentPhpClass,
91+
currentParameter
92+
);
93+
}
94+
95+
/**
96+
* Set is action available for event.
97+
*
98+
* @param event AnActionEvent
99+
* @param isAvailable boolean
100+
*/
101+
private void setIsAvailableForEvent(
102+
final @NotNull AnActionEvent event,
103+
final boolean isAvailable
104+
) {
105+
event.getPresentation().setVisible(isAvailable);
106+
event.getPresentation().setEnabled(isAvailable);
107+
}
108+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data.xml;
7+
8+
import com.magento.idea.magento2plugin.magento.packages.Areas;
9+
import com.magento.idea.magento2plugin.magento.packages.DiArgumentType;
10+
import org.jetbrains.annotations.NotNull;
11+
12+
public class DiArgumentData {
13+
14+
private final String moduleName;
15+
private final String clazz;
16+
private final String parameter;
17+
private final Areas area;
18+
private final DiArgumentType valueType;
19+
private final String value;
20+
21+
/**
22+
* DI argument DTO constructor.
23+
*
24+
* @param moduleName String
25+
* @param clazz String
26+
* @param parameter String
27+
* @param area Areas
28+
* @param valueType DiArgumentType
29+
* @param value String
30+
*/
31+
public DiArgumentData(
32+
final @NotNull String moduleName,
33+
final @NotNull String clazz,
34+
final @NotNull String parameter,
35+
final @NotNull Areas area,
36+
final @NotNull DiArgumentType valueType,
37+
final @NotNull String value
38+
) {
39+
this.moduleName = moduleName;
40+
this.clazz = clazz;
41+
this.parameter = parameter;
42+
this.area = area;
43+
this.valueType = valueType;
44+
this.value = value;
45+
}
46+
47+
/**
48+
* Get module name.
49+
*
50+
* @return String
51+
*/
52+
public String getModuleName() {
53+
return moduleName;
54+
}
55+
56+
/**
57+
* Get target class.
58+
*
59+
* @return String
60+
*/
61+
public String getClazz() {
62+
return clazz;
63+
}
64+
65+
/**
66+
* Get target parameter.
67+
*
68+
* @return String
69+
*/
70+
public String getParameter() {
71+
return parameter;
72+
}
73+
74+
/**
75+
* Get target area.
76+
*
77+
* @return Areas
78+
*/
79+
public Areas getArea() {
80+
return area;
81+
}
82+
83+
/**
84+
* Get argument value xsi:type.
85+
*
86+
* @return DiArgumentType
87+
*/
88+
public DiArgumentType getValueType() {
89+
return valueType;
90+
}
91+
92+
/**
93+
* Get argument value.
94+
*
95+
* @return String
96+
*/
97+
public String getValue() {
98+
return value;
99+
}
100+
}

0 commit comments

Comments
 (0)