diff --git a/CHANGELOG.md b/CHANGELOG.md index 29a841646..e42755970 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). ### Fixed - Throwable: Stub index points to a file without PSI [#1232](https://github.com/magento/magento2-phpstorm-plugin/pull/1232) +- Create an entity - delete button is displayed in a new entity form [#1268](https://github.com/magento/magento2-phpstorm-plugin/pull/1268) ## 5.0.0 diff --git a/resources/fileTemplates/internal/Magento Form Button Block Class.php.ft b/resources/fileTemplates/internal/Magento Form Button Block Class.php.ft index 89897c75a..ba2ec2113 100644 --- a/resources/fileTemplates/internal/Magento Form Button Block Class.php.ft +++ b/resources/fileTemplates/internal/Magento Form Button Block Class.php.ft @@ -20,6 +20,12 @@ class ${NAME} extends ${GENERIC_BUTTON} implements ${DATA_PROVIDER_TYPE} */ public function getButtonData(): array { +#if (${GET_ID}) + if (!$this->${GET_ID}) { + return []; + } + +#end return $this->wrapButtonSettings( '${LABEL}', '${CLASS}', diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonBlockGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonBlockGenerator.java index 164d0153f..ecec1c5c7 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonBlockGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/UiComponentFormButtonBlockGenerator.java @@ -208,6 +208,9 @@ protected void fillAttributes(final @NotNull Properties attributes) { attributes.setProperty("SORT_ORDER", String.valueOf(buttonTypeSettings.getSortOrder())); attributes.setProperty("ENTITY_NAME", Strings.toLowerCase(entityName)); attributes.setProperty("ENTITY_ID", entityIdField); + if (buttonData.getButtonType().equals(FormButtonBlockFile.TYPE_DELETE)) { + attributes.setProperty("GET_ID", entityIdAccessor); + } attributes.setProperty("USES", PhpClassGeneratorUtil.formatUses(uses)); } diff --git a/testData/actions/generation/generator/FormButtonBlockGenerator/generateDeleteButtonBlock/DeleteBlock.php b/testData/actions/generation/generator/FormButtonBlockGenerator/generateDeleteButtonBlock/DeleteBlock.php index 6c172f538..78adb4440 100644 --- a/testData/actions/generation/generator/FormButtonBlockGenerator/generateDeleteButtonBlock/DeleteBlock.php +++ b/testData/actions/generation/generator/FormButtonBlockGenerator/generateDeleteButtonBlock/DeleteBlock.php @@ -17,6 +17,10 @@ class DeleteBlock extends GenericButton implements ButtonProviderInterface */ public function getButtonData(): array { + if (!$this->getBookId()) { + return []; + } + return $this->wrapButtonSettings( 'Delete', 'delete',