docs icon indicating copy to clipboard operation
docs copied to clipboard

Tutorial to migrate simple Legacy ModuleAdminControllers to Symfony

Open madsoliver opened this issue 5 years ago • 3 comments

It's such a simple task to make a good looking, and well functioning module configuration form and/or a list of entities by just extending the Legacy ModuleAdminController. Below is a simple example on a module and it's admin-controller, that both list some table and creates a simple configuration form (that automatically gets the configuration values on load and saves them on submit). Easy peasy, and we love it.

// mymodule/mymodule.php

class mymodule extends Module {
    public function __construct() {
        // ...
        $this->tabs = [
            [          
                'class_name' => 'AdminMyModuleConfigController',
                'parent_class_name' => 'AdminCatalog',
                'name' => 'My Module settings',
                'visible' => true,
            ],
        ];
    }
}


// mymodule/controllers/admin/AdminMyModuleConfigController.php

class AdminMyModuleConfigController extends ModuleAdminController
{
    public function __construct()
    {       
        parent::__construct();
        $this->bootstrap = true;

        $this->table = $this->module->name.'_mylist';
        $this->identifier = 'id';
        $this->_defaultOrderBy = 'id';
        $this->_defaultOrderWay = 'DESC';
        $this->list_no_link = true;
        $this->actions = [];
        $this->actions_available = [];
        $this->lang = false;
        $this->list_simple_header = true;  
        $this->fields_list = [
            'message' => [
                'title' => $this->l('Messages'),
            ]
        ];
        
        $this->fields_options = [
            'options' => 
	            [
	                'title' =>  $this->l('My simple options'),
	                'fields' => [
                        $this->module->name.'_api_key' => [
                            'title' => $this->l('My API KEY'),
                            'type' => 'text',
                        ],
	                'submit' => [
	                    'title' => $this->l('Save'), 
	                    'name' => 'submitOptions'
	                ]
	            ]
            ]
        ];
    }
}

I know that there does not exist such a simple way to do modern controllers, and that there are reasons to this (generating html-code directly in php etc). However: I hope that you will consider to:

  1. make it (almost) as easy to do very common things like the example above in new symfony module admin controllers. Off course, I think most of us would like an even more flexible system than the HelperOptions, HelperForm and HelperList, and can handle a little bit more complexity in favour of getting a more flexible system.
  2. that a tutorial on how to best/fastest migrate such simple legacy admin controllers into symfony.

I realise that this feature request is both relevant to the documentation and the code - let me know if you want me to move it.

madsoliver avatar Sep 08 '20 08:09 madsoliver