Skip to content

Commit

Permalink
1205: Created a new action "Override email template in a project theme"
Browse files Browse the repository at this point in the history
  • Loading branch information
anzin committed Oct 21, 2022
1 parent c8f351a commit 450b516
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<action id="OverrideTemplateInTheme.Menu" class="com.magento.idea.magento2plugin.actions.generation.OverrideTemplateInThemeAction">
<add-to-group group-id="ProjectViewPopupMenu"/>
</action>
<action id="OverrideEmailTemplateInTheme.Menu" class="com.magento.idea.magento2plugin.actions.generation.OverrideEmailTemplateInThemeAction">
<add-to-group group-id="ProjectViewPopupMenu"/>
</action>
<action id="OverrideLayoutInTheme.Menu" class="com.magento.idea.magento2plugin.actions.generation.OverrideLayoutInThemeAction">
<add-to-group group-id="ProjectViewPopupMenu"/>
</action>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

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

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideTemplateInThemeDialog;
import com.magento.idea.magento2plugin.magento.packages.Areas;
import org.jetbrains.annotations.NotNull;

public class OverrideEmailTemplateInThemeAction extends OverrideFileInThemeAction {

public static final String ACTION_NAME = "Override email template in a project theme";
public static final String ACTION_TEMPLATE_DESCRIPTION = "Override email template file in project theme";
public static final String EMAIL_DIRECTORY = "email";
public static final String HTML = "html";

public OverrideEmailTemplateInThemeAction() {
super(ACTION_NAME, ACTION_TEMPLATE_DESCRIPTION, MagentoIcons.MODULE);
}

@Override
public void actionPerformed(final @NotNull AnActionEvent event) {
final Project project = event.getProject();

if (project == null || psiFile == null) {
return;
}
OverrideTemplateInThemeDialog.open(project, psiFile);
}

@Override
protected boolean isOverrideAllowed(
final @NotNull PsiFile file,
final @NotNull Project project
) {
final VirtualFile virtualFile = file.getVirtualFile();

if (virtualFile == null) {
return false;
}
final String fileExtension = virtualFile.getExtension();

if (fileExtension == null) {
return false;
}

if(!HTML.equals(fileExtension)) {
return false;
}

return isEmailTemplateFile(virtualFile);
}

private boolean isEmailTemplateFile(final @NotNull VirtualFile virtualFile) {
final VirtualFile directory = virtualFile.getParent();

if (directory == null) {
return false;
}

if (EMAIL_DIRECTORY.equals(directory.getName())) {
return Areas.getAreaByString(directory.getParent().getName()) != null;
} else {
return isEmailTemplateFile(directory);
}
}
}

0 comments on commit 450b516

Please sign in to comment.