-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,351 additions
and
173 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
templates/crudEAVWithFile/.no-copied-config/after-generate-info.txt
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,53 @@ | ||
1. Add your STATIC fields on: | ||
|
||
${Vendorname}/${Modulename}/Setup/InstallSchema.php | ||
|
||
2. Add ENTITY EAV Attributes on: | ||
|
||
${Vendorname}/${Modulename}/Setup/${Entityname}Setup.php | ||
|
||
3. Add your custom columns to the grid: | ||
|
||
${Vendorname}/${Modulename}/view/adminhtml/ui_component/${vendorname}_${modulename}_${entityname}_listing.xml | ||
|
||
4. Add your custom fields to the form: | ||
|
||
${Vendorname}/${Modulename}/view/adminhtml/ui_component/${vendorname}_${modulename}_${entityname}_form.xml | ||
|
||
5. Add Attributes to display in Grid on the Listing DataProvider: | ||
|
||
${Vendorname}\${Modulename}\Ui\Component\Listing\DataProvider | ||
|
||
/** | ||
* @param SearchResultInterface $searchResult | ||
* @return array | ||
*/ | ||
protected function searchResultToOutput(SearchResultInterface $searchResult) | ||
{ | ||
$searchResult->setStoreId($this->request->getParam('store', 0)) | ||
->addAttributeToSelect([]); // Add here needed EAV attributes to display on grid | ||
|
||
return parent::searchResultToOutput($searchResult); | ||
} | ||
|
||
6. Set the Admin Menu tab where you want your Module can be found: | ||
|
||
${Vendorname}/${Modulename}/etc/adminhtml/menu.xml | ||
|
||
7. Set From server side Validations: | ||
|
||
${Vendorname}\${Modulename}\Controller\Adminhtml\${Entityname}\Validate: | ||
|
||
/** | ||
* Check if required fields is not empty | ||
* | ||
* @param array $data | ||
*/ | ||
public function validateRequireEntries(array $data) | ||
{ | ||
$requiredFields = [ | ||
'identifier' => __('${Entityname} Identifier'), | ||
]; | ||
|
||
//... | ||
} |
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,4 @@ | ||
dependencies: | ||
0: crudEAV | ||
1: fileEAVAttribute | ||
2: fileProcessor |
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 @@ | ||
This Template creates an EAV crud module using uiComponents for Grid and Form. It includes a file attribute |
53 changes: 53 additions & 0 deletions
53
templates/crudEAVWithMultipleFiles/.no-copied-config/after-generate-info.txt
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,53 @@ | ||
1. Add your STATIC fields on: | ||
|
||
${Vendorname}/${Modulename}/Setup/InstallSchema.php | ||
|
||
2. Add ENTITY EAV Attributes on: | ||
|
||
${Vendorname}/${Modulename}/Setup/${Entityname}Setup.php | ||
|
||
3. Add your custom columns to the grid: | ||
|
||
${Vendorname}/${Modulename}/view/adminhtml/ui_component/${vendorname}_${modulename}_${entityname}_listing.xml | ||
|
||
4. Add your custom fields to the form: | ||
|
||
${Vendorname}/${Modulename}/view/adminhtml/ui_component/${vendorname}_${modulename}_${entityname}_form.xml | ||
|
||
5. Add Attributes to display in Grid on the Listing DataProvider: | ||
|
||
${Vendorname}\${Modulename}\Ui\Component\Listing\DataProvider | ||
|
||
/** | ||
* @param SearchResultInterface $searchResult | ||
* @return array | ||
*/ | ||
protected function searchResultToOutput(SearchResultInterface $searchResult) | ||
{ | ||
$searchResult->setStoreId($this->request->getParam('store', 0)) | ||
->addAttributeToSelect([]); // Add here needed EAV attributes to display on grid | ||
|
||
return parent::searchResultToOutput($searchResult); | ||
} | ||
|
||
6. Set the Admin Menu tab where you want your Module can be found: | ||
|
||
${Vendorname}/${Modulename}/etc/adminhtml/menu.xml | ||
|
||
7. Set From server side Validations: | ||
|
||
${Vendorname}\${Modulename}\Controller\Adminhtml\${Entityname}\Validate: | ||
|
||
/** | ||
* Check if required fields is not empty | ||
* | ||
* @param array $data | ||
*/ | ||
public function validateRequireEntries(array $data) | ||
{ | ||
$requiredFields = [ | ||
'identifier' => __('${Entityname} Identifier'), | ||
]; | ||
|
||
//... | ||
} |
6 changes: 6 additions & 0 deletions
6
templates/crudEAVWithMultipleFiles/.no-copied-config/config.yml
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,6 @@ | ||
dependencies: | ||
0: crudEAV | ||
1: model | ||
2: fileModel | ||
3: fileEAVMultiple | ||
4: fileProcessor |
1 change: 1 addition & 0 deletions
1
templates/crudEAVWithMultipleFiles/.no-copied-config/description.txt
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 @@ | ||
This Template creates an EAV crud module using uiComponents for Grid and Form. It includes Dynamic Multiple Files |
115 changes: 0 additions & 115 deletions
115
templates/eavFileAttribute/.no-copied-config/after-generate-info.txt
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
105 changes: 105 additions & 0 deletions
105
templates/fileEAVAttribute/Controller/Adminhtml/${Entityname}/Save.php
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,105 @@ | ||
<?php | ||
/** | ||
* Save | ||
* | ||
* @copyright Copyright © ${commentsYear} ${CommentsCompanyName}. All rights reserved. | ||
* @author ${commentsUserEmail} | ||
*/ | ||
namespace ${Vendorname}\${Modulename}\Controller\Adminhtml\${Entityname}; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use ${Vendorname}\${Modulename}\Model\${Entityname}Factory; | ||
|
||
class Save extends Action | ||
{ | ||
/** @var ${Entityname}Factory $objectFactory */ | ||
protected $objectFactory; | ||
|
||
/** | ||
* @param Context $context | ||
* @param ${Entityname}Factory $objectFactory | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
${Entityname}Factory $objectFactory | ||
) { | ||
$this->objectFactory = $objectFactory; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function _isAllowed() | ||
{ | ||
return $this->_authorization->isAllowed('${Vendorname}_${Modulename}::${entityname}'); | ||
} | ||
|
||
/** | ||
* Save action | ||
* | ||
* @return \Magento\Framework\Controller\ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
$storeId = (int)$this->getRequest()->getParam('store_id'); | ||
$data = $this->getRequest()->getParams(); | ||
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ | ||
$resultRedirect = $this->resultRedirectFactory->create(); | ||
if ($data) { | ||
$params = []; | ||
$objectInstance = $this->objectFactory->create(); | ||
$objectInstance->setStoreId($storeId); | ||
$params['store'] = $storeId; | ||
if (empty($data['entity_id'])) { | ||
$data['entity_id'] = null; | ||
} else { | ||
$objectInstance->load($data['entity_id']); | ||
$params['entity_id'] = $data['entity_id']; | ||
} | ||
$this->${fileattributename}Preprocessing($data); | ||
$objectInstance->addData($data); | ||
|
||
$this->_eventManager->dispatch( | ||
'${vendorname}_${modulename}_${entityname}_prepare_save', | ||
['object' => $this->objectFactory, 'request' => $this->getRequest()] | ||
); | ||
|
||
try { | ||
$objectInstance->save(); | ||
$this->messageManager->addSuccessMessage(__('You saved this record.')); | ||
$this->_getSession()->setFormData(false); | ||
if ($this->getRequest()->getParam('back')) { | ||
$params['entity_id'] = $objectInstance->getId(); | ||
$params['_current'] = true; | ||
return $resultRedirect->setPath('*/*/edit', $params); | ||
} | ||
return $resultRedirect->setPath('*/*/'); | ||
} catch (\Exception $e) { | ||
$this->messageManager->addErrorMessage($e->getMessage()); | ||
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the record.')); | ||
} | ||
|
||
$this->_getSession()->setFormData($this->getRequest()->getPostValue()); | ||
return $resultRedirect->setPath('*/*/edit', $params); | ||
} | ||
return $resultRedirect->setPath('*/*/'); | ||
} | ||
|
||
/** | ||
* ${Fileattributename} data preprocessing | ||
* | ||
* @param array $data | ||
* | ||
* @return array | ||
*/ | ||
protected function ${fileattributename}Preprocessing(&$data) | ||
{ | ||
if (empty($data['${fileattributename}'])) { | ||
unset($data['${fileattributename}']); | ||
$data['${fileattributename}']['delete'] = true; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.