Module creator

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
tamasd's picture

Module creator

Overview

Most simple (10-15 lines) modules use “components” (piece of code). At the implementation level, a component is a class, with input, and based on that it's output. In connecting” components we can create the business logic of a module. This module will only handle basic tasks, but it will be a great help for all the little glue modules that most projects need, that basically implement a hook, call 3-4 functions, and based on that return data.

Goal

By the end of the summer, I would like to create a basic API, and an example interface with Drush. My module will only ship components for Drupal 6.x core, but it will supply hooks, so new component classes for other modules can easily be registered. The result will be a companion module for the patterns module (but for modules creation, not for settings). Since everything is declared in XML or YAML, it will be very easy to get out the variables and store (or export a module) it in a patterns-like format.

Applications

There are several areas where this module can be useful.
-Modules like http://drupal.org/project/helpinject
-other examples?

Technical implementation plans

In the backend, I will define a very easy description script language with XML or YAML syntax, later this “script language” can be used to generate a source file (valid for my parser, and valid for PHP), that can be “compiled”. (but this is not for now)

An example module in Drush:
drush mc create-module my_generated_module
drush mc add-hook my_generated_module form_alter
drush mc add-component my_generated_module formid string my_form // create-component parameters: module name, unique instance name, component name, constructor parameters...
drush mc add-component my_generated_module formid_cmp eq_compare
drush mc add-component my_generated_module formid_action my_action_block
drush mc connect my_generated_module formid.out formid_cmp.in2
drush mc connect my_generated_module form_alter.form_id formid_cmp.in1
drush mc connect my_generated_module formid_action.code formid_cmp.ifTrue
drush mc connect my_generated_module form_alter.form formid_action.form
drush mc connect my_generated_module formid_cmp.evald form_alter.return

In the example you can see 4 components:

  • The string component is a very simple one. It represents a primitive type, and it returns a predefined value. In this example, we initialized it with “my_form”.
  • The hook_form_alter component is also a simple one: it has 3 “out parameters” and it asks for a return value (it is essential for the implementation, but in this example, it will always receive NULL)
  • The my_action_block asks for an input parameter, and returns “executable code”.
  • The eq_compare component is a simple if statement. It has 4 “in parameters”: the first two are the values to compare. The third and the forth parameter takes executable code pieces (practically a return value of a block). I can demonstrate how it works with this little snippet:
    if($this->param1 == $this->param2) $this->ifTrue->execute(); else $this->ifFalse->execute();

The evaluation starts from the return value of the hook, and it will recursively go through all components and it will execute the module.

Difficulity: Medium

Link to my student proposal: http://socghop.appspot.com/student_proposal/show/google/gsoc2009/yorirou...

Comments

I am looking forward for

tamasd's picture

I am looking forward for mentors :)

SoC 2009

Group categories

Admin Tags

Group notifications

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

Hot content this week