Skip to content

Commit b486190

Browse files
author
Vitaliy Boyko
committed
89: added tests
1 parent 0536b83 commit b486190

File tree

18 files changed

+559
-14
lines changed

18 files changed

+559
-14
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
2-
<body>
3-
</body>
42
</page>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public void actionPerformed(final ActionEvent event) {
164164

165165
formAreaSelect.addActionListener(e -> toggleAcl());
166166
acl.setText(getModuleName() + "::manage");
167+
formAreaSelect.setEnabled(false);
167168
}
168169

169170
protected void initButtonsTable() {

src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonPhpClassGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public PsiFile generate(final String actionName) {
5555
final PhpClass buttonClass = createButton(actionName);
5656
new ButtonMethodGenerator(buttonData, project).generate(buttonClassFile, buttonClass);
5757

58-
return buttonClassFile[0];
58+
return buttonClass.getContainingFile();
5959
}
6060

6161
/**

src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormGenerator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public PsiFile generate(final String actionName) {
5757

5858
createButtonClasses(actionName);
5959

60-
61-
6260
return formFile;
6361
}
6462

src/com/magento/idea/magento2plugin/actions/generation/generator/code/ButtonMethodGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public ButtonMethodGenerator(
6262
* @param buttonClass PhpClass
6363
*/
6464
public void generate(PsiFile[] buttonClassFile, final PhpClass buttonClass) {
65+
final String template = getMethodTemplateByButtonType(buttonData.getButtonType());
66+
if (template.equals("")) {
67+
return;
68+
}
6569
WriteCommandAction.runWriteCommandAction(project, () -> {
6670
if (buttonClass == null) {
6771
final String errorTitle = commonBundle.message("common.error");
@@ -79,10 +83,6 @@ public void generate(PsiFile[] buttonClassFile, final PhpClass buttonClass) {
7983
return;
8084
}
8185

82-
final String template = getMethodTemplateByButtonType(buttonData.getButtonType());
83-
if (template == null) {
84-
return;
85-
}
8686
final StringBuffer textBuf = new StringBuffer();
8787
try {
8888
textBuf.append(getCodeTemplate.execute(

src/com/magento/idea/magento2plugin/actions/generation/generator/util/FindOrCreateLayoutXml.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,22 @@ public PsiFile execute(
5858
.findOrCreateSubdirectory(parentDirectory, fileDirectory);
5959
}
6060
final LayoutXml layoutXml = new LayoutXml(routeId, controllerName, controllerActionName);
61-
PsiFile routesXml = FileBasedIndexUtil.findModuleViewFile(
61+
PsiFile layoutXmlFile = FileBasedIndexUtil.findModuleViewFile(
6262
layoutXml.getFileName(),
6363
getArea(area),
6464
moduleName,
6565
project,
6666
LayoutXml.PARENT_DIR
6767
);
68-
if (routesXml == null) {
69-
routesXml = fileFromTemplateGenerator.generate(
68+
if (layoutXmlFile == null) {
69+
layoutXmlFile = fileFromTemplateGenerator.generate(
7070
layoutXml,
7171
new Properties(),
7272
parentDirectory,
7373
actionName
7474
);
7575
}
76-
return routesXml;
76+
return layoutXmlFile;
7777
}
7878

7979
private Areas getArea(final String area) {

src/com/magento/idea/magento2plugin/magento/files/LayoutXml.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class LayoutXml implements ModuleFileInterface {
1616
public static String CACHEABLE_ATTRIBUTE_VALUE_FALSE = "false";
1717
public static String BLOCK_ATTRIBUTE_TAG_NAME = "block";
1818
public static String REFERENCE_BLOCK_ATTRIBUTE_TAG_NAME = "referenceBlock";
19-
public static String ROOT_TAG_NAME = "referenceBlock";
19+
public static String ROOT_TAG_NAME = "body";
2020
public static String REFERENCE_CONTAINER_TAG_NAME = "referenceContainer";
2121
public static String UI_COMPONENT_TAG_NAME = "uiComponent";
2222
public static String XML_ATTRIBUTE_TEMPLATE = "template";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
4+
namespace Foo\Bar\Block\Form;
5+
6+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
7+
8+
/**
9+
* @inheritdoc
10+
*/
11+
class MyBackButton implements ButtonProviderInterface
12+
{
13+
/**
14+
* @inheritDoc
15+
*/
16+
public function getButtonData()
17+
{
18+
return ['label' => __('Back Button'), 'on_click' => sprintf("location.href = '%s';", $this->getUrl('*/*/')), 'class' => 'back', 'sort_order' => 20];
19+
}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
4+
namespace Foo\Bar\Block\Form;
5+
6+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
7+
8+
/**
9+
* @inheritdoc
10+
*/
11+
class MyCustom implements ButtonProviderInterface
12+
{
13+
/**
14+
* @inheritDoc
15+
*/
16+
public function getButtonData()
17+
{
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
4+
namespace Foo\Bar\Block\Form;
5+
6+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
7+
8+
/**
9+
* @inheritdoc
10+
*/
11+
class DeleteBlock implements ButtonProviderInterface
12+
{
13+
/**
14+
* @inheritDoc
15+
*/
16+
public function getButtonData()
17+
{
18+
return ['label' => __('Delete Entity'), 'class' => 'delete', 'on_click' => 'deleteConfirm(\'' . __('Are you sure you want to do this?') . '\', \'' . //TODO: adjust entity ID
19+
$this->getUrl('*/*/${BUTTON_ROUTE}', ['entity_id' => '']) . '\', {"data": {}})', 'sort_order' => 30];
20+
}
21+
}

0 commit comments

Comments
 (0)