Skip to content

Commit

Permalink
Merge branch 'release/1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
jalogut committed Jul 28, 2017
2 parents b906120 + 07b90cd commit 67ec314
Show file tree
Hide file tree
Showing 30 changed files with 1,351 additions and 173 deletions.
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'),
];

//...
}
4 changes: 4 additions & 0 deletions templates/crudEAVWithFile/.no-copied-config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies:
0: crudEAV
1: fileEAVAttribute
2: fileProcessor
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
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'),
];

//...
}
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
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 templates/eavFileAttribute/.no-copied-config/after-generate-info.txt

This file was deleted.

105 changes: 105 additions & 0 deletions templates/fileEAVAttribute/Controller/Adminhtml/${Entityname}/Save.php
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;
}
}

}
Loading

0 comments on commit 67ec314

Please sign in to comment.