Skip to content

Commit 33e69a0

Browse files
Merge pull request #1003 from doninAtwix/995-new-context-page-types-xml-file-action
2 parents 3f1a674 + 010586c commit 33e69a0

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<action id="MagentoCreateSectionsFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewSectionsXmlAction"/>
7575
<action id="MagentoCreateEmailTemplatesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewEmailTemplatesXmlAction"/>
7676
<action id="MagentoCreateCrontabFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewCrontabXmlAction"/>
77+
<action id="MagentoCreatePageTypesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewPageTypesXmlAction"/>
7778
<!-- Context dependent actions -->
7879
<separator/>
7980
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
@@ -586,6 +587,7 @@
586587
<internalFileTemplate name="Magento Fieldset XML"/>
587588
<internalFileTemplate name="Magento Sections XML"/>
588589
<internalFileTemplate name="Magento Module Email Templates Xml"/>
590+
<internalFileTemplate name="Magento Page Types XML"/>
589591

590592
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
591593

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0"?>
2+
#parse("XML File Header.xml")
3+
<page_types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_types.xsd">
5+
</page_types>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html lang="en">
8+
<body>
9+
<font face="verdana" size="-1">
10+
<p>
11+
After creating a new route routing/index/index, it is a good practice to give more control
12+
on it for the admin. By creating a new Page Type, the admin can manage the content of this
13+
page using widgets.
14+
Defining a new page type: etc/frontend/page_types.xml
15+
</p>
16+
<p>
17+
Read more about page_types.xml in the
18+
<a href="https://devdocs.magento.com/guides/v2.4/extension-dev-guide/routing.html#declaring-the-new-route-as-page-type">DevDocs</a>.
19+
</p>
20+
</font>
21+
</body>
22+
</html>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.context.xml;
7+
8+
import com.intellij.ide.fileTemplates.actions.AttributesDefaults;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.actions.context.AbstractContextAction;
12+
import com.magento.idea.magento2plugin.magento.files.ModulePageTypesXmlFile;
13+
import com.magento.idea.magento2plugin.magento.packages.Areas;
14+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
15+
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
16+
import org.jetbrains.annotations.NotNull;
17+
18+
public class NewPageTypesXmlAction extends AbstractContextAction {
19+
20+
public static final String ACTION_NAME = "Magento 2 Page Types File";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 page_types.xml file";
22+
23+
/**
24+
* New page_types.xml file generation action constructor.
25+
*/
26+
public NewPageTypesXmlAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, new ModulePageTypesXmlFile());
28+
}
29+
30+
@Override
31+
protected boolean isVisible(
32+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
33+
final @NotNull PsiDirectory targetDirectory,
34+
final PsiFile targetFile
35+
) {
36+
final PsiDirectory parentDir = targetDirectory.getParentDirectory();
37+
final PsiDirectory configDir = moduleData.getConfigDir();
38+
39+
if (parentDir == null || configDir == null) {
40+
return false;
41+
}
42+
43+
return targetDirectory.getName().equals(Areas.frontend.toString())
44+
&& parentDir.equals(configDir)
45+
&& moduleData.getType().equals(ComponentType.module);
46+
}
47+
48+
49+
@Override
50+
protected AttributesDefaults getProperties(
51+
final @NotNull AttributesDefaults defaults,
52+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
53+
final PsiDirectory targetDirectory,
54+
final PsiFile targetFile
55+
) {
56+
return defaults;
57+
}
58+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.magento.files;
7+
8+
import com.intellij.lang.Language;
9+
import com.intellij.lang.xml.XMLLanguage;
10+
11+
public final class ModulePageTypesXmlFile implements ModuleFileInterface {
12+
13+
public static final String FILE_NAME = "page_types.xml";
14+
public static final String TEMPLATE = "Magento Page Types XML";
15+
16+
@Override
17+
public String getFileName() {
18+
return FILE_NAME;
19+
}
20+
21+
@Override
22+
public String getTemplate() {
23+
return TEMPLATE;
24+
}
25+
26+
@Override
27+
public Language getLanguage() {
28+
return XMLLanguage.INSTANCE;
29+
}
30+
}

0 commit comments

Comments
 (0)