Skip to content

Commit e60400f

Browse files
author
Vitaliy
authored
Merge pull request #527 from ProkopovVitaliy/525-зroduct-attribute-setup-patch-generator
Created Product attribute setup patch generator
2 parents 27fb74b + c1df489 commit e60400f

File tree

21 files changed

+1688
-0
lines changed

21 files changed

+1688
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<action id="MagentoCreateADataModel" class="com.magento.idea.magento2plugin.actions.generation.NewDataModelAction" />
7474
<action id="MagentoMessageQueue" class="com.magento.idea.magento2plugin.actions.generation.NewMessageQueueAction" />
7575
<action id="NewDbSchema" class="com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction" />
76+
<action id="NewEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.NewEavAttributeAction" />
7677
<add-to-group group-id="NewGroup" anchor="last"/>
7778
</group>
7879

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
#if (${NAMESPACE})
4+
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
#set ($uses = ${USES})
9+
#foreach ($use in $uses.split(","))
10+
use $use;
11+
#end
12+
13+
class ${NAME} implements ${IMPLEMENTS} {
14+
15+
/**
16+
* @var ${MODULE_DATA_SETUP_INTERFACE}
17+
*/
18+
private $moduleDataSetup;
19+
20+
/**
21+
* @var ${EAV_SETUP_FACTORY}
22+
*/
23+
private $eavSetupFactory;
24+
25+
/**
26+
* AddRecommendedAttribute constructor.
27+
*
28+
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
29+
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
30+
*/
31+
public function __construct(
32+
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
33+
${EAV_SETUP_FACTORY} $eavSetupFactory
34+
) {
35+
$this->moduleDataSetup = $moduleDataSetup;
36+
$this->eavSetupFactory = $eavSetupFactory;
37+
}
38+
39+
/**
40+
* Get array of patches that have to be executed prior to this.
41+
*
42+
* Example of implementation:
43+
*
44+
* [
45+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
46+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
47+
* ]
48+
*
49+
* @return string[]
50+
*/
51+
public static function getDependencies()
52+
{
53+
return [];
54+
}
55+
56+
/**
57+
* Get aliases (previous names) for the patch.
58+
*
59+
* @return string[]
60+
*/
61+
public function getAliases()
62+
{
63+
return [];
64+
}
65+
66+
/**
67+
* Run code inside patch
68+
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
69+
* means run PatchInterface::revert()
70+
*
71+
* If we speak about data, under revert means: $transaction->rollback()
72+
*
73+
* @return $this
74+
*/
75+
public function apply()
76+
{
77+
/** @var ${EAV_SETUP} $eavSetup */
78+
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
79+
80+
$eavSetup->addAttribute(
81+
${ENTITY_CLASS}::ENTITY,
82+
'${ATTRIBUTE_CODE}',
83+
[
84+
#set ($attributeSet = ${ATTRIBUTE_SET})
85+
#foreach ($attribute in $attributeSet.split(","))
86+
$attribute,
87+
#end
88+
]
89+
);
90+
}
91+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.psi.PsiDirectory;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewEavAttributeDialog;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
public class NewEavAttributeAction extends AnAction {
21+
public static final String ACTION_NAME = "Magento 2 EAV Attribute";
22+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Attribute";
23+
24+
public NewEavAttributeAction() {
25+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
26+
}
27+
28+
@Override
29+
public void actionPerformed(final @NotNull AnActionEvent event) {
30+
final DataContext dataContext = event.getDataContext();
31+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
32+
if (view == null) {
33+
return;
34+
}
35+
36+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
37+
if (project == null) {
38+
return;
39+
}
40+
41+
final PsiDirectory directory = view.getOrChooseDirectory();
42+
if (directory == null) {
43+
return;
44+
}
45+
46+
NewEavAttributeDialog.open(project, directory);
47+
}
48+
49+
@Override
50+
public boolean isDumbAware() {
51+
return false;
52+
}
53+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.magento.idea.magento2plugin.actions.generation.data;
2+
3+
@SuppressWarnings({"PMD.UnnecessaryModifier"})
4+
public interface EavEntityDataInterface {
5+
public String getCode();
6+
7+
public String getType();
8+
9+
public String getLabel();
10+
11+
public String getInput();
12+
13+
public String getNamespace();
14+
15+
public String getModuleName();
16+
17+
public String getDirectory();
18+
19+
public String getDataPatchName();
20+
21+
public String getEntityClass();
22+
}

0 commit comments

Comments
 (0)