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 .ModuleEventsXml ;
13
+ import com .magento .idea .magento2plugin .magento .packages .Areas ;
14
+ import com .magento .idea .magento2plugin .magento .packages .ComponentType ;
15
+ import com .magento .idea .magento2plugin .magento .packages .Package ;
16
+ import com .magento .idea .magento2plugin .util .magento .GetMagentoModuleUtil ;
17
+ import java .util .Arrays ;
18
+ import java .util .List ;
19
+ import org .jetbrains .annotations .NotNull ;
20
+
21
+ public class NewEventsXmlAction extends AbstractContextAction {
22
+
23
+ public static final String ACTION_NAME = "Magento 2 Events Observer File" ;
24
+ public static final String ACTION_DESCRIPTION = "Create a new Magento 2 events.xml file" ;
25
+
26
+ /**
27
+ * New events.xml file generation action constructor.
28
+ */
29
+ public NewEventsXmlAction () {
30
+ super (ACTION_NAME , ACTION_DESCRIPTION , new ModuleEventsXml ());
31
+ }
32
+
33
+ @ Override
34
+ protected boolean isVisible (
35
+ final @ NotNull GetMagentoModuleUtil .MagentoModuleData moduleData ,
36
+ final PsiDirectory targetDirectory ,
37
+ final PsiFile targetFile
38
+ ) {
39
+ final PsiDirectory configDir = moduleData .getConfigDir ();
40
+ final PsiDirectory globalScopeDir = getGlobalScopeDir (targetDirectory );
41
+
42
+ if (configDir == null || globalScopeDir == null ) {
43
+ return false ;
44
+ }
45
+
46
+ final List <String > allowedDirectories = Arrays .asList (
47
+ Package .moduleBaseAreaDir ,
48
+ Areas .adminhtml .toString (),
49
+ Areas .crontab .toString (),
50
+ Areas .frontend .toString (),
51
+ Areas .graphql .toString (),
52
+ Areas .webapi_rest .toString (),
53
+ Areas .webapi_soap .toString ()
54
+ );
55
+
56
+ return allowedDirectories .contains (targetDirectory .getName ())
57
+ && globalScopeDir .equals (configDir )
58
+ && moduleData .getType ().equals (ComponentType .module );
59
+ }
60
+
61
+ @ Override
62
+ protected AttributesDefaults getProperties (
63
+ final @ NotNull AttributesDefaults defaults ,
64
+ final @ NotNull GetMagentoModuleUtil .MagentoModuleData moduleData ,
65
+ final PsiDirectory targetDirectory ,
66
+ final PsiFile targetFile
67
+ ) {
68
+ return defaults ;
69
+ }
70
+ }
0 commit comments