Skip to content

Commit

Permalink
Merge pull request #1114 from SilinMykola/1094-fix-new-layout-action
Browse files Browse the repository at this point in the history
1094 fix a new layout action error
  • Loading branch information
bohdan-harniuk authored Jun 15, 2022
2 parents 82829a5 + 5be28b2 commit 8486929
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
import com.magento.idea.magento2plugin.actions.context.xml.NewLayoutXmlAction;
import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData;
import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData;
import com.magento.idea.magento2plugin.actions.generation.dialog.util.DialogFieldErrorUtil;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlTemplateGenerator;
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
import com.magento.idea.magento2plugin.magento.packages.Areas;
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
import java.awt.event.KeyEvent;
Expand Down Expand Up @@ -122,7 +120,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 +186,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 8486929

Please sign in to comment.