-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1003 from doninAtwix/995-new-context-page-types-x…
…ml-file-action
- Loading branch information
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
resources/fileTemplates/internal/Magento Page Types XML.xml.ft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0"?> | ||
#parse("XML File Header.xml") | ||
<page_types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_types.xsd"> | ||
</page_types> |
22 changes: 22 additions & 0 deletions
22
resources/fileTemplates/internal/Magento Page Types XML.xml.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<html lang="en"> | ||
<body> | ||
<font face="verdana" size="-1"> | ||
<p> | ||
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 | ||
</p> | ||
<p> | ||
Read more about page_types.xml in the | ||
<a href="https://devdocs.magento.com/guides/v2.4/extension-dev-guide/routing.html#declaring-the-new-route-as-page-type">DevDocs</a>. | ||
</p> | ||
</font> | ||
</body> | ||
</html> |
58 changes: 58 additions & 0 deletions
58
src/com/magento/idea/magento2plugin/actions/context/xml/NewPageTypesXmlAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/com/magento/idea/magento2plugin/magento/files/ModulePageTypesXmlFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |