Skip to content

Commit 5d9122e

Browse files
committed
1263: Remove redundant field validation logic and enhance features.
Refactored redundant `validateFormFields()` checks across multiple dialogs to streamline code execution and reduce duplication. Introduced Magento folder management via the project settings, added support for marking directories as Magento content roots, and updated icons and versioning. Enhanced workflow for plugin releases with GitHub Actions.
1 parent 2a47a54 commit 5d9122e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+710
-368
lines changed

.github/workflows/asset.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This workflow will build a package using Gradle and then save it to Assets
2+
3+
name: Build Asset
4+
5+
on:
6+
release:
7+
types: [created]
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up JDK 17
15+
uses: actions/setup-java@v3
16+
with:
17+
java-version: 17
18+
distribution: 'temurin'
19+
cache: gradle
20+
- name: Gradle wrapper
21+
run: gradle wrapper
22+
- name: Grant execute permission for gradlew
23+
run: chmod +x gradlew
24+
25+
- name: Build Plugin
26+
run: ./gradlew buildPlugin
27+
28+
- name: Upload Plugin to Release Assets
29+
uses: actions/upload-release-asset@v1
30+
with:
31+
upload_url: ${{ github.event.release.upload_url }}
32+
asset_path: ./build/distributions/PhpStorm Magento 2 Plugin-${{ github.event.release.tag_name }}.zip
33+
asset_name: PhpStorm Magento 2 Plugin-${{ github.event.release.tag_name }}.zip
34+
asset_content_type: application/zip-archive
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).
66

7-
## 2025.0.1
7+
## 2025.1.0
88

99
### Fixed
1010

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pluginGroup = com.magento.idea.magento2plugin
22
pluginName = Magento PhpStorm
33
pluginRepositoryUrl = https://github.com/magento/magento2-phpstorm-plugin
4-
pluginVersion = 2025.0.1
5-
pluginSinceBuild = 233
4+
pluginVersion = 2025.1.0
5+
pluginSinceBuild = 243.3
66
pluginUntilBuild = 258.*
77
platformType = PS
88
platformVersion = 2024.3

src/main/java/com/magento/idea/magento2plugin/MagentoIcons.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ public class MagentoIcons {
1818
public static final Icon PLUGIN_ICON_MEDIUM =
1919
IconLoader.getIcon("/icons/pluginIcon64x64.svg", MagentoIcons.class);
2020
public static final Icon GRAPHQL = IconLoader.getIcon("/icons/graphql.svg", MagentoIcons.class);
21+
public static final Icon MARK_AS = IconLoader.getIcon("/icons/mark-as.svg", MagentoIcons.class);
2122
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.content.root;
7+
8+
import com.intellij.ide.projectView.ProjectView;
9+
import com.intellij.ide.projectView.actions.MarkRootActionBase;
10+
import com.intellij.openapi.actionSystem.*;
11+
import com.intellij.openapi.module.Module;
12+
import com.intellij.openapi.project.Project;
13+
import com.intellij.openapi.roots.ContentEntry;
14+
import com.intellij.openapi.vfs.VfsUtil;
15+
import com.intellij.openapi.vfs.VirtualFile;
16+
import com.intellij.psi.PsiDirectory;
17+
import com.intellij.psi.PsiElement;
18+
import com.magento.idea.magento2plugin.MagentoIcons;
19+
import com.magento.idea.magento2plugin.project.Settings;
20+
import com.magento.idea.magento2plugin.util.magento.MagentoPathUrlUtil;
21+
import org.jetbrains.annotations.NotNull;
22+
import java.net.MalformedURLException;
23+
import java.net.URL;
24+
25+
public class MarkDirectoryAsMagentoContentRot extends MarkRootActionBase {
26+
private Project project;
27+
28+
public MarkDirectoryAsMagentoContentRot() {
29+
super();
30+
final Presentation presentation = this.getTemplatePresentation();
31+
presentation.setIcon(MagentoIcons.MARK_AS);
32+
}
33+
34+
@Override
35+
protected void modifyRoots(final VirtualFile virtualFile, ContentEntry contentEntry) {
36+
if (project != null) {
37+
final Settings settings = Settings.getInstance(project);
38+
Settings.getInstance(project).addMagentoFolder(virtualFile.getUrl());
39+
if (settings.getMagentoFolders() != null) {
40+
settings.getMagentoFolders().removeIf(folder -> {
41+
final VirtualFile file;
42+
try {
43+
file = VfsUtil.findFileByURL(new URL(folder));
44+
} catch (MalformedURLException e) {
45+
return false;
46+
}
47+
return file == null || !file.exists();
48+
});
49+
}
50+
51+
ProjectView.getInstance(project).refresh();
52+
}
53+
}
54+
55+
@Override
56+
public void update(@NotNull final AnActionEvent event) {
57+
final DataContext context = event.getDataContext();
58+
final PsiElement targetElement = LangDataKeys.PSI_ELEMENT.getData(context);
59+
final Module module = event.getData(PlatformCoreDataKeys.MODULE);
60+
if (module != null) {
61+
project = module.getProject();
62+
}
63+
64+
if (targetElement instanceof PsiDirectory) {
65+
final Settings settings = Settings.getInstance(project);
66+
final String magentoPathUrl = MagentoPathUrlUtil.execute(project);
67+
final String directoryUrl = ((PsiDirectory) targetElement).getVirtualFile().getUrl();
68+
if (magentoPathUrl != null && magentoPathUrl.equals(directoryUrl)) {
69+
event.getPresentation().setEnabledAndVisible(false);
70+
return;
71+
}
72+
if (!settings.containsMagentoFolder(directoryUrl)) {
73+
event.getPresentation().setEnabledAndVisible(true);
74+
return;
75+
}
76+
}
77+
78+
event.getPresentation().setEnabledAndVisible(false);
79+
}
80+
81+
@Override
82+
protected boolean isEnabled(@NotNull RootsSelection rootsSelection, @NotNull Module module) {
83+
return false;
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.content.root;
7+
8+
import com.intellij.ide.projectView.ProjectView;
9+
import com.intellij.ide.projectView.actions.MarkRootActionBase;
10+
import com.intellij.openapi.actionSystem.*;
11+
import com.intellij.openapi.module.Module;
12+
import com.intellij.openapi.project.Project;
13+
import com.intellij.openapi.roots.ContentEntry;
14+
import com.intellij.openapi.vfs.VfsUtil;
15+
import com.intellij.openapi.vfs.VirtualFile;
16+
import com.intellij.psi.PsiDirectory;
17+
import com.intellij.psi.PsiElement;
18+
import com.magento.idea.magento2plugin.project.Settings;
19+
import com.magento.idea.magento2plugin.util.magento.MagentoPathUrlUtil;
20+
import org.jetbrains.annotations.NotNull;
21+
import java.net.MalformedURLException;
22+
import java.net.URL;
23+
24+
public class UnmarkDirectoryAsMagentoContentRot extends MarkRootActionBase {
25+
private Project project;
26+
27+
public UnmarkDirectoryAsMagentoContentRot() {
28+
super();
29+
}
30+
31+
@Override
32+
protected void modifyRoots(VirtualFile virtualFile, ContentEntry contentEntry) {
33+
if (project != null) {
34+
Settings settings = Settings.getInstance(project);
35+
Settings.getInstance(project).removeMagentoFolder(virtualFile.getUrl());
36+
if (settings.getMagentoFolders() != null) {
37+
settings.getMagentoFolders().removeIf(folder -> {
38+
VirtualFile file = null;
39+
try {
40+
file = VfsUtil.findFileByURL(new URL(folder));
41+
} catch (MalformedURLException e) {
42+
return false;
43+
}
44+
return file == null || !file.exists();
45+
});
46+
}
47+
48+
ProjectView.getInstance(project).refresh();
49+
}
50+
}
51+
52+
@Override
53+
public void update(@NotNull AnActionEvent event) {
54+
final DataContext context = event.getDataContext();
55+
final PsiElement targetElement = LangDataKeys.PSI_ELEMENT.getData(context);
56+
Module module = event.getData(PlatformCoreDataKeys.MODULE);
57+
if (module != null) {
58+
project = module.getProject();
59+
}
60+
61+
if (targetElement instanceof PsiDirectory) {
62+
Settings settings = Settings.getInstance(project);
63+
String magentoPathUrl = MagentoPathUrlUtil.execute(project);
64+
String directoryUrl = ((PsiDirectory) targetElement).getVirtualFile().getUrl();
65+
if (magentoPathUrl != null && magentoPathUrl.equals(directoryUrl)) {
66+
event.getPresentation().setEnabledAndVisible(false);
67+
return;
68+
}
69+
70+
if (settings.containsMagentoFolder(directoryUrl)) {
71+
event.getPresentation().setEnabledAndVisible(true);
72+
return;
73+
}
74+
}
75+
76+
event.getPresentation().setEnabledAndVisible(false);
77+
}
78+
79+
@Override
80+
protected boolean isEnabled(@NotNull RootsSelection rootsSelection, @NotNull Module module) {
81+
return false;
82+
}
83+
}

src/main/java/com/magento/idea/magento2plugin/actions/generation/NewModuleAction.java

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.magento.idea.magento2plugin.actions.generation.util.IsClickedDirectoryInsideProject;
2121
import com.magento.idea.magento2plugin.project.Settings;
2222
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
23+
import com.magento.idea.magento2plugin.util.magento.IsFileInEditableModuleUtil;
2324
import com.magento.idea.magento2plugin.util.magento.MagentoBasePathUtil;
2425
import org.jetbrains.annotations.NotNull;
2526

@@ -72,45 +73,56 @@ public void update(final AnActionEvent event) {
7273
return;
7374
}
7475

75-
if (Settings.isEnabled(project)) {
76-
final String magentoPath = Settings.getMagentoPath(project);
77-
if (magentoPath == null) {
78-
event.getPresentation().setVisible(false);
79-
return;
80-
}
81-
final PsiElement psiElement = event.getData(PlatformDataKeys.PSI_ELEMENT);
82-
if (!(psiElement instanceof PsiDirectory)) {
83-
event.getPresentation().setVisible(false);
84-
return;
85-
}
86-
87-
if (!IsClickedDirectoryInsideProject.getInstance().execute(
88-
project,
89-
(PsiDirectory) psiElement)
90-
) {
91-
event.getPresentation().setVisible(false);
92-
return;
93-
}
76+
if (!Settings.isEnabled(project)) {
77+
event.getPresentation().setVisible(false);
78+
}
79+
final String magentoPath = Settings.getMagentoPath(project);
80+
if (magentoPath == null) {
81+
event.getPresentation().setVisible(false);
82+
return;
83+
}
84+
final PsiElement psiElement = event.getData(PlatformDataKeys.PSI_ELEMENT);
85+
if (!(psiElement instanceof PsiDirectory)) {
86+
event.getPresentation().setVisible(false);
87+
return;
88+
}
9489

95-
final String moduleName = GetModuleNameByDirectoryUtil
96-
.execute((PsiDirectory) psiElement, project);
97-
if (moduleName == null) {
98-
final String sourceDirPath = ((PsiDirectory) psiElement).getVirtualFile().getPath();
99-
final boolean isCustomCodeSourceDirValid =
100-
MagentoBasePathUtil.isCustomCodeSourceDirValid(sourceDirPath);
101-
final boolean isCustomVendorDirValid =
102-
MagentoBasePathUtil.isCustomVendorDirValid(sourceDirPath);
90+
if (!IsClickedDirectoryInsideProject.getInstance().execute(
91+
project,
92+
(PsiDirectory) psiElement)
93+
) {
94+
event.getPresentation().setVisible(false);
95+
return;
96+
}
10397

104-
if (!isCustomCodeSourceDirValid && !isCustomVendorDirValid) { //NOPMD
105-
event.getPresentation().setVisible(false);
106-
return;
107-
}
108-
event.getPresentation().setVisible(true);
98+
final String moduleName = GetModuleNameByDirectoryUtil
99+
.execute((PsiDirectory) psiElement, project);
100+
if (moduleName == null) {
101+
if (showAction(project, (PsiDirectory) psiElement)) {
102+
event.getPresentation().setVisible(false);
109103
return;
110104
}
105+
event.getPresentation().setVisible(true);
111106
}
107+
}
108+
109+
/**
110+
* Determines whether the "Show Action" operation should be displayed
111+
*
112+
* @param project the current project
113+
* @param psiElement the directory
114+
* @return true if the action can be displayed; false otherwise
115+
*/
116+
private static boolean showAction(final Project project, final PsiDirectory psiElement) {
117+
final String sourceDirPath = psiElement.getVirtualFile().getPath();
118+
final boolean isCustomCodeSourceDirValid =
119+
MagentoBasePathUtil.isCustomCodeSourceDirValid(sourceDirPath);
120+
final boolean isCustomVendorDirValid =
121+
MagentoBasePathUtil.isCustomVendorDirValid(sourceDirPath);
112122

113-
event.getPresentation().setVisible(false);
123+
return !isCustomCodeSourceDirValid
124+
&& !isCustomVendorDirValid
125+
&& !IsFileInEditableModuleUtil.execute(project, psiElement.getVirtualFile());
114126
}
115127

116128
@Override

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ protected final void executeOnOk() {
9797
* Hook executed when the OK button is pressed.
9898
*/
9999
protected final void onOK() {
100-
executeOnOk();
100+
if (validateFormFields()) {
101+
executeOnOk();
102+
}
101103
}
102104

103105
/**

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,25 @@ protected void onWriteActionOK() {
175175
if (targetMethod == null) {
176176
targetMethod = getSelectedTargetMethod();
177177
}
178-
if (validateFormFields()) {
179-
new PluginClassGenerator(new PluginFileData(
180-
getPluginDirectory(),
181-
getPluginClassName(),
182-
getPluginType(),
183-
getPluginModule(),
184-
targetClass,
185-
targetMethod,
186-
getPluginClassFqn(),
187-
getNamespace()
188-
), project).generate(CreateAPluginAction.ACTION_NAME, true);
189-
190-
new PluginDiXmlGenerator(new PluginDiXmlData(
191-
getPluginArea(),
192-
getPluginModule(),
193-
targetClass,
194-
getPluginSortOrder(),
195-
getPluginName(),
196-
getPluginClassFqn()
197-
), project).generate(CreateAPluginAction.ACTION_NAME);
198-
}
178+
new PluginClassGenerator(new PluginFileData(
179+
getPluginDirectory(),
180+
getPluginClassName(),
181+
getPluginType(),
182+
getPluginModule(),
183+
targetClass,
184+
targetMethod,
185+
getPluginClassFqn(),
186+
getNamespace()
187+
), project).generate(CreateAPluginAction.ACTION_NAME, true);
188+
189+
new PluginDiXmlGenerator(new PluginDiXmlData(
190+
getPluginArea(),
191+
getPluginModule(),
192+
targetClass,
193+
getPluginSortOrder(),
194+
getPluginName(),
195+
getPluginClassFqn()
196+
), project).generate(CreateAPluginAction.ACTION_NAME);
199197
exit();
200198
}
201199

0 commit comments

Comments
 (0)