├── .github ├── dependabot.yml └── workflows │ ├── ci.yml │ └── dependabot-auto-merge.yml ├── .gitignore ├── Dockerfile ├── README.md ├── app.vue ├── assets └── stubs │ ├── Api │ ├── Data │ │ ├── ModelNameInterface.php.stub │ │ └── ModelNameSearchResultsInterface.php.stub │ └── ModelNameRepositoryInterface.php.stub │ ├── Block │ └── Adminhtml │ │ └── ModelName │ │ └── Edit │ │ ├── BackButton.php.stub │ │ ├── DeleteButton.php.stub │ │ ├── GenericButton.php.stub │ │ └── SaveButton.php.stub │ ├── Controller │ └── Adminhtml │ │ └── ModelName │ │ ├── Delete.php.stub │ │ ├── Edit.php.stub │ │ ├── Index.php.stub │ │ ├── MassDelete.php.stub │ │ ├── NewAction.php.stub │ │ └── Save.php.stub │ ├── Model │ ├── Data │ │ └── ModelName.php.stub │ ├── ModelName │ │ └── DataProvider.php.stub │ ├── ModelNameRepositoryWithDataModel.php.stub │ ├── ModelNameRepositoryWithoutDataModel.php.stub │ ├── ModelNameSearchResults.php.stub │ ├── ModelNameWithDataModel.php.stub │ ├── ModelNameWithoutDataModel.php.stub │ └── ResourceModel │ │ ├── ModelName.php.stub │ │ └── ModelName │ │ └── Collection.php.stub │ ├── Ui │ └── Component │ │ └── Listing │ │ └── Column │ │ └── Actions.php.stub │ ├── composer.json.stub │ ├── etc │ ├── acl.xml.stub │ ├── adminhtml │ │ ├── menu.xml.stub │ │ └── routes.xml.stub │ ├── di.xml.stub │ └── module.xml.stub │ ├── registration.php.stub │ └── view │ └── adminhtml │ ├── layout │ ├── BaseName_edit.xml.stub │ ├── BaseName_index.xml.stub │ └── BaseName_new.xml.stub │ └── ui_component │ └── FormName.xml.stub ├── components ├── AdminGrid.vue ├── BottomSidebar.vue ├── DefineModelColumns.vue ├── ModelColumn.vue ├── ModelInformation.vue ├── ModuleName.vue ├── ScriptModal.vue ├── TopSidebar.vue ├── TreeItem.vue └── TreeView.vue ├── cypress.config.ts ├── cypress ├── e2e │ ├── data-models.cy.js │ ├── fields.cy.js │ └── file-output.cy.js ├── fixtures │ └── example.json └── support │ ├── commands.ts │ └── e2e.ts ├── eslint.config.mjs ├── functions └── xml.ts ├── interfaces ├── AttributeInterface.ts ├── ColumnInterface.ts ├── GeneratesFileInterface.ts ├── GeneratesXmlInterface.ts └── TreeItemInterface.ts ├── nuxt.config.ts ├── output ├── FileList.ts ├── GeneratedFile.ts ├── StateAware.ts └── listing │ ├── Column.ts │ ├── Columns.ts │ ├── DataArgument.ts │ ├── DataSource.ts │ ├── DbSchema.ts │ ├── DbSchemaWhitelist.ts │ ├── ListingTop.ts │ ├── NewButton.ts │ ├── Settings.ts │ ├── UiComponent.ts │ └── UiComponentForm.ts ├── package.json ├── pages ├── README.md └── index.vue ├── public └── favicon.ico ├── run-cypress.sh ├── run-docker.sh ├── server └── tsconfig.json ├── static ├── favicon.png ├── icon.png └── magento2-model-generator-logo.png ├── stores ├── admingridStore.ts ├── downloadStore.ts ├── fathomStore.ts ├── modelStore.ts ├── moduleStore.ts └── tableStore.ts ├── tsconfig.json └── yarn.lock /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Fetch and update latest `npm` packages 4 | - package-ecosystem: npm 5 | directory: '/' 6 | schedule: 7 | interval: daily 8 | time: '00:00' 9 | open-pull-requests-limit: 10 10 | reviewers: 11 | - michielgerritsen 12 | assignees: 13 | - michielgerritsen 14 | commit-message: 15 | prefix: fix 16 | prefix-development: chore 17 | include: scope 18 | # Fetch and update latest `github-actions` pkgs 19 | - package-ecosystem: github-actions 20 | directory: '/' 21 | schedule: 22 | interval: daily 23 | time: '00:00' 24 | open-pull-requests-limit: 10 25 | reviewers: 26 | - michielgerritsen 27 | assignees: 28 | - michielgerritsen 29 | commit-message: 30 | prefix: fix 31 | prefix-development: chore 32 | include: scope 33 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | ci: 7 | runs-on: ${{ matrix.os }} 8 | 9 | strategy: 10 | matrix: 11 | os: [ubuntu-latest] 12 | node: [18] 13 | 14 | steps: 15 | - name: Checkout 🛎 16 | uses: actions/checkout@v4.2.2 17 | 18 | - name: Setup node env 🏗 19 | uses: actions/setup-node@v4 20 | with: 21 | node-version: ${{ matrix.node }} 22 | check-latest: true 23 | 24 | - name: Get yarn cache directory path 🛠 25 | id: yarn-cache-dir-path 26 | run: echo "::set-output name=dir::$(yarn cache dir)" 27 | 28 | - name: Cache node_modules 📦 29 | uses: actions/cache@v4 30 | id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) 31 | with: 32 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 33 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} 34 | restore-keys: | 35 | ${{ runner.os }}-yarn- 36 | 37 | - name: Install dependencies 👨🏻‍💻 38 | run: yarn 39 | 40 | - name: Run linter 👀 41 | run: yarn lint 42 | 43 | - name: Run Cypress 🌎 44 | run: yarn cypress 45 | 46 | - name: Upload artifacts 47 | uses: actions/upload-artifact@v4 48 | if: always() 49 | with: 50 | name: Cypress logs 51 | path: | 52 | cypress/videos 53 | -------------------------------------------------------------------------------- /.github/workflows/dependabot-auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: dependabot-auto-merge 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | dependabot-auto-merge: 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v4.2.2 12 | - uses: ahmadnassri/action-dependabot-auto-merge@v2 13 | with: 14 | github-token: ${{ secrets.dependabot_auto_merge }} 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Nuxt dev/build outputs 2 | .output 3 | .data 4 | .nuxt 5 | .nitro 6 | .cache 7 | dist 8 | 9 | # Node dependencies 10 | node_modules 11 | 12 | # Logs 13 | logs 14 | *.log 15 | 16 | # Misc 17 | .DS_Store 18 | .fleet 19 | .idea 20 | 21 | # Local env files 22 | .env 23 | .env.* 24 | !.env.example 25 | cypress/videos 26 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:18-alpine 2 | 3 | # create destination directory 4 | RUN mkdir -p /usr/src/nuxt-app 5 | WORKDIR /usr/src/nuxt-app 6 | 7 | ENV PYTHONUNBUFFERED=1 8 | RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python 9 | 10 | RUN apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make 11 | RUN npm install --quiet node-gyp -g 12 | 13 | # copy the app, note .dockerignore 14 | COPY . /usr/src/nuxt-app/ 15 | RUN yarn install 16 | RUN yarn run build 17 | 18 | EXPOSE 3000 19 | 20 | ENV NUXT_HOST=0.0.0.0 21 | ENV NUXT_PORT=3000 22 | 23 | CMD yarn install && yarn dev 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Magento 2 Model Generator 2 | 3 | With this app, you can create models for Magento 2 very fast. If you are not sure what a model in Magento 2 is, I can recommend you to read [this article](https://www.michiel-gerritsen.com/where-to-place-code-in-a-magento-2-module) (TLDR: It's everything that you need to connect to your database). 4 | 5 | Writing models can become cumbersome, as you need to write a lot of boilerplate code which is sort of the same for every model you need to make. 6 | 7 | This app tries to take the cumbersome out of your hands and generate the code for you. 8 | 9 | ## Build Setup 10 | 11 | ```bash 12 | # install dependencies 13 | $ yarn install 14 | 15 | # serve with hot reload at localhost:3000 16 | $ yarn dev 17 | 18 | # build for production and launch server 19 | $ yarn build 20 | $ yarn start 21 | 22 | # generate static project 23 | $ yarn generate 24 | ``` 25 | 26 | For detailed explanation on how things work, check out [Nuxt.js docs](https://nuxtjs.org). 27 | 28 | ## Using docker 29 | 30 | Build the image: 31 | 32 | ```bash 33 | docker build -t magento2-model-generator . 34 | ``` 35 | 36 | Run the container: 37 | 38 | ```bash 39 | docker run --rm -it -v $(pwd):/usr/src/nuxt-app --name m2mg -p 3000:3000 magento2-model-generator 40 | ``` 41 | 42 | or simply use: 43 | 44 | ```bash 45 | sh run-docker.sh 46 | ``` 47 | -------------------------------------------------------------------------------- /app.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /assets/stubs/Api/Data/ModelNameInterface.php.stub: -------------------------------------------------------------------------------- 1 | __('Back'), 18 | 'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()), 19 | 'class' => 'back', 20 | 'sort_order' => 10 21 | ]; 22 | } 23 | 24 | /** 25 | * Get URL for back (reset) button 26 | * 27 | * @return string 28 | */ 29 | public function getBackUrl() 30 | { 31 | return $this->getUrl('*/*/'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /assets/stubs/Block/Adminhtml/ModelName/Edit/DeleteButton.php.stub: -------------------------------------------------------------------------------- 1 | getId()) { 18 | $data = [ 19 | 'label' => __('Delete Item'), 20 | 'class' => 'delete', 21 | 'on_click' => 'deleteConfirm(\'' . __( 22 | 'Are you sure you want to do this?' 23 | ) . '\', \'' . $this->getDeleteUrl() . '\', {"data": {}})', 24 | 'sort_order' => 20, 25 | ]; 26 | } 27 | return $data; 28 | } 29 | 30 | /** 31 | * URL to send delete requests to. 32 | * 33 | * @return string 34 | */ 35 | public function getDeleteUrl() 36 | { 37 | return $this->getUrl('*/*/delete', ['{{ FieldIndex }}' => $this->getId()]); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /assets/stubs/Block/Adminhtml/ModelName/Edit/GenericButton.php.stub: -------------------------------------------------------------------------------- 1 | context = $context; 29 | $this->repository = $repository; 30 | } 31 | 32 | public function getId(): ?int 33 | { 34 | $id = $this->context->getRequest()->getParam('{{ IndexField }}'); 35 | if (!$id) { 36 | return null; 37 | } 38 | 39 | try { 40 | return $this->repository->get($id)->getId(); 41 | } catch (NoSuchEntityException $e) { 42 | } 43 | return null; 44 | } 45 | 46 | /** 47 | * Generate url by route and parameters 48 | * 49 | * @param string $route 50 | * @param array $params 51 | * @return string 52 | */ 53 | public function getUrl($route = '', $params = []) 54 | { 55 | return $this->context->getUrlBuilder()->getUrl($route, $params); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /assets/stubs/Block/Adminhtml/ModelName/Edit/SaveButton.php.stub: -------------------------------------------------------------------------------- 1 | __('Save'), 18 | 'class' => 'save primary', 19 | 'data_attribute' => [ 20 | 'mage-init' => [ 21 | 'buttonAdapter' => [ 22 | 'actions' => [ 23 | [ 24 | 'targetName' => '{{ FormName }}.{{ FormName }}', 25 | 'actionName' => 'save', 26 | 'params' => [ 27 | true, 28 | [ 29 | 'back' => 'continue' 30 | ] 31 | ] 32 | ] 33 | ] 34 | ] 35 | ] 36 | ], 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /assets/stubs/Controller/Adminhtml/ModelName/Delete.php.stub: -------------------------------------------------------------------------------- 1 | modelFactory = $modelFactory; 31 | $this->modelResource = $modelResource; 32 | } 33 | 34 | /** @thows \Exception */ 35 | public function execute(): Redirect 36 | { 37 | try { 38 | $id = $this->getRequest()->getParam('{{ IndexField }}'); 39 | /** @var {{ ModelName }} $model */ 40 | $model = $this->modelFactory->create(); 41 | $this->modelResource->load($model, $id); 42 | if ($model->getId()) { 43 | $this->modelResource->delete($model); 44 | $this->messageManager->addSuccessMessage(__('The record has been deleted.')); 45 | } else { 46 | $this->messageManager->addErrorMessage(__('The record does not exist.')); 47 | } 48 | } catch (\Exception $e) { 49 | $this->messageManager->addErrorMessage($e->getMessage()); 50 | } 51 | 52 | /** @var Redirect $redirect */ 53 | $redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); 54 | 55 | return $redirect->setPath('*/*'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /assets/stubs/Controller/Adminhtml/ModelName/Edit.php.stub: -------------------------------------------------------------------------------- 1 | pageFactory->create(); 27 | $page->setActiveMenu('{{ VendorName }}_{{ ModuleName }}::{{ ModelName }}'); 28 | $page->getConfig()->getTitle()->prepend(__('Edit {{ ModelName }}')); 29 | 30 | return $page; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /assets/stubs/Controller/Adminhtml/ModelName/Index.php.stub: -------------------------------------------------------------------------------- 1 | pageFactory->create(); 27 | $page->setActiveMenu('{{ VendorName }}_{{ ModuleName }}::{{ ModelName }}'); 28 | $page->getConfig()->getTitle()->prepend(__('{{ ModelName }}s')); 29 | 30 | return $page; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /assets/stubs/Controller/Adminhtml/ModelName/MassDelete.php.stub: -------------------------------------------------------------------------------- 1 | collectionFactory->create(); 30 | $items = $this->filter->getCollection($collection); 31 | $itemsSize = $items->getSize(); 32 | 33 | foreach ($items as $item) { 34 | $item->delete(); 35 | } 36 | 37 | $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $itemsSize)); 38 | 39 | /** @var Redirect $redirect */ 40 | $redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); 41 | 42 | return $redirect->setPath('*/*'); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /assets/stubs/Controller/Adminhtml/ModelName/NewAction.php.stub: -------------------------------------------------------------------------------- 1 | pageFactory->create(); 27 | $page->setActiveMenu('{{ VendorName }}_{{ ModuleName }}::{{ ModelName }}'); 28 | $page->getConfig()->getTitle()->prepend(__('New {{ ModelName }}')); 29 | 30 | return $page; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /assets/stubs/Controller/Adminhtml/ModelName/Save.php.stub: -------------------------------------------------------------------------------- 1 | request->getParam('{{ IndexField }}'); 28 | $data = $this->request->getPostValue(); 29 | 30 | $model = $this->modelFactory->create(); 31 | if ($id) { 32 | $model = $this->repository->get((int)$id); 33 | } 34 | 35 | $model->setData($data); 36 | 37 | try { 38 | $model = $this->repository->save($model); 39 | $this->messageManager->addSuccessMessage(__('You saved the item.')); 40 | } catch (\Exception $e) { 41 | $this->messageManager->addErrorMessage($e->getMessage()); 42 | return $this->resultRedirectFactory->create()->setPath('*'); 43 | } 44 | 45 | return $this->resultRedirectFactory->create() 46 | ->setPath('*/*/edit', ['entity_id' => $model->getId()]); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /assets/stubs/Model/Data/ModelName.php.stub: -------------------------------------------------------------------------------- 1 | _get(self::{{ fieldNameUppercase }}); 17 | } 18 | 19 | public function set{{ functionName }}({{ phpType }} ${{ fieldName }}): {{ ModelName }}Interface 20 | { 21 | return $this->setData(self::{{ fieldNameUppercase }}, ${{ fieldName }}); 22 | } 23 | 24 | {{/Columns}} 25 | public function getExtensionAttributes(): ?{{ ModelName }}ExtensionInterface 26 | { 27 | return $this->_getExtensionAttributes(); 28 | } 29 | 30 | public function setExtensionAttributes( 31 | {{ ModelName }}ExtensionInterface $extensionAttributes 32 | ): static { 33 | return $this->_setExtensionAttributes($extensionAttributes); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /assets/stubs/Model/ModelName/DataProvider.php.stub: -------------------------------------------------------------------------------- 1 | collection = $collectionFactory->create(); 19 | } 20 | 21 | public function getData(): array 22 | { 23 | $data = parent::getData(); 24 | 25 | $items = []; 26 | foreach ($data['items'] as $item) { 27 | $items[$item['entity_id']] = $item; 28 | } 29 | 30 | return $items; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /assets/stubs/Model/ModelNameRepositoryWithDataModel.php.stub: -------------------------------------------------------------------------------- 1 | extensibleDataObjectConverter->toNestedArray( 41 | $entity, 42 | [], 43 | {{ ModelName }}Interface::class 44 | ); 45 | 46 | ${{ VariableName }}Model = $this->{{ VariableName }}Factory->create()->setData(${{ VariableName }}Data); 47 | 48 | try { 49 | $this->resource->save(${{ VariableName }}Model); 50 | } catch (\Exception $exception) { 51 | throw new CouldNotSaveException(__( 52 | 'Could not save the {{ VariableName }}: %1', 53 | $exception->getMessage() 54 | )); 55 | } 56 | return ${{ VariableName }}Model->getDataModel(); 57 | } 58 | 59 | /** 60 | * @throws NoSuchEntityException 61 | */ 62 | public function get(int $id): {{ ModelName }}Interface 63 | { 64 | ${{ VariableName }} = $this->{{ VariableName }}Factory->create(); 65 | $this->resource->load(${{ VariableName }}, $id); 66 | if (!${{ VariableName }}->getId()) { 67 | throw new NoSuchEntityException(__('{{ ModelName }} with id "%1" does not exist.', $id)); 68 | } 69 | return ${{ VariableName }}->getDataModel(); 70 | } 71 | 72 | public function getList(SearchCriteriaInterface $criteria): {{ ModelName }}SearchResultsInterface 73 | { 74 | $collection = $this->{{ VariableName }}CollectionFactory->create(); 75 | 76 | $this->extensionAttributesJoinProcessor->process( 77 | $collection, 78 | {{ ModelName }}Interface::class 79 | ); 80 | 81 | $this->collectionProcessor->process($criteria, $collection); 82 | 83 | $searchResults = $this->searchResultsFactory->create(); 84 | $searchResults->setSearchCriteria($criteria); 85 | 86 | $items = []; 87 | foreach ($collection as $model) { 88 | $items[] = $model->getDataModel(); 89 | } 90 | 91 | $searchResults->setItems($items); 92 | $searchResults->setTotalCount($collection->getSize()); 93 | return $searchResults; 94 | } 95 | 96 | /** 97 | * @throws CouldNotDeleteException 98 | */ 99 | public function delete({{ ModelName }}Interface ${{ VariableName }}): bool 100 | { 101 | try { 102 | ${{ VariableName }}Model = $this->{{ VariableName }}Factory->create(); 103 | $this->resource->load(${{ VariableName }}Model, ${{ VariableName }}->getEntityId()); 104 | $this->resource->delete(${{ VariableName }}Model); 105 | } catch (\Exception $exception) { 106 | throw new CouldNotDeleteException(__( 107 | 'Could not delete the {{ ModelName }}: %1', 108 | $exception->getMessage() 109 | )); 110 | } 111 | return true; 112 | } 113 | 114 | public function deleteById(int $id): bool 115 | { 116 | return $this->delete($this->get($id)); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /assets/stubs/Model/ModelNameRepositoryWithoutDataModel.php.stub: -------------------------------------------------------------------------------- 1 | resource->save($entity); 38 | } catch (\Exception $exception) { 39 | throw new CouldNotSaveException(__( 40 | 'Could not save the {{ VariableName }}: %1', 41 | $exception->getMessage() 42 | )); 43 | } 44 | return $entity; 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | public function get(int $id): {{ ModelName }}Interface 51 | { 52 | ${{ VariableName }} = $this->{{ VariableName }}Factory->create(); 53 | $this->resource->load(${{ VariableName }}, $id); 54 | if (!${{ VariableName }}->getId()) { 55 | throw new NoSuchEntityException(__('{{ ModelName }} with id "%1" does not exist.', $id)); 56 | } 57 | return ${{ VariableName }}; 58 | } 59 | 60 | /** 61 | * {@inheritdoc} 62 | */ 63 | public function getList(SearchCriteriaInterface $criteria): {{ ModelName }}SearchResultsInterface 64 | { 65 | $collection = $this->{{ VariableName }}CollectionFactory->create(); 66 | 67 | $this->extensionAttributesJoinProcessor->process( 68 | $collection, 69 | {{ ModelName }}Interface::class 70 | ); 71 | 72 | $this->collectionProcessor->process($criteria, $collection); 73 | 74 | $searchResults = $this->searchResultsFactory->create(); 75 | $searchResults->setSearchCriteria($criteria); 76 | 77 | $items = []; 78 | foreach ($collection as $model) { 79 | $items[] = $model; 80 | } 81 | 82 | $searchResults->setItems($items); 83 | $searchResults->setTotalCount($collection->getSize()); 84 | return $searchResults; 85 | } 86 | 87 | /** 88 | * {@inheritdoc} 89 | */ 90 | public function delete({{ ModelName }}Interface $entity): bool 91 | { 92 | try { 93 | ${{ VariableName }}Model = $this->{{ VariableName }}Factory->create(); 94 | $this->resource->load(${{ VariableName }}Model, $entity->getEntityId()); 95 | $this->resource->delete(${{ VariableName }}Model); 96 | } catch (\Exception $exception) { 97 | throw new CouldNotDeleteException(__( 98 | 'Could not delete the {{ ModelName }}: %1', 99 | $exception->getMessage() 100 | )); 101 | } 102 | return true; 103 | } 104 | 105 | /** 106 | * {@inheritdoc} 107 | */ 108 | public function deleteById(int $id): bool 109 | { 110 | return $this->delete($this->get($id)); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /assets/stubs/Model/ModelNameSearchResults.php.stub: -------------------------------------------------------------------------------- 1 | getData(); 32 | 33 | $dataObject = $this->{{ VariableName }}DataFactory->create(); 34 | $this->dataObjectHelper->populateWithArray( 35 | $dataObject, 36 | $data, 37 | {{ ModelName }}InterfaceFactory::class 38 | ); 39 | 40 | return $dataObject; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /assets/stubs/Model/ModelNameWithoutDataModel.php.stub: -------------------------------------------------------------------------------- 1 | _init(ResourceModel\{{ ModelName }}::class); 17 | } 18 | 19 | {{#Columns}} 20 | /** 21 | * Get {{ fieldName }} 22 | * @return {{ phpType }}|null 23 | */ 24 | public function get{{ functionName }}(): ?{{ phpType }} 25 | { 26 | return $this->getData(self::{{ fieldNameUppercase }}); 27 | } 28 | 29 | /** 30 | * Set {{ fieldName }} 31 | * @param {{ phpType }} ${{ fieldName }} 32 | * @return {{ ModelName }}Interface 33 | */ 34 | public function set{{ functionName }}({{ phpType }} ${{ fieldName }}): {{ ModelName }}Interface 35 | { 36 | return $this->setData(self::{{ fieldNameUppercase }}, ${{ fieldName }}); 37 | } 38 | 39 | {{/Columns}} 40 | /** 41 | * Retrieve existing extension attributes object or create a new one. 42 | * @return {{ ModelName }}ExtensionInterface|null 43 | */ 44 | public function getExtensionAttributes(): ?{{ ModelName }}ExtensionInterface 45 | { 46 | return $this->_getExtensionAttributes(); 47 | } 48 | 49 | /** 50 | * Set an extension attributes object. 51 | * @param {{ ModelName }}ExtensionInterface $extensionAttributes 52 | * @return $this 53 | */ 54 | public function setExtensionAttributes( 55 | {{ ModelName }}ExtensionInterface $extensionAttributes 56 | ): static { 57 | return $this->_setExtensionAttributes($extensionAttributes); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /assets/stubs/Model/ResourceModel/ModelName.php.stub: -------------------------------------------------------------------------------- 1 | _init(self::MAIN_TABLE, self::ID_FIELD_NAME); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /assets/stubs/Model/ResourceModel/ModelName/Collection.php.stub: -------------------------------------------------------------------------------- 1 | _init({{ ModelName }}::class, \{{ VendorName }}\{{ ModuleName }}\Model\ResourceModel\{{ ModelName }}::class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /assets/stubs/Ui/Component/Listing/Column/Actions.php.stub: -------------------------------------------------------------------------------- 1 | urlBuilder = $urlBuilder; 41 | parent::__construct($context, $uiComponentFactory, $components, $data); 42 | } 43 | 44 | /** 45 | * @inheritDoc 46 | */ 47 | public function prepareDataSource(array $dataSource) 48 | { 49 | if (isset($dataSource['data']['items'])) { 50 | foreach ($dataSource['data']['items'] as & $item) { 51 | if (isset($item['{{ IndexField }}'])) { 52 | $item[$this->getData('name')] = [ 53 | 'edit' => [ 54 | 'href' => $this->urlBuilder->getUrl( 55 | static::URL_PATH_EDIT, 56 | [ 57 | '{{ IndexField }}' => $item['{{ IndexField }}'] 58 | ] 59 | ), 60 | 'label' => __('Edit') 61 | ], 62 | 'delete' => [ 63 | 'href' => $this->urlBuilder->getUrl( 64 | static::URL_PATH_DELETE, 65 | [ 66 | '{{ IndexField }}' => $item['{{ IndexField }}'] 67 | ] 68 | ), 69 | 'label' => __('Delete'), 70 | 'confirm' => [ 71 | 'title' => __('Delete item'), 72 | 'message' => __('Are you sure you want to delete this record?') 73 | ], 74 | 'post' => true 75 | ], 76 | ]; 77 | } 78 | } 79 | } 80 | 81 | return $dataSource; 82 | } 83 | 84 | /** 85 | * Get instance of escaper 86 | * 87 | * @return Escaper 88 | * @deprecated 101.0.7 89 | */ 90 | private function getEscaper() 91 | { 92 | if (!$this->escaper) { 93 | // phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor 94 | $this->escaper = ObjectManager::getInstance()->get(Escaper::class); 95 | } 96 | return $this->escaper; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /assets/stubs/composer.json.stub: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{ VendorName }}/{{ ModuleName}}", 3 | "authors": [ 4 | { 5 | "name": "{{ VendorName }}", 6 | "email": "user@example.com" 7 | }, 8 | { 9 | "name": "model-generator.com", 10 | "email": "modelgenerator@controlaltdelete.nl" 11 | } 12 | ], 13 | "require": { 14 | "php": "~8.1" 15 | }, 16 | "autoload": { 17 | "files": [ 18 | "src/registration.php" 19 | ], 20 | "psr-4": { 21 | "{{ VendorName }}\\{{ ModuleName }}\\": "src/" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /assets/stubs/etc/acl.xml.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /assets/stubs/etc/adminhtml/menu.xml.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /assets/stubs/etc/adminhtml/routes.xml.stub: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /assets/stubs/etc/di.xml.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{#IncludeAdminGrid}} 7 | 8 | 9 | 10 | 11 | {{ VirtualCollectionName }} 12 | 13 | 14 | 15 | 16 | 17 | 18 | {{ TableName }} 19 | {{ VendorName }}\{{ ModuleName }}\Model\ResourceModel\{{ ModelName }} 20 | 21 | 22 | {{/IncludeAdminGrid}} 23 | 24 | -------------------------------------------------------------------------------- /assets/stubs/etc/module.xml.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /assets/stubs/registration.php.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /assets/stubs/view/adminhtml/layout/BaseName_index.xml.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /assets/stubs/view/adminhtml/layout/BaseName_new.xml.stub: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /assets/stubs/view/adminhtml/ui_component/FormName.xml.stub: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | {{ FormName }}.{{ FormDataSource }} 6 | 7 | General Information 8 | templates/form/collapsible 9 | 10 | 11 | 12 |