CVS edit link for Kevin Quillen

I want to contribute a module that was developed for a website of the US Travel government organization. I did some research first and found no module to suit my needs.

This module allows a user with the proper permissions to create an 'alert message', which displays at the top of the site, like CNN Breaking News. When enabled, this module sets a cookie to track that user, so when they close a message, they don't see it again.

Example of what this module does: http://blog.melissahie.com/wp-content/uploads/2009/06/michaeljackson-cnn...

Comments

kevinquillen’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new5.71 KB

Working code posted.

How to use:

Enable the module, and assign the User Alert block to a region of your choice. Create a User Alert node, and it will display until either you close it or the time limit for the message expires. There are settings to allow you to change the display label from User Alert to something else, as well as set a expiration time for messages (1, 3, 6, 9, 12, 24 hours or never).

Right now it will also unpublish any published alert when a new one is created or updated to published, to avoid having a bunch of messages show up.

avpaderno’s picture

Status: Needs review » Needs work
Issue tags: +Module review

Hello, and thanks for applying for a CVS account.

May you describe a bit more the proposed module, and make a comparison with existing solutions?

kevinquillen’s picture

Sure.

I am filling a gap wherein the admin or someone with permission can create an 'Alert', which is basically a short direct message at the top of the screen. The best comparison of the functionality is a BREAKING NEWS flash on a news site. A user can X out the message and it goes away. drupal_set_message didn't satisfy my use case to also allow tpl/css overrides, and a click to close functionality.

I looked at admin_message (http://drupal.org/project/admin_message) but this was architected for logged in users only, and has a different purpose in mind. My module uses a cookie to track a visitor (assigning a UUID), and not rely on the Drupal user object which does not store data about an anonymous user, as not all sites will have users log in. This way, anyone coming to the website can see the urgent message, regardless if they are logged in or not, which satisfies my use case in providing the functionality that you would see on CNN or even Facebook.

Beyond that one module, I did not see anything close to what I wanted to achieve.

kevinquillen’s picture

StatusFileSize
new5.27 KB

Fixed a slight bug in the cron hook.

avpaderno’s picture

Status: Needs work » Needs review

Thank you for your reply.

kevinquillen’s picture

Hi guys any update here?

kevinquillen’s picture

I have added this module into GitHub for time being so I can track my changes. Please let me know of an update when you can would love to have it on drupal.org.

kevinquillen’s picture

StatusFileSize
new5.16 KB

Removed the drupal_goto in the init(). I implemented that prior to having AJAX method of closing the message. The drupal_goto interfered with crawlers.

avpaderno’s picture

Assigned: Unassigned » avpaderno

I will review the code tomorrow morning.

kevinquillen’s picture

Thank you

avpaderno’s picture

Status: Needs review » Needs work
  • The points reported in this review are not in order or 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. /**
     * Implementation of hook_form
     */
    
    function user_alert_settings_form() {
    			
    	$form = array();
    
    	$form['user_alert_label'] = array(
    		'#title' => 'User alert label',
    		'#type' => 'textfield',
    		'#description' => t('The label next to every user alert message.'),
    		'#default_value' =>	variable_get('user_alert_label', 'User Alert'),
    	);
    	
    	$form['user_alert_timelimit'] = array(
    		'#title' => 'User alert timelimit',
    		'#type' => 'select',
    	    '#options' => array(
    			0 => 'Never', 
    			3600 => '1 hour', 
    			10800 => '3 hours', 
    			21600 => '6 hours',
    			32400 => '9 hours',
    			43200 => '12 hours',
    			86400 => '24 hours'
    			),
    		'#description' => t('You can automatically unpublish alerts after a given time period. "Never" will leave them up forever, until the user closes it.'),
    		'#default_value' =>	variable_get('user_alert_timelimit', 0),
    	);
    	
    	$form['submit']['save'] = array(
    		'#type' => 'submit',
    		'#name' => 'save',
    		'#value' => t('Save'),
    	);
    	
    	$form['#submit'][] = 'user_alert_settings_submit';
    
    	return $form;	
    }
    
    /**
     * Implementation of hook_submit
     */
    
    function user_alert_settings_submit(&$form, $form_state) {
    	
    	variable_set('user_alert_label', $form_state['values']['user_alert_label']);
    	variable_set('user_alert_timelimit', $form_state['values']['user_alert_timelimit']);
    	
    	drupal_set_message(t('User alert settings have been updated.'), 'status', FALSE);
    
    	return;
    }
    

    Neither the functions are implementations of a hook.
    The coding standards report there should not be any empty lines between the documentation comment and the function.
    The return statement in the last function is not required.

  2. package = Other
    

    The default package is Other; there is no need to declare it.

  3. Drupal variables are not initialized from hook_install().
  4. 	$result = db_query('SELECT nid FROM {node} WHERE type = "%s"', 'user_alert');
    	
    	while($row = db_fetch_object($result)) {
    		node_delete($row->nid);
    	}
    

    None of the Drupal core modules removes nodes of the content type they define.

  5. /**
     * Implementation of hook_perm()
     */
    
    function user_alert_perm() {
    	return array('administer user alert', 'create user alert', 'edit own user alert', 'edit any user alert', 'delete own user alert', 'delete any user alert');
    }
    

    AFAIK, the permissions to edit any node of a content type, to edit own nodes of a content type, to delete any nodes of a content type, and to delete own nodes of a content type are already defined from the node module. See the permissions defined in book_perm(), which doesn't define the permission edit own books, in example.

  6. See http://drupal.org/coding-standards to understand how a module should be written. In particular, see how the code should be formatted, and how hook implementations should be commented.
  7.   $node = $vars['node'];
      $vars['alert_label'] = t(variable_get('user_alert_label', 'User Alert'));
      $vars['body'] = t($node->body);
    
    

    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.

kevinquillen’s picture

Okay, I will address these. A few I was not aware of and was just following the lead of other modules I have seen.

About #4 though, why would Drupal not want a module to clean up its data? I can see the drawbacks, but at the same time, if you really wanted something out of the system, shouldn't it do that? That is what I thought anyway.

avpaderno’s picture

I can see a reason why book.module, in example, doesn't delete any book pages, when it is removed.
With few exceptions, Drupal core code is usually the reference code to use to write your own code; the exceptions are, in example, the name to give to the functions, and the use of functions with a name starting with _.

kevinquillen’s picture

StatusFileSize
new5 KB

Gotcha. Changed _form to _admin_settings and removed submit handler. Reformatted a majority of my comments to the coding standards page, removed the node deletion on uninstall, removed the variable sets in the install, removed the t() on variable output, removed package declaration, removed all perms other than 'administer user alert'.

kevinquillen’s picture

Status: Needs work » Needs review
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.

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