-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #521 from magento/mainline-entity-manager
Code generator for a Magento Entity
- Loading branch information
Showing
291 changed files
with
15,838 additions
and
2,564 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
18 changes: 18 additions & 0 deletions
18
resources/fileTemplates/code/Magento Entity Data Mapper.html.ft
This file contains 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> |
52 changes: 52 additions & 0 deletions
52
resources/fileTemplates/code/Magento Entity Data Mapper.php.ft
This file contains 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,52 @@ | ||
<?php | ||
#parse("PHP File Header.php") | ||
|
||
namespace ${NAMESPACE}; | ||
|
||
#set($uses = ${USES}) | ||
#foreach ($use in $uses.split(",")) | ||
use $use; | ||
#end | ||
|
||
/** | ||
* Converts a collection of ${ENTITY_NAME} entities to an array of data transfer objects. | ||
*/ | ||
class ${CLASS_NAME} | ||
{ | ||
/** | ||
* @var ${DTO_FACTORY} | ||
*/ | ||
private $entityDtoFactory; | ||
|
||
/** | ||
* @param ${DTO_FACTORY} $entityDtoFactory | ||
*/ | ||
public function __construct( | ||
${DTO_FACTORY} $entityDtoFactory | ||
) { | ||
$this->entityDtoFactory = $entityDtoFactory; | ||
} | ||
|
||
/** | ||
* Map magento models to DTO array. | ||
* | ||
* @param ${ABSTRACT_COLLECTION} $collection | ||
* | ||
* @return array|${DTO_TYPE}[] | ||
*/ | ||
public function map(${ABSTRACT_COLLECTION} $collection): array | ||
{ | ||
$results = []; | ||
/** @var ${MAGENTO_MODEL_TYPE} $item */ | ||
foreach ($collection->getItems() as $item) { | ||
/** @var ${DTO_TYPE}|${DATA_OBJECT} $entityDto */ | ||
$entityDto = $this->entityDtoFactory->create(); | ||
$entityDto->addData($item->getData()); | ||
|
||
#set($brackets = "[]") | ||
$results$brackets = $entityDto; | ||
} | ||
|
||
return $results; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
resources/fileTemplates/code/Magento Grid UI Component Column.xml.ft
This file contains 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,8 @@ | ||
<column name="${COLUMN_NAME}"> | ||
<settings> | ||
#if (${COLUMN_FILTER}) | ||
<filter>${COLUMN_FILTER}</filter> | ||
#end | ||
<label translate="true">${COLUMN_LABEL}</label> | ||
</settings> | ||
</column> |
Empty file.
This file contains 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
6 changes: 0 additions & 6 deletions
6
resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.ft
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
resources/fileTemplates/code/Magento Php Form Button Block Type Back.php.html
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.ft
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
resources/fileTemplates/code/Magento Php Form Button Block Type Delete.php.html
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.ft
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
resources/fileTemplates/code/Magento Php Form Button Block Type Save.php.html
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.ft
This file contains 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,83 @@ | ||
<?php | ||
#parse("PHP File Header.php") | ||
|
||
namespace ${NAMESPACE}; | ||
|
||
#set($uses = ${USES}) | ||
#foreach ($use in $uses.split(",")) | ||
use $use; | ||
#end | ||
|
||
/** | ||
* Delete ${ENTITY_NAME} by id Command. | ||
*/ | ||
class ${CLASS_NAME} | ||
{ | ||
/** | ||
* @var ${LOGGER} | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var ${MODEL_FACTORY} | ||
*/ | ||
private $modelFactory; | ||
|
||
/** | ||
* @var ${RESOURCE} | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @param ${LOGGER} $logger | ||
* @param ${MODEL_FACTORY} $modelFactory | ||
* @param ${RESOURCE} $resource | ||
*/ | ||
public function __construct( | ||
${LOGGER} $logger, | ||
${MODEL_FACTORY} $modelFactory, | ||
${RESOURCE} $resource | ||
) { | ||
$this->logger = $logger; | ||
$this->modelFactory = $modelFactory; | ||
$this->resource = $resource; | ||
} | ||
|
||
/** | ||
* Delete ${ENTITY_NAME}. | ||
* | ||
* @param int $entityId | ||
* | ||
* @return void | ||
* @throws ${COULD_NOT_DELETE}|${NO_SUCH_ENTITY_EXCEPTION} | ||
*/ | ||
public function execute(int $entityId) | ||
{ | ||
try { | ||
/** @var ${MODEL} $model */ | ||
$model = $this->modelFactory->create(); | ||
$this->resource->load($model, $entityId, '${ENTITY_ID}'); | ||
|
||
if (!$model->getData('${ENTITY_ID}')) { | ||
throw new ${NO_SUCH_ENTITY_EXCEPTION}( | ||
__('Could not find ${ENTITY_NAME} with id: `%id`', | ||
[ | ||
'id' => $entityId | ||
] | ||
) | ||
); | ||
} | ||
|
||
$this->resource->delete($model); | ||
} catch (Exception $exception) { | ||
$this->logger->error( | ||
__('Could not delete ${ENTITY_NAME}. Original message: {message}'), | ||
[ | ||
'message' => $exception->getMessage(), | ||
'exception' => $exception | ||
] | ||
); | ||
throw new ${COULD_NOT_DELETE}(__('Could not delete ${ENTITY_NAME}.')); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
resources/fileTemplates/internal/Magento Delete Entity By Id Command.php.html
This file contains 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> |
61 changes: 61 additions & 0 deletions
61
resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.ft
This file contains 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,61 @@ | ||
<?php | ||
#parse("PHP File Header.php") | ||
|
||
namespace ${NAMESPACE}; | ||
|
||
#set($uses = ${USES}) | ||
#foreach ($use in $uses.split(",")) | ||
use $use; | ||
#end | ||
|
||
/** | ||
* Delete ${ENTITY_NAME} controller. | ||
*/ | ||
class ${CLASS_NAME} extends ${EXTENDS} implements ${IMPLEMENTS_POST}, ${IMPLEMENTS_GET} | ||
{ | ||
/** | ||
* Authorization level of a basic admin session. | ||
* | ||
* @see _isAllowed() | ||
*/ | ||
const ADMIN_RESOURCE = '${ADMIN_RESOURCE}'; | ||
|
||
/** | ||
* @var ${DELETE_COMMAND} | ||
*/ | ||
private $deleteByIdCommand; | ||
|
||
/** | ||
* @param Context $context | ||
* @param DeleteByIdCommand $deleteByIdCommand | ||
*/ | ||
public function __construct( | ||
${CONTEXT} $context, | ||
${DELETE_COMMAND} $deleteByIdCommand | ||
) { | ||
parent::__construct($context); | ||
$this->deleteByIdCommand = $deleteByIdCommand; | ||
} | ||
|
||
/** | ||
* Delete ${ENTITY_NAME} action. | ||
* | ||
* @return ${RESULT_INTERFACE} | ||
*/ | ||
public function execute() | ||
{ | ||
/** @var ${RESULT_INTERFACE} $resultRedirect */ | ||
$resultRedirect = $this->resultFactory->create(${RESULT_FACTORY}::TYPE_REDIRECT); | ||
$resultRedirect->setPath('*/*/'); | ||
$entityId = (int) $this->getRequest()->getParam('${ENTITY_ID}'); | ||
|
||
try { | ||
$this->deleteByIdCommand->execute($entityId); | ||
$this->messageManager->addSuccessMessage(__('You have successfully deleted ${ENTITY_NAME} entity')); | ||
} catch (${COULD_NOT_DELETE} | ${NO_SUCH_ENTITY_EXCEPTION} $exception) { | ||
$this->messageManager->addErrorMessage($exception->getMessage()); | ||
} | ||
|
||
return $resultRedirect; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
resources/fileTemplates/internal/Magento Entity Delete Controller Class.php.html
This file contains 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> |
Oops, something went wrong.