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

1205: Created a new action "Override email template in a project theme" #1233

Open
wants to merge 3 commits into
base: 5.1.0-develop
Choose a base branch
from
Open
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
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_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_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);
}
}
}