Skip to content

Commit 8b4198d

Browse files
author
Vitaliy
authored
Merge pull request #523 from bohdan-harniuk/php-file-generators-refactoring
Php file generators refactoring - model, resource model, collection, save entity command, etc.
2 parents 18fbdcc + 22d7358 commit 8b4198d

File tree

128 files changed

+3092
-1278
lines changed

Some content is hidden

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

128 files changed

+3092
-1278
lines changed

resources/META-INF/plugin.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<idea-plugin>
7+
<idea-plugin require-restart="true">
88
<id>com.magento.idea.magento2plugin</id>
99
<name>Magento PhpStorm</name>
1010
<version>3.2.0</version>
@@ -66,6 +66,7 @@
6666
<action id="MagentoCreateAViewModel" class="com.magento.idea.magento2plugin.actions.generation.NewViewModelAction" />
6767
<action id="MagentoCreateAGraphQlResolver" class="com.magento.idea.magento2plugin.actions.generation.NewGraphQlResolverAction" />
6868
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
69+
<action id="MagentoCreateEmailTemplate" class="com.magento.idea.magento2plugin.actions.generation.NewEmailTemplateAction" />
6970
<action id="MagentoCreateUiComponentGrid" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction" />
7071
<action id="MagentoCreateUiComponentForm" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction" />
7172
<action id="NewModelsAction" class="com.magento.idea.magento2plugin.actions.generation.NewModelsAction" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<template id="${ID}" label="${LABEL}" file="${FILE_NAME}.html" type="${TYPE}" module="${MODULE}" area="${AREA}"/>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td>
12+
<font face="verdana" size="-1">Email templates configuration.</font>
13+
</td>
14+
</tr>
15+
</table>
16+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
17+
<tr>
18+
<td colspan="3"><font face="verdana" size="-1">Predefined variables explanation:</font></td>
19+
</tr>
20+
<tr>
21+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${ID}</b></font></nobr></td>
22+
<td width="10">&nbsp;</td>
23+
<td width="100%" valign="top"><font face="verdana" size="-1">Email template ID.</font></td>
24+
</tr>
25+
<tr>
26+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${LABEL}</b></font></nobr></td>
27+
<td width="10">&nbsp;</td>
28+
<td width="100%" valign="top"><font face="verdana" size="-1">Email Template Label.</font></td>
29+
</tr>
30+
<tr>
31+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${FILE_NAME}</b></font></nobr></td>
32+
<td width="10">&nbsp;</td>
33+
<td width="100%" valign="top"><font face="verdana" size="-1">Email template file name.</font></td>
34+
</tr>
35+
<tr>
36+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${TYPE}</b></font></nobr></td>
37+
<td width="10">&nbsp;</td>
38+
<td width="100%" valign="top"><font face="verdana" size="-1">Email template type. (HTML or TEXT)</font></td>
39+
</tr>
40+
<tr>
41+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${MODULE}</b></font></nobr></td>
42+
<td width="10">&nbsp;</td>
43+
<td width="100%" valign="top"><font face="verdana" size="-1">Module's name.</font></td>
44+
</tr>
45+
<tr>
46+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${AREA}</b></font></nobr></td>
47+
<td width="10">&nbsp;</td>
48+
<td width="100%" valign="top"><font face="verdana" size="-1">Email template area. (Adminhtml or Frontend)</font></td>
49+
</tr>
50+
</table>
51+
</body>
52+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!--@subject {{trans "${SUBJECT}"}} @-->
2+
<!--@vars {} @-->
3+
4+
#if (${HTML_TYPE}){{template config_path="design/email/header_template"}}#end
5+
6+
<!-- @todo: implement ${TYPE} template -->
7+
#if (${HTML_TYPE}){{template config_path="design/email/footer_template"}}#end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td>
12+
<font face="verdana" size="-1">Email template.</font>
13+
</td>
14+
</tr>
15+
</table>
16+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
17+
<tr>
18+
<td colspan="3"><font face="verdana" size="-1">Predefined variables explanation:</font></td>
19+
</tr>
20+
<tr>
21+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${SUBJECT}</b></font></nobr></td>
22+
<td width="10">&nbsp;</td>
23+
<td width="100%" valign="top"><font face="verdana" size="-1">Email subject.</font></td>
24+
</tr>
25+
<tr>
26+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${HTML_TYPE}</b></font></nobr></td>
27+
<td width="10">&nbsp;</td>
28+
<td width="100%" valign="top"><font face="verdana" size="-1">Defines if it's HTML type template.</font></td>
29+
</tr>
30+
<tr>
31+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${TYPE}</b></font></nobr></td>
32+
<td width="10">&nbsp;</td>
33+
<td width="100%" valign="top"><font face="verdana" size="-1">Email template type. (HTML or TEXT)</font></td>
34+
</tr>
35+
</table>
36+
</body>
37+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
3+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
4+
</config>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td>
12+
<font face="verdana" size="-1">Email templates configurations.</font>
13+
</td>
14+
</tr>
15+
</table>
16+
</body>
17+
</html>

resources/magento2/common.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,8 @@ common.addToolbarFullTextSearch=Add Toolbar Full Text Search
6464
common.addToolbarColumnsControl=Add Toolbar Columns Control
6565
common.addToolbarBookmarks=Add Toolbar Bookmarks
6666
common.argument=Argument name
67+
common.template.id=Template ID
68+
common.template.label=Template Label
69+
common.template.filename=Template File Name
70+
common.template.subject=Email Subject
71+
common.template.type=Email Type

src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.intellij.openapi.project.Project;
1313
import com.intellij.openapi.vfs.VirtualFile;
1414
import com.intellij.psi.PsiDirectory;
15+
import com.intellij.psi.PsiFile;
1516
import com.intellij.psi.PsiManager;
1617
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
1718
import org.jetbrains.annotations.NotNull;
@@ -24,13 +25,15 @@ public class CopyMagentoPath extends CopyPathProvider {
2425
private final String[] templatePaths = {
2526
"view/frontend/templates/",
2627
"view/adminhtml/templates/",
27-
"view/base/templates/"
28+
"view/base/templates/",
29+
"templates/"
2830
};
2931

3032
@Override
3133
public void update(@NotNull final AnActionEvent event) {
3234
final VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
33-
if (virtualFile != null && virtualFile.isDirectory()) {
35+
if (virtualFile != null && virtualFile.isDirectory()
36+
|| virtualFile != null && !PHTML.equals(virtualFile.getExtension())) {
3437
event.getPresentation().setVisible(false);
3538
}
3639
}
@@ -42,11 +45,22 @@ public String getPathToElement(
4245
@Nullable final VirtualFile virtualFile,
4346
@Nullable final Editor editor
4447
) {
45-
final PsiDirectory directory
46-
= PsiManager.getInstance(project).findFile(virtualFile).getContainingDirectory();
48+
if (virtualFile == null) {
49+
return null;
50+
}
51+
final PsiFile file
52+
= PsiManager.getInstance(project).findFile(virtualFile);
53+
if (file == null) {
54+
return null;
55+
}
56+
final PsiDirectory directory = file.getContainingDirectory();
57+
final String moduleName = GetModuleNameByDirectoryUtil.execute(directory, project);
58+
if (moduleName == null) {
59+
return null;
60+
}
4761
final StringBuilder fullPath = new StringBuilder(virtualFile.getPath());
4862
final StringBuilder magentoPath
49-
= new StringBuilder(GetModuleNameByDirectoryUtil.execute(directory, project));
63+
= new StringBuilder(moduleName);
5064
String path = fullPath.toString();
5165

5266
if (PHTML.equals(virtualFile.getExtension())) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.psi.PsiDirectory;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewEmailTemplateDialog;
18+
19+
@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"})
20+
public class NewEmailTemplateAction extends AnAction {
21+
public static final String ACTION_NAME = "Magento 2 Email Template";
22+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 email template";
23+
24+
/**
25+
* New email template action constructor.
26+
*/
27+
public NewEmailTemplateAction() {
28+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
29+
}
30+
31+
@Override
32+
public void actionPerformed(final AnActionEvent event) {
33+
final DataContext dataContext = event.getDataContext();
34+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
35+
36+
if (view == null) {
37+
return;
38+
}
39+
40+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
41+
if (project == null) {
42+
return;
43+
}
44+
45+
final PsiDirectory directory = view.getOrChooseDirectory();
46+
if (directory == null) {
47+
return;
48+
}
49+
50+
NewEmailTemplateDialog.open(project, directory);
51+
}
52+
53+
@Override
54+
public boolean isDumbAware() {
55+
return false;
56+
}
57+
}

0 commit comments

Comments
 (0)