Skip to content

Error in the console (New Module Action) #519

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

Merged
merged 2 commits into from
Mar 29, 2021
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
5 changes: 5 additions & 0 deletions src/com/magento/idea/magento2plugin/util/RegExUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ public static class XmlRegex {
public static final String CLASS_ELEMENT =
"\\\\?" + PhpRegex.FQN + "(" + CLASS_MEMBER_NAME + ")?.*";
}

public static class CustomTheme {
public static final String MODULE_NAME =
"app\\/design\\/(adminhtml|frontend)\\/\\w*\\/\\w*\\/\\w*";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import com.magento.idea.magento2plugin.magento.files.RegistrationPhp;
import com.magento.idea.magento2plugin.util.RegExUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jetbrains.annotations.Nullable;

public final class GetModuleNameByDirectoryUtil {
public static final int THEME_SPLIT_COUNT = 1;
public static final String THEME_DIRECTORY_REGEX = "app\\/design\\/(adminhtml|frontend)\\/";

private GetModuleNameByDirectoryUtil() {}

Expand All @@ -34,10 +34,14 @@ public static String execute(
final Project project
) {
// Check if directory is theme directory and return module name from directory path if yes
final String[] splits = psiDirectory.getVirtualFile().getPath()
.split(THEME_DIRECTORY_REGEX);
if (splits.length > THEME_SPLIT_COUNT) {
return splits[1].split("\\/")[2];
final String path = psiDirectory.getVirtualFile().getPath();
final Pattern pattern = Pattern.compile(RegExUtil.CustomTheme.MODULE_NAME);
final Matcher matcher = pattern.matcher(path);
while (matcher.find()) {
final String moduleNamePath = matcher.group(0);
if (!moduleNamePath.isEmpty()) {
return moduleNamePath.split("/")[5];
}
}

final PhpFile registrationPhp = getRegistrationPhpRecursively(
Expand Down