CVS edit link for bartonfreelance

I've been using Drupal for many years now. I've made a lot of money using Drupal as my framework of choice. Drupal has saved my butt many times. I've always been an open source developer, piggy backing onto the work of others. However, I've never really been able to give back what I've taken.

The reason I'd like a CVS account and why I'd like to contribute to the Drupal community is that I'd like to give back to the community. I've gained so much from the community and I haven't given anything back. This would be the first time I've open sourced any of the code that I've written.

I have 2 modules off the top of my head that I'd like to donate, and many others that I hope to write for Drupal 6 (and moving forward, Drupal 7).

One module adds hook_message_alter to Drupal 6. I've searched and searched and haven't found any module that actually allows me to alter the messages besides overriding the theme. Now, I've created a module that gives this ability along with some added helper functions.

The second module that I’ve written overrides how the css & js are aggregated. The reason I did this is because with anonymous users, the page is cached and when you have multiple servers running (2 web servers and 1 database server), the css points to a file that is created on one server, but not the other. This module fixes that by routing the css & js to a php script that generates the file if it doesn’t exist. This a little bit more plug and play than having to route things using apache. Most developers these days aren’t very good and a lot of them are designers. Hey, it’s the economy man.

I hope that you except this as a good motivation. It is to me. I have been using Drupal for years, but I’ve never given back to the community. This is my shot to at least get 2 good modules out there to help others in need. Thank you.

Comments

BartonDrupal’s picture

StatusFileSize
new1.58 KB
BartonDrupal’s picture

Status: Postponed (maintainer needs more info) » Needs review
avpaderno’s picture

Issue tags: +Module review
dawehner’s picture


  $hook = 'message_alter';
  $modules = module_implements($hook);
  foreach ($modules as $module) {
    $func = $module . '_' . $hook;
    call_user_func($func, &$adapter);
  }

I think you can remove this part by using drupal_alter('message', &$adapter), or not?

  $theme = variable_get('messages_theme_altered', '');
  $output = $theme($display);

Couldn't you use here theme('status_messages', $display);

I don't really like the name, why dont' you use messages_alter. The messages name could be also a alternative private messaging system or yet another notification system.

I like the module :)!

dawehner’s picture

Status: Needs review » Needs work

Update status

BartonDrupal’s picture

StatusFileSize
new1.67 KB

I implemented drupal_alter, thanks. I forgot about that function. In addition, I added another theme function that can be overridden should someone want to use their own theme function.

BartonDrupal’s picture

Status: Needs work » Needs review
BartonDrupal’s picture

StatusFileSize
new1.75 KB

I just re-read you saying you didn't like the name of the module. I renamed the module "messages_alter."

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine.

avpaderno’s picture

Status: Reviewed & tested by the community » Fixed

The module should declare its dependency from PHP 5, as Drupal 6 works on PHP 4 too.

Why are there two theme functions, where the first calls the second one?

/**
 * Theme function
 * This is the theme function that overrides
 * theme('status_messages');
 */
function theme_messages_alter_alter($display=NULL) {

  messages_alter_invoke_message_alter();

  $output = theme('messages_alter_status_messages', $display, variable_get('messages_alter_theme_altered', FALSE));

  return $output;

}

/**
 * Theme function
 * Using a theme function here so that if someone wants to overide it, they can.
 */
function theme_messages_alter_status_messages($display=NULL, $theme_function=FALSE) {
  
  $output = '';
  
  if ($theme_function) {
    $output = $theme_function($display);
  }
  
  return $output;
  
}
BartonDrupal’s picture

I'll add this:

// PHP 5.x constructor
  function __construct(&$messages) {

    $this->MessagesAdapter($messages);

  }
  
  // PHP 4.x constructor
  function MessagesAdapter(&$messages) {
    
    $this->messages =& $messages;  
  
  }

And theme_messages_alter_alter isn't really a theme function. It's a function that is replacing another function. I'm using hook_theme_registry_alter and changing the function that is being used. Of course someone can override this function through basic theming but I don't really want them to because then that defeats the purpose of the module. So I've provided another theme that can be overridden should someone want to theme the status messages differently.

avpaderno’s picture

Using a single function doesn't alter the behavior of the module.

/**
* Theme function
* This is the theme function that overrides
* theme('status_messages');
*/
function theme_messages_alter_alter($display=NULL) {

  messages_alter_invoke_message_alter();

  $output = '';
  
  if (($theme_function = variable_get('messages_alter_theme_altered', FALSE))) {
    $output = $theme_function($display);
  }
  
  return $output;
}
/*
 * Implementation of hook_theme_registry_alter to add messages theme function
 */
function messages_alter_theme_registry_alter(&$theme_registry) {
  if (!variable_get('messages_alter_theme_altered', FALSE)) {
    variable_set('messages_alter_theme_altered', $theme_registry['status_messages']['function']);
  }
  $theme_registry['status_messages']['function'] = 'theme_messages_alter_alter';
}
BartonDrupal’s picture

Are you wanting me to drop the theme_ prefix? I have it broken into 2 functions so I can keep my hook in there and still allow for developers to do this:

function phptemplate_messages_alter_status_messages($default=NULL) {
return 'overridden';
}

Since they can't do this anymore:

function phptemplate_status_messages($display = NULL){
return 'overridden';
}

I'll document this so themers know how to do what this guy is doing here:
http://teddy.fr/blog/theming-almost-hidden

avpaderno’s picture

I was just wondering about the need to have two functions. If I would have wanted you to change the code, I would not have approved your application.

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
Assigned: Unassigned » avpaderno
Issue summary: View changes
Status: Closed (fixed) » Fixed

Status: Fixed » Closed (fixed)

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