Dieses Blog durchsuchen

Sonntag, 22. November 2015

Magento 2 generate new module the rapid way. Part I

Yesterday i was looking for the fastest way, to generate a module with an own entity, admingrid, editforms for the adminbackend etc.

In the past I have used UMC Module Creator for fast prototyping to bringup services rapidly. And I realy liked it on Magento 1.9  On Magento2 the UMC project ist still under heavy development, but the first results are very respactable. Some things are not available at the moment, but the mainfeatures of generating Models, Grids, Adminhtml are.

With this modulegenerator you are able to generate your Entitymodule in 20 minutes.

Lets start:

If you dont have a valid magento2 installation you can use my last install tutorial:
http://magento2-tuts.blogspot.de/2015/11/first-steps.html

At first I had to create a codefolder inside your magentoroot/app folder
 mkdir -p /var/www/html/magento2/app/code/Umc/Base  
 cd /var/www/html/magento2/app/code/Umc/Base  
 git clone https://github.com/UltimateModuleCreator/Umc_Base.git  
copy -fr Umc_Base/* /var/www/html/magento2/app/code/Umc/Base  

 This creates a folder Umc_Base with all the "good stuff" in it. You dont have to take care of registering the namespace, directory and all kind of that configuring stuff. Its all predefined. At the moment its not possible to store your module in the vendor folder. The magento devs will bringup this option later, as I can read in protokoll of a websession with devs and architects earlier this year.

After that you have to enable your extension on the new n98magerun based cli-tool

 cd /var/www/htm/magento2/bin  
 php magento module:enable Umc_Base  
 php magento setup:upgrade  
 php magento setup:di:compile   

the first cli-command enables the module.
the second one is neccessary to upgrade your database structure
the last command compiles the codebase and generates the output.

After that you will get a coreexception of a missing token. This seems to be a bug in Magento Core. You can ignore it for this time

After compiling you have to set your filesystem accessrights new, because the compiling process overrides it.
chmod -R 755 will do the trick (Do not use 755 in production)

 php magento cache:clear  

will clear the cache.

Now you can login in adminarea under
http://magento2.local/admin

A new mainnavigationpoint will come up "UMC" at the bottom of the navigation


After that the usage is almost selfdescribing.
Use the "new module" Button to get in the configscreen.
The formular helps you to get on it.

You can setup your namespace, version, companyname etc. On every field there is a helpfunction to get missing information.

After you have setup your entity, attributes etc you can save the module for downloading it.

Download your zippackage and unpack it. Copy the modulefolder unter
/var/www/html/magento/app/code

At last repeat the step to activate the module, like I descriped some minutes ago.

If everything worked fine, you should now have a new menupoint in the mainnavigation where you have defined your navigationlink.

If you open it you can directly see your new entity with all the known function
- editing
- inlineediting of a row (cool new stuff)
- exporting rows
- massactions
- deletes
- a searchfield with lucence support (new)

My module is named Workflowtask_Task. With that I can an any external workflowengine  to handle usertasks.





But lets see, what code was generated.

Here is my structure of the new module:




I do not want to explain much about the known structures. Most of the things seems to be similar to Magento1 with "little" architectural changes.
Even if these little changes are breaking all backward compatibility for all Modules you have used in the past, which is realy realy annoying and painfull to rewrite. Lets give Magento2 a chance here to have a deeper sight.

Controllers

As you can see all controllers now have only 1 action.  But for the moment I couldnt care less. As a magento2 developer you now have to setup a complete controller for each action.

Alan Storm says
In Magento 2, each controller has one, and only one, entry point. That’s the execute method. This is a step Magento 2’s architects took to help avoid conflicts with a large development teams all editing the same controller file for different features. 


That might be a good reason for that.
http://alanstorm.com/magento_2_mvvm_mvc

A very good deep view of controllers can be found on inchoo
http://inchoo.net/magento-2/magento-2-controllers/


In Part II we will show, how models, routing, di and template definitions are structured.

Thanks for now























Keine Kommentare:

Kommentar veröffentlichen