diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml
index ce3f6db59..70446e5c2 100644
--- a/resources/META-INF/plugin.xml
+++ b/resources/META-INF/plugin.xml
@@ -71,6 +71,7 @@
+ Specify actions that trigger cache invalidation for private content blocks in a sections.xml configuration file + in the Vendor/ModuleName/etc/frontend directory. Magento invalidates the cache on a POST or PUT request. +
++ Read more about sections.xml in the + DevDocs. +
+ + + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewSectionsXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewSectionsXmlAction.java new file mode 100644 index 000000000..7a9784202 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewSectionsXmlAction.java @@ -0,0 +1,58 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.context.xml; + +import com.intellij.ide.fileTemplates.actions.AttributesDefaults; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.context.AbstractContextAction; +import com.magento.idea.magento2plugin.magento.files.ModuleSectionsXmlFile; +import com.magento.idea.magento2plugin.magento.packages.Areas; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; +import org.jetbrains.annotations.NotNull; + +public class NewSectionsXmlAction extends AbstractContextAction { + + public static final String ACTION_NAME = "Magento 2 Sections File"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 sections.xml file"; + + /** + * New sections.xml file generation action constructor. + */ + public NewSectionsXmlAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleSectionsXmlFile()); + } + + @Override + protected boolean isVisible( + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final @NotNull PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + final PsiDirectory parentDir = targetDirectory.getParentDirectory(); + final PsiDirectory configDir = moduleData.getConfigDir(); + + if (parentDir == null || configDir == null) { + return false; + } + + return targetDirectory.getName().equals(Areas.frontend.toString()) + && parentDir.equals(configDir) + && moduleData.getType().equals(ComponentType.module); + } + + + @Override + protected AttributesDefaults getProperties( + final @NotNull AttributesDefaults defaults, + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + return defaults; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModuleSectionsXmlFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleSectionsXmlFile.java new file mode 100644 index 000000000..5a776a28a --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ModuleSectionsXmlFile.java @@ -0,0 +1,30 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.intellij.lang.Language; +import com.intellij.lang.xml.XMLLanguage; + +public final class ModuleSectionsXmlFile implements ModuleFileInterface { + + public static final String FILE_NAME = "sections.xml"; + public static final String TEMPLATE = "Magento Sections XML"; + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +}