Introduction of Page Controllers into Drupal

Events happening in the community are now at Drupal community events on www.drupal.org.
hinikato's picture

There is a special page that describes what Page Controller is and how it can be used: http://drupal.org/node/1389042

I would like to suggest introduce the Page Controllers for all core modules.

Each controller class could use a namespace. For example if module name is "foo_bar" and the page controller name is "MyController", the namespace would be "FooBar" and the class name would be MyController, so the full class name would be \FooBar\MyController.

Moreover I would like to consider to use following structure for module directories:
- module_name/forms/ - all forms. For example for the form callback module_name_my_form_id(), the file name can be 'my_form_id.inc'.
- module_name/nodeapi/ - node API.
- module_name/libs/ - some useful libraries/classes.
- module_name/controllers/ - page controllers. Each controller can handle set of paths. Each controller is class that should end with the "Controller" suffix, for example MyController. The controller classes can use the namespace.
- module_name/ui/ - user interface including (theme_*() functions, and the *.tpl.php files).
- module_name/models/ - models (optional)
- module_name/tests/ - tests.
- module_name/utils/ - some utility classes.
- module_name/services/ - services. Each service can be called from the Page Controller or other service class. Each service is class that should end with the "Service" suffix, for example MyService. The service classes can use the namespaces.
- module_name/repos/ - repositories (Repository pattern, optional).

I hope I wrote in the right place to suggest and introduce these concepts ;)

Comments

Not MVC

Crell's picture

Well, Drupal does not use the pseudo-MVC pattern common to a number of projects that took inspiration from Rails: http://www.garfieldtech.com/blog/mvc-vs-pac So a lot of those structures would not make sense.

There's an ongoing discussion of how to handle module organization for classes already, revolving around the PSR-0 standard. Actually there's about 5, but the most current and actionable one is here: http://drupal.org/node/1400748

Also, a single controller per response is too limiting for what Drupal is being asked to do these days. That's why the WSCCI initiative is pushing for a more layered approach, as described:

http://groups.drupal.org/node/198538
http://groups.drupal.org/node/148149
http://www.garfieldtech.com/blog/web-services-initiative
http://www.garfieldtech.com/blog/drupal-post-page-era

I don't think simply wrapping page callback functions into objects buys us much, especially compared to the work that is already under way. If the above links excite you, though, track me down in IRC (#drupal-wscci) and let's see if we can put you to work. :-)

Hi, Crell Thank you for your

hinikato's picture

Hi, Crell

Thank you for your answer. I excited by your suggestion. I can't meet via IRC or other ways for now. I have tried to show some ideas that can be useful. So now I know that you/others know about them and I can be calm ;)

Page and web services

fgm's picture

Not to forget something: WSCCI is (also) about being a better REST server, and the various web services (XML-RPC, SOAP, REST...) do not typically provide "pages" in the usual sense, but need various deviations on the standard HTTP/REST model (if you look at the REST Maturity Model, XML-RPC and SOAP are level 0 compliant only, for example).

Web Services and Context Core Initiative

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week