diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index bacddef60..67fdabb3a 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -65,6 +65,7 @@ + @@ -569,6 +570,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Extension Attributes XML.xml.ft b/resources/fileTemplates/internal/Magento Extension Attributes XML.xml.ft new file mode 100644 index 000000000..c1e4b0752 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Extension Attributes XML.xml.ft @@ -0,0 +1,5 @@ + +#parse("XML File Header.xml") + + diff --git a/resources/fileTemplates/internal/Magento Extension Attributes XML.xml.html b/resources/fileTemplates/internal/Magento Extension Attributes XML.xml.html new file mode 100644 index 000000000..935d87b21 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Extension Attributes XML.xml.html @@ -0,0 +1,20 @@ + + + + +

+ Extension attributes are new in Magento 2. They are used to extend functionality and + often use more complex data types than custom attributes. These attributes do not appear in the Admin. +

+

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

+
+ + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewExtensionAttributesXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewExtensionAttributesXmlAction.java new file mode 100644 index 000000000..d9d91167d --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewExtensionAttributesXmlAction.java @@ -0,0 +1,57 @@ +/* + * 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.ModuleExtensionAttributesXmlFile; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; +import org.jetbrains.annotations.NotNull; + +public class NewExtensionAttributesXmlAction extends AbstractContextAction { + + public static final String ACTION_NAME = "Magento 2 Extension Attributes File"; + public static final String ACTION_DESCRIPTION = + "Create a new Magento 2 extension_attributes.xml file"; + + /** + * New extension_attributes.xml file generation action constructor. + */ + public NewExtensionAttributesXmlAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleExtensionAttributesXmlFile()); + } + + @Override + protected boolean isVisible( + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final @NotNull PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + final PsiDirectory configDir = moduleData.getConfigDir(); + + if (configDir == null) { + return false; + } + + return targetDirectory.getName().equals(Package.moduleBaseAreaDir) + && targetDirectory.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/ModuleExtensionAttributesXmlFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleExtensionAttributesXmlFile.java new file mode 100644 index 000000000..cf9a65e31 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ModuleExtensionAttributesXmlFile.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 ModuleExtensionAttributesXmlFile implements ModuleFileInterface { + + public static final String FILE_NAME = "extension_attributes.xml"; + public static final String TEMPLATE = "Magento Extension Attributes XML"; + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +}