Skip to content

Revert "Revert "Mainline EAV attribute generators"" #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Run automated tests

on:
pull_request:
branches: [ master, 4.3.0-develop ]
branches: [ master, '*-develop', 'mainline*' ]

jobs:
build-linux:
Expand Down Expand Up @@ -107,6 +107,7 @@ jobs:
run: ./gradlew checkstyleCI -i --no-daemon
env:
MODIFIED_FILES: ${{ steps.file_changes.outputs.files}}
ACTIONS_STEP_DEBUG: true
- name: Run PMD Quality Check
run: ./gradlew pmdCI -i --no-daemon
env:
Expand Down
9 changes: 9 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
<add-to-group group-id="NewGroup" anchor="last"/>
</group>

<!-- Eav Attribute generators -->
<group id="NewEavAttributeGroup" class="com.magento.idea.magento2plugin.actions.groups.NewEavAttributeGroup" text="Magento 2 EAV Attribute" popup="true">
<action id="NewProductEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.eavattribute.NewProductEavAttributeAction" />
<action id="NewCatalogEavAttribute" class="com.magento.idea.magento2plugin.actions.generation.eavattribute.NewCategoryEavAttributeAction" />
<action id="NewCustomerAttribute" class="com.magento.idea.magento2plugin.actions.generation.NewCustomerEavAttributeAction" />
<add-to-group group-id="MagentoNewModuleFileGroup" anchor="last"/>
</group>

<!-- Complex generators -->
<group id="MagentoNewGroup">
<action id="Magento2NewModule" class="com.magento.idea.magento2plugin.actions.generation.NewModuleAction"/>
Expand Down Expand Up @@ -200,6 +208,7 @@
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.DeclarativeSchemaElementsIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.UIComponentIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.xml.ProductTypeIndex" />

<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="PHP" implementationClass="com.magento.idea.magento2plugin.linemarker.php.PluginTargetLineMarkerProvider"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if(${INCLUDE_FIELDSET})
<fieldset name="${FIELDSET_NAME}">
#end
<field name="${FIELD_NAME}" sortOrder="${SORT_ORDER}" formElement="${FORM_ELEMENT}"/>
#if(${INCLUDE_FIELDSET})
</fieldset>
#end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php
#parse("PHP File Header.php")
#if (${NAMESPACE})
namespace ${NAMESPACE};
#end

#set ($uses = ${USES})
#foreach ($use in $uses.split(","))
use $use;
#end

class ${CLASS_NAME} implements ${IMPLEMENTS}
{
/**
* @var ${MODULE_DATA_SETUP_INTERFACE}
*/
private $moduleDataSetup;

/**
* @var ${EAV_SETUP_FACTORY}
*/
private $eavSetupFactory;

/**
* @var ${EAV_CONFIG_CLASS}
*/
private $eavConfig;

/**
* @var ${ATTRIBUTE_RESOURCE}
*/
private $attributeResource;

/**
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
* @param ${EAV_CONFIG_CLASS} $eavConfig
* @param ${ATTRIBUTE_RESOURCE} $attributeResource
*/
public function __construct(
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
${EAV_SETUP_FACTORY} $eavSetupFactory,
${EAV_CONFIG_CLASS} $eavConfig,
${ATTRIBUTE_RESOURCE} $attributeResource
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetupFactory = $eavSetupFactory;
$this->eavConfig = $eavConfig;
$this->attributeResource = $attributeResource;
}

/**
* Run code inside patch
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
* means run PatchInterface::revert()
*
* If we speak about data, under revert means: $transaction->rollback()
*
* @return $this
*/
public function apply()
{
/** @var ${EAV_SETUP} $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

$eavSetup->addAttribute(
${ENTITY_CLASS}::ENTITY,
'${ATTRIBUTE_CODE}',
[
#set ($attributeSet = ${ATTRIBUTE_SET})
#foreach ($attribute in $attributeSet.split("->"))
$attribute
#end
]
);

$eavSetup->addAttributeToSet(
${CUSTOMER_METADATA_INTERFACE}::ENTITY_TYPE_CUSTOMER,
${CUSTOMER_METADATA_INTERFACE}::ATTRIBUTE_SET_ID_CUSTOMER,
null,
'${ATTRIBUTE_CODE}'
);

#if (${CUSTOMER_FORMS})
$attribute = $this->eavConfig->getAttribute(${ENTITY_CLASS}::ENTITY, '${ATTRIBUTE_CODE}');
$attribute->setData(
'used_in_forms',
[${CUSTOMER_FORMS}]
);
$this->attributeResource->save($attribute);
#end

return $this;
}

/**
* Get array of patches that have to be executed prior to this.
*
* Example of implementation:
*
* [
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
* ]
*
* @return string[]
*/
public static function getDependencies()
{
return [];
}

/**
* Get aliases (previous names) for the patch.
*
* @return string[]
*/
public function getAliases()
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<html lang="en">
<body>
<font face="verdana" size="-1">
<p>
Data patch for the customer EAV attribute
</p>
</font>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
#parse("PHP File Header.php")
#if (${NAMESPACE})

namespace ${NAMESPACE};
#end

#set ($uses = ${USES})
#foreach ($use in $uses.split(","))
use $use;
#end

class ${CLASS_NAME} implements ${IMPLEMENTS} {

/**
* @var ${MODULE_DATA_SETUP_INTERFACE}
*/
private $moduleDataSetup;

/**
* @var ${EAV_SETUP_FACTORY}
*/
private $eavSetupFactory;

/**
* @param ${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup
* @param ${EAV_SETUP_FACTORY} $eavSetupFactory
*/
public function __construct(
${MODULE_DATA_SETUP_INTERFACE} $moduleDataSetup,
${EAV_SETUP_FACTORY} $eavSetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetupFactory = $eavSetupFactory;
}

/**
* Run code inside patch
* If code fails, patch must be reverted, in case when we are speaking about schema - then under revert
* means run PatchInterface::revert()
*
* If we speak about data, under revert means: $transaction->rollback()
*/
public function apply()
{
/** @var ${EAV_SETUP} $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

$eavSetup->addAttribute(
${ENTITY_CLASS}::ENTITY,
'${ATTRIBUTE_CODE}',
[
#set ($attributeSet = ${ATTRIBUTE_SET})
#foreach ($attribute in $attributeSet.split("->"))
$attribute
#end
]
);
}

/**
* Get array of patches that have to be executed prior to this.
*
* Example of implementation:
*
* [
* \Vendor_Name\Module_Name\Setup\Patch\Patch1::class,
* \Vendor_Name\Module_Name\Setup\Patch\Patch2::class
* ]
*
* @return string[]
*/
public static function getDependencies()
{
return [];
}

/**
* Get aliases (previous names) for the patch.
*
* @return string[]
*/
public function getAliases()
{
return [];
}
}
22 changes: 22 additions & 0 deletions resources/fileTemplates/internal/Magento Source Model Class.php.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
#parse("PHP File Header.php")

namespace ${NAMESPACE};

#set ($uses = ${USES})
#foreach ($use in $uses.split(","))
use $use;
#end

class ${NAME} extends ${EXTENDS}
{
/**
* Retrieve All options
*
* @return array
*/
public function getAllOptions(): array
{
return [];
}
}
1 change: 1 addition & 0 deletions resources/magento2/validation.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ validator.arrayValuesDialog.namesMustBeUnique=Duplicated items names
validator.arrayValuesDialog.nameMustNotBeEmpty=The array name cannot be empty
validator.layoutNameRuleInvalid=The layout name is invalid
validator.layoutNameUnderscoreQtyInvalid=Wrong layout name, please check
validator.commaSeparatedString.isNotValid=The {0} field must contain comma separated string without whitespaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation;

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCustomerEavAttributeDialog;
import com.magento.idea.magento2plugin.actions.generation.dialog.eavattribute.EavAttributeDialog;
import com.magento.idea.magento2plugin.actions.generation.eavattribute.NewEavAttributeAction;

public class NewCustomerEavAttributeAction extends NewEavAttributeAction {

public static final String ACTION_NAME = "Customer Attribute";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 EAV Customer Attribute";

public NewCustomerEavAttributeAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
}

@Override
protected EavAttributeDialog getDialogWindow(
final Project project,
final PsiDirectory directory
) {
return new NewCustomerEavAttributeDialog(project, directory, ACTION_NAME);
}
}
Loading