Skip to content

Commit 68d01bf

Browse files
authored
Revert "Revert "Mainline EAV attribute generators""
1 parent 4b842f1 commit 68d01bf

File tree

85 files changed

+7598
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+7598
-5
lines changed

.github/workflows/gradle.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Run automated tests
55

66
on:
77
pull_request:
8-
branches: [ master, 4.3.0-develop ]
8+
branches: [ master, '*-develop', 'mainline*' ]
99

1010
jobs:
1111
build-linux:
@@ -107,6 +107,7 @@ jobs:
107107
run: ./gradlew checkstyleCI -i --no-daemon
108108
env:
109109
MODIFIED_FILES: ${{ steps.file_changes.outputs.files}}
110+
ACTIONS_STEP_DEBUG: true
110111
- name: Run PMD Quality Check
111112
run: ./gradlew pmdCI -i --no-daemon
112113
env:

resources/META-INF/plugin.xml

+9
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@
101101
<add-to-group group-id="NewGroup" anchor="last"/>
102102
</group>
103103

104+
<!-- Eav Attribute generators -->
105+
<group id="NewEavAttributeGroup" class="com.magento.idea.magento2plugin.actions.groups.NewEavAttributeGroup" text="Magento 2 EAV Attribute" popup="true">
106+
<action id="NewProductEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.eavattribute.NewProductEavAttributeAction" />
107+
<action id="NewCatalogEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.eavattribute.NewCategoryEavAttributeAction" />
108+
<action id="NewCustomerAttribute" class="com.magento.idea.magento2plugin.actions.generation.NewCustomerEavAttributeAction" />
109+
<add-to-group group-id="MagentoNewModuleFileGroup" anchor="last"/>
110+
</group>
111+
104112
<!-- Complex generators -->
105113
<group id="MagentoNewGroup">
106114
<action id="Magento2NewModule" class="com.magento.idea.magento2plugin.actions.generation.NewModuleAction"/>
@@ -200,6 +208,7 @@
200208
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex" />
201209
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex" />
202210
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.UIComponentIndex" />
211+
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.ProductTypeIndex" />
203212

204213
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginLineMarkerProvider"/>
205214
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginTargetLineMarkerProvider"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#if(${INCLUDE_FIELDSET})
2+
<fieldset name="${FIELDSET_NAME}">
3+
#end
4+
<field name="${FIELD_NAME}" sortOrder="${SORT_ORDER}" formElement="${FORM_ELEMENT}"/>
5+
#if(${INCLUDE_FIELDSET})
6+
</fieldset>
7+
#end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
4+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
#if (${NAMESPACE})
4+
namespace ${NAMESPACE};
5+
#end
6+
7+
#set ($uses = ${USES})
8+
#foreach ($use in $uses.split(","))
9+
use $use;
10+
#end
11+
12+
class ${CLASS_NAME} implements ${IMPLEMENTS}
13+
{
14+
/**
15+
* @var ${MODULE_DATA_SETUP_INTERFACE}
16+
*/
17+
private $moduleDataSetup;
18+
19+
/**
20+
* @var ${EAV_SETUP_FACTORY}
21+
*/
22+
private $eavSetupFactory;
23+
24+
/**
25+
* @var ${EAV_CONFIG_CLASS}
26+
*/
27+
private $eavConfig;
28+
29+
/**
30+
* @var ${ATTRIBUTE_RESOURCE}
31+
*/
32+
private $attributeResource;
33+
34+
/**
35+
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
36+
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
37+
* @param ${EAV_CONFIG_CLASS} $eavConfig
38+
* @param ${ATTRIBUTE_RESOURCE} $attributeResource
39+
*/
40+
public function __construct(
41+
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
42+
${EAV_SETUP_FACTORY} $eavSetupFactory,
43+
${EAV_CONFIG_CLASS} $eavConfig,
44+
${ATTRIBUTE_RESOURCE} $attributeResource
45+
) {
46+
$this->moduleDataSetup = $moduleDataSetup;
47+
$this->eavSetupFactory = $eavSetupFactory;
48+
$this->eavConfig = $eavConfig;
49+
$this->attributeResource = $attributeResource;
50+
}
51+
52+
/**
53+
* Run code inside patch
54+
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
55+
* means run PatchInterface::revert()
56+
*
57+
* If we speak about data, under revert means: $transaction->rollback()
58+
*
59+
* @return $this
60+
*/
61+
public function apply()
62+
{
63+
/** @var ${EAV_SETUP} $eavSetup */
64+
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
65+
66+
$eavSetup->addAttribute(
67+
${ENTITY_CLASS}::ENTITY,
68+
'${ATTRIBUTE_CODE}',
69+
[
70+
#set ($attributeSet = ${ATTRIBUTE_SET})
71+
#foreach ($attribute in $attributeSet.split("->"))
72+
$attribute
73+
#end
74+
]
75+
);
76+
77+
$eavSetup->addAttributeToSet(
78+
${CUSTOMER_METADATA_INTERFACE}::ENTITY_TYPE_CUSTOMER,
79+
${CUSTOMER_METADATA_INTERFACE}::ATTRIBUTE_SET_ID_CUSTOMER,
80+
null,
81+
'${ATTRIBUTE_CODE}'
82+
);
83+
84+
#if (${CUSTOMER_FORMS})
85+
$attribute = $this->eavConfig->getAttribute(${ENTITY_CLASS}::ENTITY, '${ATTRIBUTE_CODE}');
86+
$attribute->setData(
87+
'used_in_forms',
88+
[${CUSTOMER_FORMS}]
89+
);
90+
$this->attributeResource->save($attribute);
91+
#end
92+
93+
return $this;
94+
}
95+
96+
/**
97+
* Get array of patches that have to be executed prior to this.
98+
*
99+
* Example of implementation:
100+
*
101+
* [
102+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
103+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
104+
* ]
105+
*
106+
* @return string[]
107+
*/
108+
public static function getDependencies()
109+
{
110+
return [];
111+
}
112+
113+
/**
114+
* Get aliases (previous names) for the patch.
115+
*
116+
* @return string[]
117+
*/
118+
public function getAliases()
119+
{
120+
return [];
121+
}
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
Data patch for the customer EAV attribute
12+
</p>
13+
</font>
14+
</body>
15+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 ${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+
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
27+
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
28+
*/
29+
public function __construct(
30+
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
31+
${EAV_SETUP_FACTORY} $eavSetupFactory
32+
) {
33+
$this->moduleDataSetup = $moduleDataSetup;
34+
$this->eavSetupFactory = $eavSetupFactory;
35+
}
36+
37+
/**
38+
* Run code inside patch
39+
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
40+
* means run PatchInterface::revert()
41+
*
42+
* If we speak about data, under revert means: $transaction->rollback()
43+
*/
44+
public function apply()
45+
{
46+
/** @var ${EAV_SETUP} $eavSetup */
47+
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
48+
49+
$eavSetup->addAttribute(
50+
${ENTITY_CLASS}::ENTITY,
51+
'${ATTRIBUTE_CODE}',
52+
[
53+
#set ($attributeSet = ${ATTRIBUTE_SET})
54+
#foreach ($attribute in $attributeSet.split("->"))
55+
$attribute
56+
#end
57+
]
58+
);
59+
}
60+
61+
/**
62+
* Get array of patches that have to be executed prior to this.
63+
*
64+
* Example of implementation:
65+
*
66+
* [
67+
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
68+
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
69+
* ]
70+
*
71+
* @return string[]
72+
*/
73+
public static function getDependencies()
74+
{
75+
return [];
76+
}
77+
78+
/**
79+
* Get aliases (previous names) for the patch.
80+
*
81+
* @return string[]
82+
*/
83+
public function getAliases()
84+
{
85+
return [];
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
namespace ${NAMESPACE};
5+
6+
#set ($uses = ${USES})
7+
#foreach ($use in $uses.split(","))
8+
use $use;
9+
#end
10+
11+
class ${NAME} extends ${EXTENDS}
12+
{
13+
/**
14+
* Retrieve All options
15+
*
16+
* @return array
17+
*/
18+
public function getAllOptions(): array
19+
{
20+
return [];
21+
}
22+
}

resources/magento2/validation.properties

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ validator.arrayValuesDialog.namesMustBeUnique=Duplicated items names
4747
validator.arrayValuesDialog.nameMustNotBeEmpty=The array name cannot be empty
4848
validator.layoutNameRuleInvalid=The layout name is invalid
4949
validator.layoutNameUnderscoreQtyInvalid=Wrong layout name, please check
50+
validator.commaSeparatedString.isNotValid=The {0} field must contain comma separated string without whitespaces
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.openapi.project.Project;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.magento.idea.magento2plugin.MagentoIcons;
11+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCustomerEavAttributeDialog;
12+
import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog;
13+
import com.magento.idea.magento2plugin.actions.generation.eavattribute.NewEavAttributeAction;
14+
15+
public class NewCustomerEavAttributeAction extends NewEavAttributeAction {
16+
17+
public static final String ACTION_NAME = "Customer Attribute";
18+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Customer Attribute";
19+
20+
public NewCustomerEavAttributeAction() {
21+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
22+
}
23+
24+
@Override
25+
protected EavAttributeDialog getDialogWindow(
26+
final Project project,
27+
final PsiDirectory directory
28+
) {
29+
return new NewCustomerEavAttributeDialog(project, directory, ACTION_NAME);
30+
}
31+
}

0 commit comments

Comments
 (0)