Closed khaled-badenjki closed 4 years ago
Thank you for the bug report and the possible fix @khaled-badenjki!
When you say this issue -- what problem does this solve? Could you let us know
Thank you @astorm for the reply, and I apologize for my late response
I would like to create a module under vendor Robusta, with name ProductBrand and a model called Brand so the full module name would be Robusta_ProductBrand
How to recreate the issue: Build a module using these commands:
php pestle.phar magento2:generate:module Robusta ProductBrand 0.0.1
php pestle.phar generate_route Robusta_ProductBrand adminhtml robusta_productbrand
(with default input)
php pestle.phar magento2:generate:menu
Module Name? (Pulsestorm_HelloGenerate)] Robusta_ProductBrand
Is this a new top level menu? (Y/N) (N)] Y
Menu Link ID (Robusta_ProductBrand::unique_identifier)]
ACL Resource (Robusta_ProductBrand::unique_identifier)]
Link Title (My Link Title)] Product Brand
Three Segment Action (frontname/index/index)] robusta_productbrand
Sort Order? (10)]
php pestle.phar magento2:generate:crud-model Robusta_ProductBrand Brand
php bin/magento set:up
php pestle.phar generate_view
Which Module? (Pulsestorm_HelloGenerate)] Robusta_ProductBrand
Which Area? (frontend)] adminhtml
Which Handle? (robusta_productbrand_index_index)]
Block Name? (Main)]
Template File? (content.phtml)]
Layout (ignored for adminhtml) ? (1column)]
php pestle.phar magento2:generate:ui:grid
Which Module? (Pulsestorm_Gridexample)] Robusta_ProductBrand
Create a unique ID for your Listing/Grid! (pulsestorm_gridexample_log)] robusta_product_brand_listing
What Resource Collection Model should your listing use? (Magento\Cms\Model\ResourceModel\Page\Collection)] Robusta\ProductBrand\Model\ResourceModel\Brand\Collection
What's the ID field for you model? (pulsestorm_gridexample_log_id)] brand_id
So far there is no issue. Now run the following command:
php pestle.phar magento2:generate:ui:form
Which Module? (Pulsestorm_Formexample)] Robusta_ProductBrand
Model Class? (Pulsestorm\Formexample\Model\Thing)] Robusta\ProductBrand\Model\Brand
ACL Rule for Controllers? (Pulsestorm_Formexample::ruleName)] Robusta_ProductBrand::brand_edit
Now navigate to admin dashboard and check the newly created module. in the index page you can see the empty grid, but if you clcked the Add New button, you will have a dead blank page. This is because the layout files created in the last step have the following names:
robusta_productbrand_brands_brand_edit.xml
robusta_productbrand_brands_brand_new.xml
robusta_productbrand_brands_brand_save.xml
which doesn't match the controller structure. Try editing the flies names manually to:
robusta_productbrand_brand_edit.xml
robusta_productbrand_brand_new.xml
robusta_productbrand_brand_save.xml
in respective.
After cleaning the cache and bin/magento s:di:c
, the Add New button will show the form. Also, saving and editing forms will render properly.
In this fix, I edited the part of code that generates the layout files names to reflect the manual edit described above.
If I entered a bad input during generating the module or this is an intended behavior please let me know.
@khaled-badenjki Thank you for reporting this issue and making this PR, and apologies for the long delay in getting back to you. Magento isn't my full time thing anymore so it's hard to find a spare hour or two to dig into things.
The behavior you describe isn't ideal, but this is also pestle working as intended. Each pestle command it meant to perform a single task, as specified via its command line options, in isolation. If you need two tasks to play nice with each other, you need to make sure you provide the correct parameters for a command. We know this isn't ideal, but we also know people use Magento's base code to build out admin forms in a lot of different ways, and we wanted to make sure pestle could support that
A Solution: Because the above isn't always ideal, we provide the generate full module command command. If you follow the link and read the docs, you'll learn how this command can create a set of pestle invocations that will generate a base module for you with a working form.
$ pestle.phar magento2:generate:full-module Robusta ProductBrand Brand
#!/bin/bash
pestle.phar magento2:generate:module Robusta ProductBrand 0.0.1
pestle.phar magento2:generate:crud-model Robusta_ProductBrand Brand
pestle.phar magento2:generate:acl Robusta_ProductBrand Robusta_ProductBrand::brands
pestle.phar magento2:generate:menu Robusta_ProductBrand "" Robusta_ProductBrand::brands Robusta_ProductBrand::brands "ProductBrand brands" robusta_productbrand_brands/index/index 10
pestle.phar magento2:generate:menu Robusta_ProductBrand Robusta_ProductBrand::brands Robusta_ProductBrand::brands_list Robusta_ProductBrand::brands "Brand Objects" robusta_productbrand_brands/index/index 10
pestle.phar magento2:generate:route Robusta_ProductBrand adminhtml robusta_productbrand_brands Index Index
pestle.phar magento2:generate:view Robusta_ProductBrand adminhtml robusta_productbrand_brands_index_index Main content.phtml 1column
pestle.phar magento2:generate:ui:grid Robusta_ProductBrand robusta_productbrand_brands 'Robusta\ProductBrand\Model\ResourceModel\Brand\Collection' brand_id
pestle.phar magento2:generate:ui:add-column-text app/code/Robusta/ProductBrand/view/adminhtml/ui_component/robusta_productbrand_brands.xml title "Title"
pestle.phar magento2:generate:ui:form Robusta_ProductBrand 'Robusta\ProductBrand\Model\Brand' Robusta_ProductBrand::brands
pestle.phar magento2:generate:ui:add_to_layout app/code/Robusta/ProductBrand/view/adminhtml/layout/robusta_productbrand_brands_index_index.xml content robusta_productbrand_brands
pestle.phar magento2:generate:acl:change_title app/code/Robusta/ProductBrand/etc/acl.xml Robusta_ProductBrand::brands "Manage brands"
pestle.phar magento2:generate:controller_edit_acl app/code/Robusta/ProductBrand/Controller/Adminhtml/Index/Index.php Robusta_ProductBrand::brands
pestle.phar magento2:generate:remove-named-node app/code/Robusta/ProductBrand/view/adminhtml/layout/robusta_productbrand_brands_index_index.xml block robusta_productbrand_block_main
If you follow the naming conventions setup in the above, you should be able to get a module working without issue.
Thank you again for bringing this up, and we hope the fact we're closing this out doesn't sour you on contributing in the future. If there's something about the naming above that creates a problem for you, please reopen the issue and we'll work with you to figure out a solution. Best wishes with your Magento projects.
this issue happens when creating a ui form for a newly created model, using
php pestle.phar magento2:generate:ui:form