From 07b90cd10b39b377aa0343be731dab6915bc7bfa Mon Sep 17 00:00:00 2001 From: alojua Date: Fri, 28 Jul 2017 11:29:48 +0200 Subject: [PATCH] New templates crudEAVWithMultipleFiles and fileEAVMultiple --- .../.no-copied-config/after-generate-info.txt | 53 ++++++ .../.no-copied-config/config.yml | 6 + .../.no-copied-config/description.txt | 1 + .../.no-copied-config/config.yml | 4 + .../.no-copied-config/description.txt | 1 + .../fileEAVMultiple/Model/${Entityname}.php | 131 ++++++++++++++ .../fileEAVMultiple/Setup/InstallSchema.php | 146 +++++++++++++++ templates/fileEAVMultiple/Setup/Uninstall.php | 49 +++++ .../Form/${Entityname}/DataProvider.php | 98 ++++++++++ ...name}_${modulename}_${entityname}_form.xml | 171 ++++++++++++++++++ .../.no-copied-config/after-generate-info.txt | 10 +- ...ntityname}.php => ${Simpleentityname}.php} | 28 +-- templates/fileModel/Setup/InstallSchema.php | 57 ++++++ ...ntityname}.php => ${Simpleentityname}.php} | 12 +- ...ntityname}.php => ${Simpleentityname}.php} | 6 +- .../Collection.php | 6 +- templates/model/Setup/InstallSchema.php | 14 +- templates/model/Setup/Uninstall.php | 4 +- 18 files changed, 757 insertions(+), 40 deletions(-) create mode 100644 templates/crudEAVWithMultipleFiles/.no-copied-config/after-generate-info.txt create mode 100644 templates/crudEAVWithMultipleFiles/.no-copied-config/config.yml create mode 100644 templates/crudEAVWithMultipleFiles/.no-copied-config/description.txt create mode 100644 templates/fileEAVMultiple/.no-copied-config/config.yml create mode 100644 templates/fileEAVMultiple/.no-copied-config/description.txt create mode 100644 templates/fileEAVMultiple/Model/${Entityname}.php create mode 100644 templates/fileEAVMultiple/Setup/InstallSchema.php create mode 100644 templates/fileEAVMultiple/Setup/Uninstall.php create mode 100644 templates/fileEAVMultiple/Ui/Component/Form/${Entityname}/DataProvider.php create mode 100644 templates/fileEAVMultiple/view/adminhtml/ui_component/${vendorname}_${modulename}_${entityname}_form.xml rename templates/fileModel/Model/{${Entityname}.php => ${Simpleentityname}.php} (87%) create mode 100644 templates/fileModel/Setup/InstallSchema.php rename templates/model/Model/{${Entityname}.php => ${Simpleentityname}.php} (76%) rename templates/model/Model/ResourceModel/{${Entityname}.php => ${Simpleentityname}.php} (71%) rename templates/model/Model/ResourceModel/{${Entityname} => ${Simpleentityname}}/Collection.php (62%) diff --git a/templates/crudEAVWithMultipleFiles/.no-copied-config/after-generate-info.txt b/templates/crudEAVWithMultipleFiles/.no-copied-config/after-generate-info.txt new file mode 100644 index 0000000..e7ae95c --- /dev/null +++ b/templates/crudEAVWithMultipleFiles/.no-copied-config/after-generate-info.txt @@ -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'), + ]; + + //... + } \ No newline at end of file diff --git a/templates/crudEAVWithMultipleFiles/.no-copied-config/config.yml b/templates/crudEAVWithMultipleFiles/.no-copied-config/config.yml new file mode 100644 index 0000000..c30aabf --- /dev/null +++ b/templates/crudEAVWithMultipleFiles/.no-copied-config/config.yml @@ -0,0 +1,6 @@ +dependencies: + 0: crudEAV + 1: model + 2: fileModel + 3: fileEAVMultiple + 4: fileProcessor diff --git a/templates/crudEAVWithMultipleFiles/.no-copied-config/description.txt b/templates/crudEAVWithMultipleFiles/.no-copied-config/description.txt new file mode 100644 index 0000000..fd42684 --- /dev/null +++ b/templates/crudEAVWithMultipleFiles/.no-copied-config/description.txt @@ -0,0 +1 @@ +This Template creates an EAV crud module using uiComponents for Grid and Form. It includes Dynamic Multiple Files \ No newline at end of file diff --git a/templates/fileEAVMultiple/.no-copied-config/config.yml b/templates/fileEAVMultiple/.no-copied-config/config.yml new file mode 100644 index 0000000..fdbb924 --- /dev/null +++ b/templates/fileEAVMultiple/.no-copied-config/config.yml @@ -0,0 +1,4 @@ +dependencies: + 0: model + 1: fileModel + 2: fileProcessor \ No newline at end of file diff --git a/templates/fileEAVMultiple/.no-copied-config/description.txt b/templates/fileEAVMultiple/.no-copied-config/description.txt new file mode 100644 index 0000000..9ec1983 --- /dev/null +++ b/templates/fileEAVMultiple/.no-copied-config/description.txt @@ -0,0 +1 @@ +This Template creates the attribute Backend, Ajax and Helpers to have a OneToMany relation between EAV entity and files \ No newline at end of file diff --git a/templates/fileEAVMultiple/Model/${Entityname}.php b/templates/fileEAVMultiple/Model/${Entityname}.php new file mode 100644 index 0000000..339cdc3 --- /dev/null +++ b/templates/fileEAVMultiple/Model/${Entityname}.php @@ -0,0 +1,131 @@ +_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); + } + +} diff --git a/templates/fileEAVMultiple/Setup/InstallSchema.php b/templates/fileEAVMultiple/Setup/InstallSchema.php new file mode 100644 index 0000000..6652759 --- /dev/null +++ b/templates/fileEAVMultiple/Setup/InstallSchema.php @@ -0,0 +1,146 @@ +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(); + } +} diff --git a/templates/fileEAVMultiple/Setup/Uninstall.php b/templates/fileEAVMultiple/Setup/Uninstall.php new file mode 100644 index 0000000..75abb68 --- /dev/null +++ b/templates/fileEAVMultiple/Setup/Uninstall.php @@ -0,0 +1,49 @@ +startSetup(); + + foreach ($this->tablesToUninstall as $table) { + if ($setup->tableExists($table)) { + $setup->getConnection()->dropTable($setup->getTable($table)); + } + } + if ($setup->tableExists('${vendorname}_${modulename}_${simpleentityname}')) { + $setup->getConnection()->dropTable($setup->getTable('${vendorname}_${modulename}_${simpleentityname}')); + } + + $setup->endSetup(); + } +} diff --git a/templates/fileEAVMultiple/Ui/Component/Form/${Entityname}/DataProvider.php b/templates/fileEAVMultiple/Ui/Component/Form/${Entityname}/DataProvider.php new file mode 100644 index 0000000..a08fc69 --- /dev/null +++ b/templates/fileEAVMultiple/Ui/Component/Form/${Entityname}/DataProvider.php @@ -0,0 +1,98 @@ +collection = $collection; + $this->filterPool = $filterPool; + $this->request = $request; + } + + /** + * Get data + * + * @return array + */ + public function getData() + { + if (!$this->loadedData) { + $storeId = (int)$this->request->getParam('store'); + $this->collection + ->setStoreId($storeId) + ->addAttributeToSelect('*'); + $items = $this->collection->getItems(); + foreach ($items as $item) { + $this->setDynamicFiles($item); + $item->setStoreId($storeId); + $this->loadedData[$item->getId()] = $item->getData(); + break; + } + } + return $this->loadedData; + } + + private function setDynamicFiles($item) + { + $files = []; + foreach ($item->getDynamicFiles() as $file) { + // Replace file data with file info needed for form input + $file->setFile($file->getFileValueForForm()); + $files[] = $file->getData(); + } + $item->setDynamicFiles($files); + } +} diff --git a/templates/fileEAVMultiple/view/adminhtml/ui_component/${vendorname}_${modulename}_${entityname}_form.xml b/templates/fileEAVMultiple/view/adminhtml/ui_component/${vendorname}_${modulename}_${entityname}_form.xml new file mode 100644 index 0000000..adcb10c --- /dev/null +++ b/templates/fileEAVMultiple/view/adminhtml/ui_component/${vendorname}_${modulename}_${entityname}_form.xml @@ -0,0 +1,171 @@ + + +
+ + + ${vendorname}_${modulename}_${entityname}_form.${vendorname}_${modulename}_${entityname}_form_data_source + ${vendorname}_${modulename}_${entityname}_form.${vendorname}_${modulename}_${entityname}_form_data_source + + + data + + templates/form/collapsible + ${Entityname} Form + + ${Vendorname}\${Modulename}\Block\Adminhtml\${Entityname}\Edit\BackButton + ${Vendorname}\${Modulename}\Block\Adminhtml\${Entityname}\Edit\DeleteButton + ${Vendorname}\${Modulename}\Block\Adminhtml\${Entityname}\Edit\SaveButton + ${Vendorname}\${Modulename}\Block\Adminhtml\${Entityname}\Edit\SaveAndContinueButton + + + + + ${Vendorname}\${Modulename}\Ui\Component\Form\${Entityname}\DataProvider + ${vendorname}_${modulename}_${entityname}_form_data_source + entity_id + entity_id + + + + + + + + + + Magento_Ui/js/form/provider + + + +
+ + + Main Information + + + + + + true + number + hidden + + 10 + main_fieldset + + + + + + + false + text + input + main_fieldset + + + + + + + true + text + Identifier + input + main_fieldset + + true + + 10 + [GLOBAL] + + + + + + + dynamicRows + record + 20 + true + ${Simpleentityname} + true + + true + + + + + + + true + true + Magento_Ui/js/dynamic-rows/record + container + false + + + + + + false + number + hidden + + + + + + + + fileUploader + fileUploader + Allowed file types: jpeg, gif, png + 2097152 + jpg jpeg gif png + + ${vendorname}_${modulename}/file/uploader + + + + + + + + true + text + Link + input + + + + + + + true + number + hidden + + + + + + + actionDelete + text + false + 50 + + + + + + +
+
diff --git a/templates/fileModel/.no-copied-config/after-generate-info.txt b/templates/fileModel/.no-copied-config/after-generate-info.txt index e0a53c3..d408c0e 100644 --- a/templates/fileModel/.no-copied-config/after-generate-info.txt +++ b/templates/fileModel/.no-copied-config/after-generate-info.txt @@ -13,12 +13,12 @@ 2. Add the formElement into your uiComponent form: - ${Vendorname}/${Modulename}/view/adminhtml/ui_component/${vendorname}_${modulename}_${entityname}_form.xml: + ${Vendorname}/${Modulename}/view/adminhtml/ui_component/${vendorname}_${modulename}_${simpleentityname}_form.xml: - ${Entityname} + ${Simpleentityname} fileUploader fileUploader Allowed file types: jpeg, gif, png @@ -36,7 +36,7 @@ 3.- Get right File format for the form in your DataProvider - ${Vendorname}/${Modulename}/Ui/Component/Form/${Entityname}/DataProvider.php + ${Vendorname}/${Modulename}/Ui/Component/Form/${Simpleentityname}/DataProvider.php /** * Get data @@ -48,7 +48,7 @@ if (!$this->loadedData) { $items = $this->collection->getItems(); foreach ($items as $item) { - $image = $item->get${Entityname}(); + $image = $item->get${Simpleentityname}(); if ($image->getId()) { $item->setFile($image->getFileValueForForm()); } @@ -61,7 +61,7 @@ 4. Save image on your Save action controller - ${Vendorname}/${Modulename}/Controller/Adminhtml/${Entityname}/Save.php: + ${Vendorname}/${Modulename}/Controller/Adminhtml/${Simpleentityname}/Save.php: /** * file data preprocessing diff --git a/templates/fileModel/Model/${Entityname}.php b/templates/fileModel/Model/${Simpleentityname}.php similarity index 87% rename from templates/fileModel/Model/${Entityname}.php rename to templates/fileModel/Model/${Simpleentityname}.php index f83d5e7..3523d59 100644 --- a/templates/fileModel/Model/${Entityname}.php +++ b/templates/fileModel/Model/${Simpleentityname}.php @@ -1,6 +1,6 @@ _init('${Vendorname}\${Modulename}\Model\ResourceModel\${Entityname}'); + $this->_init('${Vendorname}\${Modulename}\Model\ResourceModel\${Simpleentityname}'); } /** * @param FileProcessor $fileProcessor - * @param ${Entityname}Factory $${entityname}Factory + * @param ${Simpleentityname}Factory $${simpleentityname}Factory * @param Context $context * @param Registry $registry * @param AbstractResource|null $resource @@ -72,7 +72,7 @@ protected function _construct() */ public function __construct( FileProcessor $fileProcessor, - ${Entityname}Factory $${entityname}Factory, + ${Simpleentityname}Factory $${simpleentityname}Factory, Context $context, Registry $registry, AbstractResource $resource = null, @@ -88,7 +88,7 @@ public function __construct( ); $this->fileProcessor = $fileProcessor; - $this->${entityname}Factory = $${entityname}Factory; + $this->${simpleentityname}Factory = $${simpleentityname}Factory; } /** @@ -195,8 +195,8 @@ public function saveDynamicFieldFiles(array $files, array $data = []) if (isset($file[$idField]) && !$file[$idField]) { unset($file[$idField]); } - $fileObject = $this->${entityname}Factory->create()->addData($file); - if ($fileObject->getDelete() || !$fileObject->get${Form_field_name}()) { + $fileObject = $this->${simpleentityname}Factory->create()->addData($file); + if ($fileObject->getDelete() || !$fileObject->getFile()) { $fileObject->isDeleted(true); } if (isset($items[$fileObject->getId()])) { diff --git a/templates/fileModel/Setup/InstallSchema.php b/templates/fileModel/Setup/InstallSchema.php new file mode 100644 index 0000000..4411473 --- /dev/null +++ b/templates/fileModel/Setup/InstallSchema.php @@ -0,0 +1,57 @@ +startSetup(); + + /** + * Create table '${vendorname}_${modulename}_${simpleentityname}' + */ + $table = $setup->getConnection()->newTable( + $setup->getTable('${vendorname}_${modulename}_${simpleentityname}') + )->addColumn( + 'id', + Table::TYPE_SMALLINT, + null, + ['identity' => true, 'nullable' => false, 'primary' => true], + '${Simpleentityname} ID' + )->addColumn( + 'filename', + Table::TYPE_TEXT, + 255, + ['nullable' => false], + 'filename' + )->setComment( + '${Simpleentityname} Table' + ); + + // Add more columns here + + $setup->getConnection()->createTable($table); + + $setup->endSetup(); + } +} diff --git a/templates/model/Model/${Entityname}.php b/templates/model/Model/${Simpleentityname}.php similarity index 76% rename from templates/model/Model/${Entityname}.php rename to templates/model/Model/${Simpleentityname}.php index a535a35..fa40c5b 100644 --- a/templates/model/Model/${Entityname}.php +++ b/templates/model/Model/${Simpleentityname}.php @@ -1,7 +1,7 @@ _init('${Vendorname}\${Modulename}\Model\ResourceModel\${Entityname}'); + $this->_init('${Vendorname}\${Modulename}\Model\ResourceModel\${Simpleentityname}'); } /** diff --git a/templates/model/Model/ResourceModel/${Entityname}.php b/templates/model/Model/ResourceModel/${Simpleentityname}.php similarity index 71% rename from templates/model/Model/ResourceModel/${Entityname}.php rename to templates/model/Model/ResourceModel/${Simpleentityname}.php index f63390c..d373feb 100644 --- a/templates/model/Model/ResourceModel/${Entityname}.php +++ b/templates/model/Model/ResourceModel/${Simpleentityname}.php @@ -1,7 +1,7 @@ _init('${vendorname}_${modulename}_${entityname}', 'entity_id'); + $this->_init('${vendorname}_${modulename}_${simpleentityname}', 'id'); } } diff --git a/templates/model/Model/ResourceModel/${Entityname}/Collection.php b/templates/model/Model/ResourceModel/${Simpleentityname}/Collection.php similarity index 62% rename from templates/model/Model/ResourceModel/${Entityname}/Collection.php rename to templates/model/Model/ResourceModel/${Simpleentityname}/Collection.php index ddaec06..2befa25 100644 --- a/templates/model/Model/ResourceModel/${Entityname}/Collection.php +++ b/templates/model/Model/ResourceModel/${Simpleentityname}/Collection.php @@ -5,7 +5,7 @@ * @copyright Copyright © ${commentsYear} ${CommentsCompanyName}. All rights reserved. * @author ${commentsUserEmail} */ -namespace ${Vendorname}\${Modulename}\Model\ResourceModel\${Entityname}; +namespace ${Vendorname}\${Modulename}\Model\ResourceModel\${Simpleentityname}; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; @@ -14,7 +14,7 @@ class Collection extends AbstractCollection /** * @var string */ - protected $_idFieldName = 'entity_id'; + protected $_idFieldName = 'id'; /** * Define resource model @@ -23,6 +23,6 @@ class Collection extends AbstractCollection */ protected function _construct() { - $this->_init('${Vendorname}\${Modulename}\Model\${Entityname}', '${Vendorname}\${Modulename}\Model\ResourceModel\${Entityname}'); + $this->_init('${Vendorname}\${Modulename}\Model\${Simpleentityname}', '${Vendorname}\${Modulename}\Model\ResourceModel\${Simpleentityname}'); } } diff --git a/templates/model/Setup/InstallSchema.php b/templates/model/Setup/InstallSchema.php index e5561bf..fcbd31f 100644 --- a/templates/model/Setup/InstallSchema.php +++ b/templates/model/Setup/InstallSchema.php @@ -28,32 +28,32 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con $setup->startSetup(); /** - * Create table '${vendorname}_${modulename}_${entityname}' + * Create table '${vendorname}_${modulename}_${simpleentityname}' */ $table = $setup->getConnection()->newTable( - $setup->getTable('${vendorname}_${modulename}_${entityname}') + $setup->getTable('${vendorname}_${modulename}_${simpleentityname}') )->addColumn( - 'entity_id', + 'id', Table::TYPE_SMALLINT, null, ['identity' => true, 'nullable' => false, 'primary' => true], - '${Entityname} ID' + '${Simpleentityname} ID' )->addColumn( 'identifier', Table::TYPE_TEXT, 100, ['nullable' => false], - '${Entityname} Identifier' + '${Simpleentityname} Identifier' )->addIndex( $setup->getIdxName( - $setup->getTable('${vendorname}_${modulename}_${entityname}'), + $setup->getTable('${vendorname}_${modulename}_${simpleentityname}'), ['identifier'], AdapterInterface::INDEX_TYPE_FULLTEXT ), ['identifier'], ['type' => AdapterInterface::INDEX_TYPE_FULLTEXT] )->setComment( - '${Entityname} Table' + '${Simpleentityname} Table' ); // Add more columns here diff --git a/templates/model/Setup/Uninstall.php b/templates/model/Setup/Uninstall.php index 92faf56..236f654 100644 --- a/templates/model/Setup/Uninstall.php +++ b/templates/model/Setup/Uninstall.php @@ -22,8 +22,8 @@ public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $c { $setup->startSetup(); - if ($setup->tableExists('${vendorname}_${modulename}_${entityname}')) { - $setup->getConnection()->dropTable($setup->getTable('${vendorname}_${modulename}_${entityname}')); + if ($setup->tableExists('${vendorname}_${modulename}_${simpleentityname}')) { + $setup->getConnection()->dropTable($setup->getTable('${vendorname}_${modulename}_${simpleentityname}')); } $setup->endSetup();