Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1094 fix a new layout action error #1114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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