Skip to content

Commit

Permalink
Merge pull request #1003 from doninAtwix/995-new-context-page-types-x…
Browse files Browse the repository at this point in the history
…ml-file-action
  • Loading branch information
bohdan-harniuk authored Feb 17, 2022
2 parents 3f1a674 + 010586c commit 33e69a0
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
2 changes: 2 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<action id="MagentoCreateSectionsFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewSectionsXmlAction"/>
<action id="MagentoCreateEmailTemplatesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewEmailTemplatesXmlAction"/>
<action id="MagentoCreateCrontabFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewCrontabXmlAction"/>
<action id="MagentoCreatePageTypesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewPageTypesXmlAction"/>
<!-- Context dependent actions -->
<separator/>
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
Expand Down Expand Up @@ -586,6 +587,7 @@
<internalFileTemplate name="Magento Fieldset XML"/>
<internalFileTemplate name="Magento Sections XML"/>
<internalFileTemplate name="Magento Module Email Templates Xml"/>
<internalFileTemplate name="Magento Page Types XML"/>

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

Expand Down
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 resources/fileTemplates/internal/Magento Page Types XML.xml.html
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>
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;
}
}
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;
}
}

0 comments on commit 33e69a0

Please sign in to comment.