Skip to content

Commit bf1d5d7

Browse files
Form generic button development
1 parent fb5efb0 commit bf1d5d7

File tree

9 files changed

+521
-0
lines changed

9 files changed

+521
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
<internalFileTemplate name="Magento Save Entity Command Model"/>
235235
<internalFileTemplate name="Magento Entity Index Adminhtml Controller Class"/>
236236
<internalFileTemplate name="Magento Grid Ui Component Action Column Class"/>
237+
<internalFileTemplate name="Magento PHP Form Generic Button Block Class"/>
237238

238239
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
239240

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
/**
12+
* Generic (form) button for ${ENTITY_NAME} entity.
13+
*/
14+
class ${CLASS_NAME}
15+
{
16+
/**
17+
* @var ${CONTEXT}
18+
*/
19+
private $context;
20+
21+
/**
22+
* @var ${URL}
23+
*/
24+
private $urlBuilder;
25+
26+
/**
27+
* @param ${CONTEXT} $context
28+
*/
29+
public function __construct(
30+
${CONTEXT} $context
31+
) {
32+
$this->context = $context;
33+
$this->urlBuilder = $context->getUrlBuilder();
34+
}
35+
36+
/**
37+
* Get ${ENTITY_NAME} entity id.
38+
*
39+
* @return int
40+
*/
41+
public function ${ENTITY_ID_GETTER}(): int
42+
{
43+
return (int) $this->context->getRequest()->getParam('${ENTITY_ID}');
44+
}
45+
46+
/**
47+
* Wrap button specific options to settings array.
48+
*
49+
* @param string $label
50+
* @param string $class
51+
* @param string $onclick
52+
* @param array $dataAttribute
53+
* @param int $sortOrder
54+
*
55+
* @return array
56+
*/
57+
protected function wrapButtonSettings(
58+
string $label,
59+
string $class,
60+
string $onclick = '',
61+
array $dataAttribute = [],
62+
int $sortOrder = 0
63+
): array {
64+
return [
65+
'label' => $label,
66+
'on_click' => $onclick,
67+
'data_attribute' => $dataAttribute,
68+
'class' => $class,
69+
'sort_order' => $sortOrder
70+
];
71+
}
72+
73+
/**
74+
* Get url.
75+
*
76+
* @param string $route
77+
* @param array $params
78+
*
79+
* @return string
80+
*/
81+
protected function getUrl(string $route, array $params = []): string
82+
{
83+
return $this->urlBuilder->getUrl($route, $params);
84+
}
85+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<html lang="en">
2+
<body>
3+
<p face="verdana" size="-1">
4+
5+
</p>
6+
7+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
8+
<tr>
9+
<td colspan="3"><font face="verdana" size="-1">Template's predefined variables:</font></td>
10+
</tr>
11+
<tr>
12+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAMESPACE}</b></font></nobr></td>
13+
<td width="10">&nbsp;</td>
14+
<td width="100%" valign="top"><font face="verdana" size="-1"></font></td>
15+
</tr>
16+
</table>
17+
</body>
18+
</html>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.data;
7+
8+
import org.jetbrains.annotations.NotNull;
9+
10+
public class FormGenericButtonBlockData {
11+
12+
private final String moduleName;
13+
private final String entityName;
14+
private final String entityId;
15+
private final String classFqn;
16+
private final String namespace;
17+
18+
/**
19+
* Generic button DTO constructor.
20+
*
21+
* @param moduleName String
22+
* @param entityName String
23+
* @param entityId String
24+
* @param classFqn String
25+
* @param namespace String
26+
*/
27+
public FormGenericButtonBlockData(
28+
final @NotNull String moduleName,
29+
final @NotNull String entityName,
30+
final @NotNull String entityId,
31+
final @NotNull String classFqn,
32+
final @NotNull String namespace
33+
) {
34+
this.moduleName = moduleName;
35+
this.entityName = entityName;
36+
this.entityId = entityId;
37+
this.classFqn = classFqn;
38+
this.namespace = namespace;
39+
}
40+
41+
/**
42+
* Get module name.
43+
*
44+
* @return String
45+
*/
46+
public String getModuleName() {
47+
return moduleName;
48+
}
49+
50+
/**
51+
* Get entity name.
52+
*
53+
* @return String
54+
*/
55+
public String getEntityName() {
56+
return entityName;
57+
}
58+
59+
/**
60+
* Get entity id.
61+
*
62+
* @return String
63+
*/
64+
public String getEntityId() {
65+
return entityId;
66+
}
67+
68+
/**
69+
* Get class FQN.
70+
*
71+
* @return String
72+
*/
73+
public String getClassFqn() {
74+
return classFqn;
75+
}
76+
77+
/**
78+
* Get namespace.
79+
*
80+
* @return String
81+
*/
82+
public String getNamespace() {
83+
return namespace;
84+
}
85+
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData;
2121
import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData;
2222
import com.magento.idea.magento2plugin.actions.generation.data.AdminListViewEntityActionData;
23+
import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData;
2324
import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData;
2425
import com.magento.idea.magento2plugin.actions.generation.data.GridActionColumnData;
2526
import com.magento.idea.magento2plugin.actions.generation.data.LayoutXmlData;
@@ -53,6 +54,7 @@
5354
import com.magento.idea.magento2plugin.actions.generation.generator.DbSchemaXmlGenerator;
5455
import com.magento.idea.magento2plugin.actions.generation.generator.EntityDataMapperGenerator;
5556
import com.magento.idea.magento2plugin.actions.generation.generator.AdminListViewEntityActionGenerator;
57+
import com.magento.idea.magento2plugin.actions.generation.generator.FormGenericButtonBlockGenerator;
5658
import com.magento.idea.magento2plugin.actions.generation.generator.GetListQueryModelGenerator;
5759
import com.magento.idea.magento2plugin.actions.generation.generator.GridActionColumnFileGenerator;
5860
import com.magento.idea.magento2plugin.actions.generation.generator.LayoutXmlGenerator;
@@ -74,6 +76,7 @@
7476
import com.magento.idea.magento2plugin.magento.files.DataModel;
7577
import com.magento.idea.magento2plugin.magento.files.DataModelInterface;
7678
import com.magento.idea.magento2plugin.magento.files.EntityDataMapperFile;
79+
import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile;
7780
import com.magento.idea.magento2plugin.magento.files.ModelPhp;
7881
import com.magento.idea.magento2plugin.magento.files.ModuleMenuXml;
7982
import com.magento.idea.magento2plugin.magento.files.ResourceModelPhp;
@@ -343,6 +346,7 @@ private void onOK() {
343346
generateFormLayoutFile();
344347
generateSaveEntityCommandFile();
345348
generateFormSaveControllerFile();
349+
generateFormUiComponentGenericButtonFile();
346350
generateUiComponentFormFile();
347351
}
348352

@@ -1194,6 +1198,27 @@ private String getSaveEntityCommandClassFqn() {
11941198
return namespaceBuilder.getClassFqn();
11951199
}
11961200

1201+
/**
1202+
* Generate Form UI Component generic button block file.
1203+
*/
1204+
private void generateFormUiComponentGenericButtonFile() {
1205+
final NamespaceBuilder genericButtonBlockNamespace = new NamespaceBuilder(
1206+
getModuleName(),
1207+
FormGenericButtonBlockFile.CLASS_NAME,
1208+
FormGenericButtonBlockFile.DIRECTORY
1209+
);
1210+
new FormGenericButtonBlockGenerator(
1211+
new FormGenericButtonBlockData(
1212+
getModuleName(),
1213+
getEntityName(),
1214+
getEntityIdColumn(),
1215+
genericButtonBlockNamespace.getClassFqn(),
1216+
genericButtonBlockNamespace.getNamespace()
1217+
),
1218+
project
1219+
).generate(ACTION_NAME, true);
1220+
}
1221+
11971222
/**
11981223
* Generate UI Component form file.
11991224
*/

0 commit comments

Comments
 (0)