docs
docs copied to clipboard
Tutorial to migrate simple Legacy ModuleAdminControllers to Symfony
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:
- 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,HelperFormandHelperList, and can handle a little bit more complexity in favour of getting a more flexible system. - 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.