-
Notifications
You must be signed in to change notification settings - Fork 102
added generator for save controller #465
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
Merged
VitaliyBoyko
merged 1 commit into
magento:mainline-entity-manager
from
anzin:create-save-controller-generation
Feb 3, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
resources/fileTemplates/internal/Magento Entity Save Controller Class.php.ft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
#parse("PHP File Header.php") | ||
|
||
namespace ${NAMESPACE}; | ||
|
||
#set($uses = ${USES}) | ||
#foreach ($use in $uses.split(",")) | ||
use $use; | ||
#end | ||
|
||
/** | ||
* Save ${ENTITY_NAME} controller action. | ||
*/ | ||
class ${CLASS_NAME} extends ${EXTENDS} implements ${IMPLEMENTS} | ||
{ | ||
/** | ||
* Authorization level of a basic admin session | ||
* | ||
* @see _isAllowed() | ||
*/ | ||
const ADMIN_RESOURCE = '${ADMIN_RESOURCE}'; | ||
|
||
/** | ||
* @var ${DATA_PERSISTOR} | ||
*/ | ||
private $dataPersistor; | ||
|
||
/** | ||
* @var ${SAVE_COMMAND} | ||
*/ | ||
private $saveCommand; | ||
|
||
/** | ||
* @var ${ENTITY_DTO_FACTORY} | ||
*/ | ||
private $entityDataFactory; | ||
|
||
/** | ||
* @param Context $context | ||
* @param ${DATA_PERSISTOR} $dataPersistor | ||
* @param ${SAVE_COMMAND} $saveCommand | ||
* @param ${ENTITY_DTO_FACTORY} $entityDataFactory | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
${DATA_PERSISTOR} $dataPersistor, | ||
${SAVE_COMMAND} $saveCommand, | ||
${ENTITY_DTO_FACTORY} $entityDataFactory | ||
) { | ||
parent::__construct($context); | ||
$this->dataPersistor = $dataPersistor; | ||
$this->saveCommand = $saveCommand; | ||
$this->entityDataFactory = $entityDataFactory; | ||
} | ||
|
||
/** | ||
* Save ${ENTITY_NAME} Action. | ||
* | ||
* @return ResponseInterface|ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
$resultRedirect = $this->resultRedirectFactory->create(); | ||
$params = $this->getRequest()->getParams(); | ||
|
||
try { | ||
/** @var ${ENTITY_DTO}|${DATA_OBJECT} $entityModel */ | ||
$entityModel = $this->entityDataFactory->create(); | ||
$entityModel->addData($params); | ||
$this->saveCommand->execute($entityModel); | ||
$this->messageManager->addSuccessMessage( | ||
__('The ${ENTITY_NAME} data was saved successfully') | ||
); | ||
$this->dataPersistor->clear('entity'); | ||
} catch (${COULD_NOT_SAVE} $exception) { | ||
$this->messageManager->addErrorMessage($exception->getMessage()); | ||
$this->dataPersistor->set('entity', $params); | ||
|
||
return $resultRedirect->setPath('*/*/edit', [ | ||
'${ENTITY_ID}'=> $this->getRequest()->getParam('${ENTITY_ID}') | ||
]); | ||
} | ||
|
||
return $resultRedirect->setPath('*/*/'); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
resources/fileTemplates/internal/Magento Entity Save Controller Class.php.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<html lang="en"> | ||
<body> | ||
<p face="verdana" size="-1"> | ||
|
||
</p> | ||
|
||
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse"> | ||
<tr> | ||
<td colspan="3"><font face="verdana" size="-1">Template's predefined variables:</font></td> | ||
</tr> | ||
<tr> | ||
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAMESPACE}</b></font></nobr></td> | ||
<td width="10"> </td> | ||
<td width="100%" valign="top"><font face="verdana" size="-1"></font></td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> |
111 changes: 111 additions & 0 deletions
111
...com/magento/idea/magento2plugin/actions/generation/data/SaveEntityControllerFileData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.actions.generation.data; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SaveEntityControllerFileData { | ||
|
||
private final String entityName; | ||
private final String moduleName; | ||
private final String namespace; | ||
private final String saveCommandFqn; | ||
private final String dtoType; | ||
private final String acl; | ||
private final String entityId; | ||
|
||
/** | ||
* Controller save file constructor. | ||
* | ||
* @param entityName String | ||
* @param moduleName String | ||
* @param namespace String | ||
* @param saveCommandFqn String | ||
* @param acl String | ||
* @param dtoType String | ||
* @param entityId String | ||
*/ | ||
public SaveEntityControllerFileData( | ||
final @NotNull String entityName, | ||
final @NotNull String moduleName, | ||
final @NotNull String namespace, | ||
final @NotNull String saveCommandFqn, | ||
final @NotNull String dtoType, | ||
final @NotNull String acl, | ||
final @NotNull String entityId | ||
) { | ||
this.entityName = entityName; | ||
this.moduleName = moduleName; | ||
this.namespace = namespace; | ||
this.saveCommandFqn = saveCommandFqn; | ||
this.dtoType = dtoType; | ||
this.acl = acl; | ||
this.entityId = entityId; | ||
} | ||
|
||
/** | ||
* Get entity id. | ||
* | ||
* @return String | ||
*/ | ||
public String getEntityId() { | ||
return entityId; | ||
} | ||
|
||
/** | ||
* Get acl. | ||
* | ||
* @return String | ||
*/ | ||
public String getAcl() { | ||
return acl; | ||
} | ||
|
||
/** | ||
* Get dto type. | ||
* | ||
* @return String | ||
*/ | ||
public String getDtoType() { | ||
return dtoType; | ||
} | ||
|
||
/** | ||
* Get save command Fqn. | ||
* | ||
* @return String | ||
*/ | ||
public String getSaveCommandFqn() { | ||
return saveCommandFqn; | ||
} | ||
|
||
/** | ||
* Get entity name. | ||
* | ||
* @return String | ||
*/ | ||
public String getEntityName() { | ||
return entityName; | ||
} | ||
|
||
/** | ||
* Get module name. | ||
* | ||
* @return String | ||
*/ | ||
public String getModuleName() { | ||
return moduleName; | ||
} | ||
|
||
/** | ||
* Get namespace. | ||
* | ||
* @return String | ||
*/ | ||
public String getNamespace() { | ||
return namespace; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @eduard13
Please consider that this part will be refactored in the scope of the separate task.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the extended testing will be performed in the scope of the whole mainline.