From 26118be2c19f5ea2411c17248aa67ca23f6ec7c7 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Wed, 16 Feb 2022 16:24:45 +0200 Subject: [PATCH] 992: Added sections.xml file in context generation. --- resources/META-INF/plugin.xml | 2 + .../internal/Magento Sections XML.xml.ft | 5 ++ .../internal/Magento Sections XML.xml.html | 20 +++++++ .../context/xml/NewSectionsXmlAction.java | 58 +++++++++++++++++++ .../magento/files/ModuleSectionsXmlFile.java | 30 ++++++++++ 5 files changed, 115 insertions(+) create mode 100644 resources/fileTemplates/internal/Magento Sections XML.xml.ft create mode 100644 resources/fileTemplates/internal/Magento Sections XML.xml.html create mode 100644 src/com/magento/idea/magento2plugin/actions/context/xml/NewSectionsXmlAction.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/ModuleSectionsXmlFile.java 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 @@ + @@ -581,6 +582,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Sections XML.xml.ft b/resources/fileTemplates/internal/Magento Sections XML.xml.ft new file mode 100644 index 000000000..4e3a720c5 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Sections XML.xml.ft @@ -0,0 +1,5 @@ + +#parse("XML File Header.xml") + + diff --git a/resources/fileTemplates/internal/Magento Sections XML.xml.html b/resources/fileTemplates/internal/Magento Sections XML.xml.html new file mode 100644 index 000000000..d48f2a608 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Sections XML.xml.html @@ -0,0 +1,20 @@ + + + + +

+ 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; + } +}