Skip to content

Commit 346c756

Browse files
author
Vitaliy
authored
Merge pull request #478 from bohdan-harniuk/develop-ui-component-form-generation
Develop UI component form generation
2 parents 95c7134 + cb17ceb commit 346c756

File tree

14 files changed

+682
-31
lines changed

14 files changed

+682
-31
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>

resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class ${CLASS_NAME} extends ${EXTENDS}
2929
*/
3030
private $searchResultFactory;
3131

32+
/**
33+
* @var array
34+
*/
35+
private $loadedData = [];
36+
3237
/**
3338
* @param string $name
3439
* @param string $primaryFieldName
@@ -85,6 +90,26 @@ class ${CLASS_NAME} extends ${EXTENDS}
8590
'#if(${ENTITY_ID})${ENTITY_ID}#{else}entity_id#end'
8691
);
8792
}
93+
94+
/**
95+
* Get data.
96+
*
97+
* @return array
98+
*/
99+
public function getData(): array
100+
{
101+
if ($this->loadedData) {
102+
return $this->loadedData;
103+
}
104+
$this->loadedData = parent::getData();
105+
106+
foreach ($this->loadedData['items'] as $item) {
107+
#set($idAccessor = '[' + "#if(${ENTITY_ID})'${ENTITY_ID}'#{else}'entity_id'#end" + ']')
108+
$this->loadedData['items'][$item$idAccessor] = $item;
109+
}
110+
111+
return $this->loadedData;
112+
}
88113
#else
89114
/**
90115
* @inheritDoc
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.form

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<border type="none"/>
2323
<children>
2424
<grid id="6be8b" binding="generalTable" layout-manager="GridLayoutManager" row-count="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
25-
<margin top="0" left="10" bottom="0" right="10"/>
25+
<margin top="10" left="10" bottom="0" right="10"/>
2626
<constraints>
2727
<tabbedpane title="General"/>
2828
</constraints>
@@ -138,7 +138,7 @@
138138
</children>
139139
</grid>
140140
<grid id="e3309" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
141-
<margin top="0" left="10" bottom="0" right="10"/>
141+
<margin top="10" left="10" bottom="0" right="10"/>
142142
<constraints>
143143
<tabbedpane title="Admin UI Components"/>
144144
</constraints>
@@ -323,7 +323,7 @@
323323
</children>
324324
</grid>
325325
<grid id="2a206" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
326-
<margin top="0" left="10" bottom="0" right="10"/>
326+
<margin top="10" left="10" bottom="0" right="10"/>
327327
<constraints>
328328
<tabbedpane title="ACL"/>
329329
</constraints>
@@ -413,7 +413,7 @@
413413
</children>
414414
</grid>
415415
<grid id="81b65" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
416-
<margin top="0" left="10" bottom="0" right="10"/>
416+
<margin top="10" left="10" bottom="0" right="10"/>
417417
<constraints>
418418
<tabbedpane title="Menu"/>
419419
</constraints>
@@ -516,7 +516,7 @@
516516
</children>
517517
</grid>
518518
<grid id="9e945" binding="propertiesPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
519-
<margin top="0" left="0" bottom="0" right="0"/>
519+
<margin top="10" left="0" bottom="0" right="0"/>
520520
<constraints>
521521
<tabbedpane title="Properties"/>
522522
</constraints>

0 commit comments

Comments
 (0)