Skip to content

Commit 26118be

Browse files
committed
992: Added sections.xml file in context generation.
1 parent ae84e39 commit 26118be

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<action id="MagentoCreateIndexerFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewIndexerXmlAction"/>
7272
<action id="MagentoCreateViewFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewViewXmlAction"/>
7373
<action id="MagentoCreateFieldsetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewFieldsetXmlAction"/>
74+
<action id="MagentoCreateSectionsFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewSectionsXmlAction"/>
7475
<!-- Context dependent actions -->
7576
<separator/>
7677
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
@@ -581,6 +582,7 @@
581582
<internalFileTemplate name="Magento Indexer XML"/>
582583
<internalFileTemplate name="Magento View XML"/>
583584
<internalFileTemplate name="Magento Fieldset XML"/>
585+
<internalFileTemplate name="Magento Sections XML"/>
584586

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
#parse("XML File Header.xml")
3+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
5+
</config>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
Specify actions that trigger cache invalidation for private content blocks in a sections.xml configuration file
12+
in the Vendor/ModuleName/etc/frontend directory. Magento invalidates the cache on a POST or PUT request.
13+
</p>
14+
<p>
15+
Read more about sections.xml in the
16+
<a href="https://devdocs.magento.com/guides/v2.4/extension-dev-guide/cache/page-caching/private-content.html">DevDocs</a>.
17+
</p>
18+
</font>
19+
</body>
20+
</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.ModuleSectionsXmlFile;
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 NewSectionsXmlAction extends AbstractContextAction {
19+
20+
public static final String ACTION_NAME = "Magento 2 Sections File";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 sections.xml file";
22+
23+
/**
24+
* New sections.xml file generation action constructor.
25+
*/
26+
public NewSectionsXmlAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleSectionsXmlFile());
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 ModuleSectionsXmlFile implements ModuleFileInterface {
12+
13+
public static final String FILE_NAME = "sections.xml";
14+
public static final String TEMPLATE = "Magento Sections 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)