Skip to content

Commit

Permalink
1094 fix a new layout action error
Browse files Browse the repository at this point in the history
  • Loading branch information
SilinMykola committed Jun 14, 2022
1 parent 82829a5 commit 851c8c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static void open(
* Fire generation process if all fields are valid.
*/
private void onOK() {
if (validateFormFields() && isUnderscoreCorrect()) {
if (validateFormFields()) {
final String[] layoutNameParts = getLayoutNameParts();
new LayoutXmlTemplateGenerator(
new LayoutXmlData(
Expand Down Expand Up @@ -188,51 +188,11 @@ private String[] getLayoutNameParts() {
actionName = layoutNameParts[2];
}

return new String[]{routeName, controllerName, actionName};
}

/**
* Check is count of underscore is correct in layout name.
*
* @return boolean
*/
private boolean isUnderscoreCorrect() {
final String name = layoutName.getText().trim();

if (name.contains("_")) {
final int count = countUnderscore(name);

if (count != 0 && count != 2) {
DialogFieldErrorUtil.showErrorMessageForField(
layoutName,
layoutNameErrorMessage,
new ValidatorBundle()
.message("validator.layoutNameUnderscoreQtyInvalid")
);

return false;
}
if (layoutNameParts.length == 2 || layoutNameParts.length > 3) { // NOPMD
routeName = layoutName.getText().trim();
}

return true;
}

/**
* Count underscore symbols in string.
*
* @param name String
* @return int
*/
private int countUnderscore(final String name) {
int count = 0;

for (int i = 0; i < name.length(); i++) {
if (name.charAt(i) == '_') { //NOPMD
count++;
}
}

return count;
return new String[]{routeName, controllerName, actionName};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/com/magento/idea/magento2plugin/util/RegExUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class RegExUtil {
= "(\\d+)\\.(\\d+)\\.(\\d+)[a-zA-Z0-9_\\-]*";

public static final String LAYOUT_NAME
= "^([a-zA-Z0-9]+){1,}(_[a-zA-Z0-9]+){0,2}";
= "^([a-zA-Z0-9]+){1}(_[a-zA-Z0-9]+){0,}";

public static class Magento {

Expand Down

0 comments on commit 851c8c5

Please sign in to comment.