-
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.
New templates crudEAVWithMultipleFiles and fileEAVMultiple
- Loading branch information
Showing
18 changed files
with
757 additions
and
40 deletions.
There are no files selected for viewing
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 |
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: model | ||
1: fileModel | ||
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 the attribute Backend, Ajax and Helpers to have a OneToMany relation between EAV entity and files |
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,131 @@ | ||
<?php | ||
|
||
/** | ||
* ${Entityname}.php | ||
* | ||
* @copyright Copyright © ${commentsYear} ${CommentsCompanyName}. All rights reserved. | ||
* @author ${commentsUserEmail} | ||
*/ | ||
|
||
namespace ${Vendorname}\${Modulename}\Model; | ||
|
||
use Magento\Framework\DataObject\IdentityInterface; | ||
use Magento\Framework\Model\AbstractModel; | ||
use Magento\Framework\Model\Context; | ||
use Magento\Framework\Model\ResourceModel\AbstractResource; | ||
use Magento\Framework\Data\Collection\AbstractDb; | ||
use Magento\Framework\Registry; | ||
use ${Vendorname}\${Modulename}\Model\ResourceModel\${Simpleentityname}\Collection as ${Simpleentityname}Collection; | ||
|
||
class ${Entityname} extends AbstractModel implements IdentityInterface | ||
{ | ||
/** | ||
* CMS page cache tag | ||
*/ | ||
const CACHE_TAG = '${vendorname}_${modulename}_${entityname}'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $_cacheTag = '${vendorname}_${modulename}_${entityname}'; | ||
|
||
/** | ||
* Prefix of model events names | ||
* | ||
* @var string | ||
*/ | ||
protected $_eventPrefix = '${vendorname}_${modulename}_${entityname}'; | ||
|
||
/** | ||
* Initialize resource model | ||
* | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
parent::_construct(); | ||
$this->_init('${Vendorname}\${Modulename}\Model\ResourceModel\${Entityname}'); | ||
} | ||
|
||
/** | ||
* Reference constructor. | ||
* @param ${Simpleentityname}Collection $${simpleentityname}Collection, | ||
* @param ${Simpleentityname}Factory $${simpleentityname}Factory, | ||
* @param Context $context | ||
* @param Registry $registry | ||
* @param AbstractResource|null $resource | ||
* @param AbstractDb|null $resourceCollection | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
${Simpleentityname}Collection $${simpleentityname}Collection, | ||
${Simpleentityname}Factory $${simpleentityname}Factory, | ||
Context $context, | ||
Registry $registry, | ||
AbstractResource $resource = null, | ||
AbstractDb $resourceCollection = null, | ||
array $data = [] | ||
) { | ||
parent::__construct( | ||
$context, | ||
$registry, | ||
$resource, | ||
$resourceCollection, | ||
$data | ||
); | ||
$this->${simpleentityname}Collection = $${simpleentityname}Collection; | ||
$this->${simpleentityname}Factory = $${simpleentityname}Factory; | ||
} | ||
|
||
/** | ||
* Get identities | ||
* | ||
* @return array | ||
*/ | ||
public function getIdentities() | ||
{ | ||
return [self::CACHE_TAG . '_' . $this->getId()]; | ||
} | ||
|
||
/** | ||
* Save from collection data | ||
* | ||
* @param array $data | ||
* @return $this|bool | ||
*/ | ||
public function saveCollection(array $data) | ||
{ | ||
if (isset($data[$this->getId()])) { | ||
$this->addData($data[$this->getId()]); | ||
$this->getResource()->save($this); | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* Save images once the main reference data is saved | ||
* | ||
* @return $this | ||
*/ | ||
public function afterSave() //@codingStandardsIgnoreLine | ||
{ | ||
parent::afterSave(); | ||
if (is_array($this->getData('dynamic_files'))) { | ||
$fileObject = $this->${simpleentityname}Factory->create(); | ||
$fileObject->saveDynamicFieldFiles($this->getData('dynamic_files'), ['entity_id' => $this->getId()]); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection | ||
*/ | ||
public function getDynamicFiles() | ||
{ | ||
return $this->${simpleentityname}Collection | ||
->addFieldToFilter('entity_id', $this->getId()) | ||
->addOrder('position', \Magento\Framework\Data\Collection::SORT_ORDER_ASC); | ||
} | ||
|
||
} |
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,146 @@ | ||
<?php | ||
/** | ||
* installSchema.php | ||
* | ||
* @copyright Copyright © ${commentsYear} ${CommentsCompanyName}. All rights reserved. | ||
* @author ${commentsUserEmail} | ||
*/ | ||
namespace ${Vendorname}\${Modulename}\Setup; | ||
|
||
use Magento\Framework\DB\Ddl\Table; | ||
use Magento\Framework\Setup\InstallSchemaInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
use Magento\Framework\Setup\SchemaSetupInterface; | ||
use ${Vendorname}\${Modulename}\Setup\EavTablesSetupFactory; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class InstallSchema implements InstallSchemaInterface | ||
{ | ||
/** | ||
* @var EavTablesSetupFactory | ||
*/ | ||
protected $eavTablesSetupFactory; | ||
|
||
/** | ||
* Init | ||
* | ||
* @internal param EavTablesSetupFactory $EavTablesSetupFactory | ||
*/ | ||
public function __construct(EavTablesSetupFactory $eavTablesSetupFactory) | ||
{ | ||
$this->eavTablesSetupFactory = $eavTablesSetupFactory; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) //@codingStandardsIgnoreLine | ||
{ | ||
$setup->startSetup(); | ||
|
||
$eavTableName = ${Entityname}Setup::ENTITY_TYPE_CODE . '_entity'; | ||
/** | ||
* Create entity Table | ||
*/ | ||
$eavTable = $setup->getConnection() | ||
->newTable($setup->getTable($eavTableName)) | ||
->addColumn( | ||
'entity_id', | ||
Table::TYPE_INTEGER, | ||
null, | ||
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], | ||
'Entity ID' | ||
)->setComment('Entity Table'); | ||
|
||
$eavTable->addColumn( | ||
'identifier', | ||
Table::TYPE_TEXT, | ||
100, | ||
['nullable' => false], | ||
'Identifier' | ||
)->addIndex( | ||
$setup->getIdxName($eavTableName, ['identifier']), | ||
['identifier'] | ||
); | ||
|
||
// Add more static attributes here... | ||
|
||
$eavTable->addColumn( | ||
'created_at', | ||
Table::TYPE_TIMESTAMP, | ||
null, | ||
['nullable' => false, 'default' => Table::TIMESTAMP_INIT], | ||
'Creation Time' | ||
)->addColumn( | ||
'updated_at', | ||
Table::TYPE_TIMESTAMP, | ||
null, | ||
['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE], | ||
'Update Time' | ||
); | ||
$setup->getConnection()->createTable($eavTable); | ||
/** @var \${Vendorname}\${Modulename}\Setup\EavTablesSetup $eavTablesSetup */ | ||
$eavTablesSetup = $this->eavTablesSetupFactory->create(['setup' => $setup]); | ||
$eavTablesSetup->createEavTables(${Entityname}Setup::ENTITY_TYPE_CODE); | ||
|
||
/** | ||
* Create table '${vendorname}_${modulename}_${simpleentityname}' | ||
*/ | ||
$fileTableName = '${vendorname}_${modulename}_${simpleentityname}'; | ||
$fileTable = $setup->getConnection()->newTable( | ||
$setup->getTable($fileTableName) | ||
)->addColumn( | ||
'id', | ||
Table::TYPE_SMALLINT, | ||
null, | ||
['identity' => true, 'nullable' => false, 'primary' => true], | ||
'id' | ||
)->addIndex( | ||
$setup->getIdxName($fileTableName, ['id']), | ||
['id'] | ||
)->setComment( | ||
'${Entityname} ${Simpleentityname}' | ||
); | ||
$fileTable->addColumn( | ||
'entity_id', | ||
Table::TYPE_INTEGER, | ||
null, | ||
['unsigned' => true, 'nullable' => false, 'primary' => true], | ||
'Foreign Key entity_id' | ||
)->addForeignKey( | ||
$setup->getFkName($fileTableName, 'entity_id', $eavTableName, 'entity_id'), | ||
'entity_id', | ||
$setup->getTable($eavTableName), | ||
'entity_id', | ||
Table::ACTION_CASCADE | ||
); | ||
$fileTable->addColumn( | ||
'filename', | ||
Table::TYPE_TEXT, | ||
255, | ||
['nullable' => false], | ||
'filename' | ||
); | ||
$fileTable->addColumn( | ||
'link', | ||
Table::TYPE_TEXT, | ||
255, | ||
['nullable' => true], | ||
'link' | ||
); | ||
$fileTable->addColumn( | ||
'position', | ||
Table::TYPE_SMALLINT, | ||
null, | ||
['nullable' => false, 'default' => '0'], | ||
'position' | ||
); | ||
$setup->getConnection()->createTable($fileTable); | ||
|
||
$setup->endSetup(); | ||
} | ||
} |
Oops, something went wrong.