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

#issue-179 Added email template generation #350

Merged
merged 15 commits into from
Feb 15, 2021
Merged
1 change: 1 addition & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<action id="MagentoCreateAViewModel" class="com.magento.idea.magento2plugin.actions.generation.NewViewModelAction" />
<action id="MagentoCreateAGraphQlResolver" class="com.magento.idea.magento2plugin.actions.generation.NewGraphQlResolverAction" />
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
<action id="MagentoCreateEmailTemplate" class="com.magento.idea.magento2plugin.actions.generation.NewEmailTemplateAction" />
<action id="MagentoCreateUiComponentGrid" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentGridAction" />
<action id="MagentoCreateUiComponentForm" class="com.magento.idea.magento2plugin.actions.generation.NewUiComponentFormAction" />
<action id="NewModelsAction" class="com.magento.idea.magento2plugin.actions.generation.NewModelsAction" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template id="${ID}" label="${LABEL}" file="${FILE_NAME}.html" type="${TYPE}" module="${MODULE}" area="${AREA}"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!--
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<html>
<body>
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
<tr>
<td>
<font face="verdana" size="-1">Email templates configuration.</font>
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
<tr>
<td colspan="3"><font face="verdana" size="-1">Predefined variables explanation:</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${ID}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">Email template ID.</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${LABEL}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">Email Template Label.</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${FILE_NAME}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">Email template file name.</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${TYPE}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">Email template type. (HTML or TEXT)</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${MODULE}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">Module's name.</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${AREA}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">Email template area. (Adminhtml or Frontend)</font></td>
</tr>
</table>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!--@subject {{trans "${SUBJECT}"}} @-->
<!--@vars {} @-->

#if (${HTML_TYPE}){{template config_path="design/email/header_template"}}#end

<!-- @todo: implement ${TYPE} template -->
#if (${HTML_TYPE}){{template config_path="design/email/footer_template"}}#end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<html>
<body>
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
<tr>
<td>
<font face="verdana" size="-1">Email template.</font>
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
<tr>
<td colspan="3"><font face="verdana" size="-1">Predefined variables explanation:</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${SUBJECT}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">Email subject.</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${HTML_TYPE}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">Defines if it's HTML type template.</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${TYPE}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">Email template type. (HTML or TEXT)</font></td>
</tr>
</table>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<html>
<body>
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
<tr>
<td>
<font face="verdana" size="-1">Email templates configurations.</font>
</td>
</tr>
</table>
</body>
</html>
5 changes: 5 additions & 0 deletions resources/magento2/common.properties
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ common.addToolbarFullTextSearch=Add Toolbar Full Text Search
common.addToolbarColumnsControl=Add Toolbar Columns Control
common.addToolbarBookmarks=Add Toolbar Bookmarks
common.argument=Argument name
common.template.id=Template ID
common.template.label=Template Label
common.template.filename=Template File Name
common.template.subject=Email Subject
common.template.type=Email Type
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation;

import com.intellij.ide.IdeView;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewEmailTemplateDialog;

@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"})
public class NewEmailTemplateAction extends AnAction {
public static final String ACTION_NAME = "Magento 2 Email Template";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 email template";

/**
* New email template action constructor.
*/
public NewEmailTemplateAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
}

@Override
public void actionPerformed(final AnActionEvent event) {
final DataContext dataContext = event.getDataContext();
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);

if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();
if (directory == null) {
return;
}

NewEmailTemplateDialog.open(project, directory);
}

@Override
public boolean isDumbAware() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.data;

@SuppressWarnings({"PMD.DataClass"})
public class EmailTemplateHtmlData {
private final String module;
private final String fileName;
private final String area;
private final String subject;
private final String type;

/**
* Email template HTML data constructor.
*
* @param module String
* @param area String
* @param subject String
* @param type String
*/
public EmailTemplateHtmlData(
final String module,
final String fileName,
final String area,
final String subject,
final String type
) {
this.module = module;
this.fileName = fileName;
this.area = area;
this.subject = subject;
this.type = type;
}

/**
* Get module name.
*
* @return String
*/
public String getModule() {
return module;
}

/**
* Get file name.
*
* @return String
*/
public String getFileName() {
return fileName;
}

/**
* Get area.
*
* @return String
*/
public String getArea() {
return area;
}

/**
* Get subject.
*
* @return String
*/
public String getSubject() {
return subject;
}

/**
* Get type.
*
* @return String
*/
public String getType() {
return type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.data;

@SuppressWarnings({"PMD.DataClass"})
public class EmailTemplatesXmlData {
private final String module;
private final String emailTemplateId;
private final String label;
private final String templateFileName;
private final String type;
private final String area;

/**
* Email templates data constructor.
*
* @param module String
* @param emailTemplateId String
* @param label String
* @param templateFileName String
* @param type String
* @param area String
*/
public EmailTemplatesXmlData(
final String module,
final String emailTemplateId,
final String label,
final String templateFileName,
final String type,
final String area
) {
this.module = module;
this.emailTemplateId = emailTemplateId;
this.label = label;
this.templateFileName = templateFileName;
this.type = type;
this.area = area;
}

/**
* Get template file name.
*
* @return String
*/
public String getTemplateFileName() {
return templateFileName;
}

/**
* Get ID.
*
* @return String
*/
public String getId() {
return emailTemplateId;
}

/**
* Get label.
*
* @return String
*/
public String getLabel() {
return label;
}

/**
* Get module.
*
* @return String
*/
public String getModule() {
return module;
}

/**
* Get type.
*
* @return String
*/
public String getType() {
return type;
}

/**
* Get area.
*
* @return String
*/
public String getArea() {
return area;
}
}
Loading