diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index e041502a3..03732dc1f 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -74,6 +74,7 @@ + @@ -586,6 +587,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Page Types XML.xml.ft b/resources/fileTemplates/internal/Magento Page Types XML.xml.ft new file mode 100644 index 000000000..fc9072ccd --- /dev/null +++ b/resources/fileTemplates/internal/Magento Page Types XML.xml.ft @@ -0,0 +1,5 @@ + +#parse("XML File Header.xml") + + diff --git a/resources/fileTemplates/internal/Magento Page Types XML.xml.html b/resources/fileTemplates/internal/Magento Page Types XML.xml.html new file mode 100644 index 000000000..dab7d2d46 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Page Types XML.xml.html @@ -0,0 +1,22 @@ + + + + +

+ After creating a new route routing/index/index, it is a good practice to give more control + on it for the admin. By creating a new Page Type, the admin can manage the content of this + page using widgets. + Defining a new page type: etc/frontend/page_types.xml +

+

+ Read more about page_types.xml in the + DevDocs. +

+
+ + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewPageTypesXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewPageTypesXmlAction.java new file mode 100644 index 000000000..e23b67530 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewPageTypesXmlAction.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.ModulePageTypesXmlFile; +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 NewPageTypesXmlAction extends AbstractContextAction { + + public static final String ACTION_NAME = "Magento 2 Page Types File"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 page_types.xml file"; + + /** + * New page_types.xml file generation action constructor. + */ + public NewPageTypesXmlAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, new ModulePageTypesXmlFile()); + } + + @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/ModulePageTypesXmlFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModulePageTypesXmlFile.java new file mode 100644 index 000000000..4ac05c4a1 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ModulePageTypesXmlFile.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 ModulePageTypesXmlFile implements ModuleFileInterface { + + public static final String FILE_NAME = "page_types.xml"; + public static final String TEMPLATE = "Magento Page Types XML"; + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +}