CVS edit link for gaspaio

Hello everybody,

I've been working with Drupal for almost 2 years now, mostly building small websites and custom modules for customers.

I turned a small script I often use in small projects into a module : a simple newsletter subscription block. In short, it activates a block containing a form with only two fields : a text field (validated as an e-mail address), and a submit button. When a site visitor submits a new e-mail address, a trigger is ... triggered so the site administrators can configure an e-mail action to send the form data to somebody.

This is nothing new in Drupal, you can already accomplish this using the Webform module together with the node_blocks module. Except that for small projects, Webform can really be an overkill. My module is addressed to new users and web designers that don't have the time or the budget to spend configuring Webform, its public interface, etc. I use it quite a lot, for that same reason : it's really simple and it works out of the box.

For it to be useful to community members I added a few functionalities to it :

1) The administrator can configure a block header, footer, the fields' labels and contents, and even a small text added to the e-mail input field using JavaScript. This text only appears when the field is empty, and its replaces nicely the field label for those who have little room for a regular form. (see the snapshot)

2) It integrates really nicely with the Token module : the administrator can use the submitted e-mail address as a token (in e-mail actions, for example), and can use global tokens in almost every field available in the block configuration form. This is optional though, as my module also works with the core e-mail action.

3) For more advanced users, the module proposes a hook (hook_simple_subscription), so that the e-mail address can be added to a newletter management application by some other script or module.

4) I tried to comment it quite extensively, so that newbies can easily adapt the code for their own needs.

You can download the Finished Module<:a> (well, I'm sure small bugs are still hiding somewhere, but it supposed to work is most situations) as well as a Snapshot of the configuration page and of the block as it is presented to the user.
As I said, this is a really simple module that tries to do what it is supposed to, nothing more, nothing less.

My plan is to keep it in dev module for a month or so, get some user feedback, solve all the bugs, add some of the requested features (if any) and then release the first finished version.

Have fun !

Comments

gaspaio’s picture

StatusFileSize
new229.61 KB
new25 KB

oops, there was a problem with the download link. You'll find the files attached below.

gaspaio’s picture

Title: gaspaio [gaspaio] » simple_subscription module proposition
Status: Postponed (maintainer needs more info) » Needs review

Changed the status to needs review

avpaderno’s picture

Title: simple_subscription module proposition » gaspaio [gaspaio]
Issue tags: +Module review

Hello, and thanks for applying for a CVS account. I am adding the review tags, and some volunteers will review the code, pointing out what it needs to be changed.

As per requirements, the motivation message should be expanded to contain more features of the proposed project. For themes, it should include also a screenshot of the theme, and (when possible) a link to a working demo site; for modules, it should include also a comparison with the existing solutions.

avpaderno’s picture

Status: Needs review » Needs work
  • This is a partial review.
  • The points reported in this review are not in order of importance / relevance.
  • Most of the times I report the code that present an issue. In such cases, the same error can be present in other parts of the code; the fact I don't report the same issue more than once doesn't mean the same issue is not present in different places.
  • Not all the reported points are application blockers; some of the points I report are simple suggestions to who applies for a CVS account. For a list of what is considered a blocker for the application approval, see CVS applications review, what to expect. Keep in mind the list is still under construction, and can be changed to adapt it to what has been found out during code review, or to make the list clearer to who applies for a CVS account.
  1. The version line needs to be removed from the .info file.
  2. Hook implementation comments should be like the following one:
    /**
     * Implements hook_menu().
     */
    

    As reported in Documenting hook implementations:

    If the implementation of a hook is rather standard and does not require more explanation than the hook reference provides, a shorthand documentation form may be used in place of the full function documentation block described above:

    /**
     * Implements hook_help().
     */
    function blog_help($section) {
      // ...
    }
    

    This generates a link to the hook reference, reminds the developer that this is a hook implementation, and avoids having to document parameters and return values that are the same for every implementation of the hook. Optionally, you can add more information in a separate paragraph to describe the particular quirks of your hook implementation.

    In the case of hooks that have variables in the names, such as hook_form_FORM_ID_alter(), a slightly expanded syntax should be used:

    <?
    /**
    * Implements hook_form_FORM_ID_alter() for node_type_form().
    */
    function mymodule_form_node_type_form_alter(&$form, &$form_state) {
    // ...
    }
    ?>

    This generates a link to the hook reference, as well as to the particular form that is being altered. Again, optionally you can add more information in a separate paragraph to describe the particular quirks of your hook implementation.

  3. Drupal variables are not initialized in hook_install(), or hook_enable().
  4.   /*
       * delete DB references to our block from the database
       */
      db_query("DELETE FROM {blocks} WHERE module='%s'",'simple_subscription');
    
    

    That is already done by Drupal core code, as far as I can see.

  5.       variable_set('simple_subscription_config',array(
            'form_header'   =>  check_markup(trim($edit['simple_subscription_form_header'])),
            'form_footer'   =>  check_markup(trim($edit['simple_subscription_form_footer'])),     
            'input_label'   =>  check_plain(trim($edit['simple_subscription_input_label'])),
            'input_size'    =>  $edit['simple_subscription_input_size'],
            'input_content' =>  check_plain(trim($edit['simple_subscription_input_content'])),
            'submit_value'  =>  substr(check_plain(trim($edit['simple_subscription_submit_value'])),0,20),
            'success_message'=> check_markup($edit['simple_subscription_success_message']),
            'redirect_path' =>  check_url(trim($edit['simple_subscription_redirect_path'])),
            ));
    
    

    check_markup() should be eventually called when the content is output, not when it is saved in a Drupal variable.

  6.       '#description'  =>  t('This text will be displayed before the form'
                                .' elements (leave empty for none). You may use Html tags.'),
    
    

    The first argument of t() is a literal string, not a concatenation of strings. The script used to create the translation template is not able to handle any dynamic value, even in the case of code similar to t($variable); this means that if the argument of the function is not a literal string, it will not appear in the translation template.

  7. See http://drupal.org/coding-standards to understand how a module should be written. In particular, see how the code should be formatted.
  8. There are some typos in the strings used in the user interface (e.g. standart, carefull, adress)
  9.   if ($path) {
        $path = drupal_get_normal_path($path);
        drupal_goto($path);      
      }
      
    
      return true;  
    
    

    A form submission handler doesn't use drupal_goto(), nor returns any values.

gaspaio’s picture

Ok, thanks for the detailed review, i'll read it in detail and do the necessary changes !

avpaderno’s picture

See also what I reported in comment #3.

gaspaio’s picture

Status: Needs work » Needs review
StatusFileSize
new4.92 KB

I reviewed all your comments and changed almost everything you suggested. Thanks again.

The only thing I didn't change is issue 4 in #4. By default, Drupal doesn't seem to remove the block instances from the 'blocks' table when we uninstall the module. At least that's the result I get when I look at the table before and after the uninstall process without the query. Drupal should probably do it, but it doesn't, if I'm not mistaken.

As for #3, you can find a working demo (out of the box, non themed) Here.

As I mentionned before, we can get the same results by combining Webform with Nodeasblock : my module is much simpler than Webform for this specific usage. It is also a lot less intrusive as it makes no changes to the database, and is really easy to theme. It is supposed to be used almost out of the box in simple sites.
For more elaborate uses, developeurs can use the hook my module provides to get the form result and process it according to their needs.

I don't provide any notifications with my module : this is actually a feature, since users can use any notification related actions provided by other modules to pass the form result onto site editors (for example, they can use the Action email role to notify a group of users).

I am willing to add more features to simple_subscription but I'd like to get some user/tester input first. I don't think I should add a lot more though : for complicated forms, site administrators should probably use Webform or build their own custom module.

avpaderno’s picture

None of the Drupal core modules that define a block remove the references to their blocks from the blocks database table.
See poll_uninstall(), book_uninstall(), and forum_uninstall().

gaspaio’s picture

StatusFileSize
new4.84 KB

Indeed. Can anybody tell me why ? It seems to me that this is only polluting the database, but I'm sure there is a logical reason for this ...
Anyway, here's the module with all the corrections above and no query in the uninstall function.

gaspaio’s picture

Title: gaspaio [gaspaio] » simple_subscription module proposition

Any news on the validation of my module proposal ? I'd like to get the ball rolling on this and get some user input :-).

avpaderno’s picture

Title: simple_subscription module proposition » gaspaio [gaspaio]
avpaderno’s picture

Status: Needs review » Fixed

Thank you for your contribution! I am going to update your account.

These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank all the dedicated reviewers as well.

avpaderno’s picture

Assigned: Unassigned » avpaderno

Status: Fixed » Closed (fixed)
Issue tags: -Module review

Automatically closed -- issue fixed for 2 weeks with no activity.

avpaderno’s picture

Component: Miscellaneous » new project application
Issue summary: View changes
Status: Closed (fixed) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.