Drupal 6: What argument names *not* to use in hook_theme

When defining hook_theme the choice of argument names that are passed to the theme’s template is important. These argument names share a namespace with some default argument names that are added by template_preprocess. Using any of these names will conflict with the default ones and a potentially wrong argument will be accessed in the preprocessing function and template.
In this example the argument name ‘user’ is in potential conflict:

/**
 * hook_theme
 */
function my_module_theme() {
  return array(
    'some_theme' => array(
      'template' => 'some_template',
      'path' => drupal_get_path('module', 'my_module').DIRECTORY_SEPARATOR.'templates',
      'arguments' => array('user' => NULL)
    )
  );
}

To avoid this potential conflict the arguments added by the module can be prefixed with the module’s name so instead of:

      'arguments' => array('user' => NULL)

the argument can be named:

      'arguments' => array('my_module_user' => NULL)

Alternatively, when there are more than one argument, all the arguments can be encapsulated in one array argument that server as a namespace:

      'arguments' => array('my_module_args' => NULL)

where the theme arguments are added as items in an array:

     theme('some_theme', array('user' => $my_user));

and then accessed:

function template_preprocess_some_theme(&$variables) {
  $default_user_arg = $variables['user'];
  $my_user_arg = $variables['my_module_args']['user'];
Posted in Drupal | Tagged , , , , | Leave a comment

hexdump for javascript binary string

hexdump -v -e '"\\\x" 1/1 "%02x" ""' utf8.bin

output format: \xbc\x8d\xd8\xda\x90\x15\x0f\x77\xc8\x0a\xcb\x60\xb9\x67\xac\x5e\x15\xdd\xde\x2c\x6c\xc6\x67\x2a\x3b\xfd\x6d\xb2

source: http://256.com/gray/docs/misc/hexdump_manual_how_to.html

Posted in Uncategorized | Tagged , , , | Leave a comment

Drupal 6: Allow authenticated users to comment anonymously

In a web site where only authenticated users have access to content and comments it may still be required to let authenticated users comment anonymously.
This small module adds the option for the administrator to allow anonymous commenting by authenticated users for specific roles on specific content types.
Where allowed, users get a choice, on the comment creation form, to post their comment anonymously.
Such comments are assigned the anonymous user id but the log will still show the creation of the comment by the authenticated user which makes it a bit less than completely anonymous and allows for some moderation. Within a trusted site membership such feature may encourage more participation with little risk of misuse.

Download Drupal 6 module: anonym_comment.tar.gz

Posted in Drupal | Tagged , | Leave a comment

Drupal 6: Restricting access to users-search

The core search in drupal 6 adds a “Users” search tab in the search page. Although it has permissions settings for content search and for advanced search, there seems to be no built-in option to restrict access to the users search.
One way of achieving this is by overriding the access callback of the search/user URL in hook_menu_alter.
For example, the following code replaces the access callback with user_access() and its argument with ‘administer users’, so only roles with this permission get access to the users search. As a side effect the users search tab is removed if the user doesn’t have this permission. The user/autocomplete path is also handled in the same way.

function mymodule_menu_alter(&$items) {
  if (isset($items['search/user/%menu_tail'])) {
    $menu_item =& $items['search/user/%menu_tail'];
 
    $menu_item['access callback'] = 'user_access';
    $menu_item['access arguments'] = array('administer users');
  }
 
  if (isset($items['user/autocomplete'])) {
    $menu_item =& $items['user/autocomplete'];
 
    $menu_item['access callback'] = 'user_access';
    $menu_item['access arguments'] = array('administer users');
  }
}

Other ways to achieve the same are discussed here.

Tested in Drupal 6.16 with core search.

Posted in Drupal | Tagged , , , | Leave a comment

Drupal 6: Customizing individual checkboxes in hook_form_alter()

When hook_form_alter() is called, form elements of type ‘checkboxes’ are not yet expanded to individual checkbox elements:

Array
(
    [#title] => Options
    [#type] => checkboxes
    [#options] => Array
        (
            [opt_1] => Option 1
            [opt_2] => Option 2
            [opt_3] => Option 3
            [opt_4] => Option 4
        )
 
    [#default_value] => Array
        (
        )
)


If for example we wanted to add a description to each of the checkboxes we could call expand_checkboxes() passing as an argument the checkboxes element.
Continue reading

Posted in Drupal | Tagged , , | Leave a comment

Drupal 6: Notifications and content type access interaction

The notifications module lets users subscribe to content types that they don’t have view access to.

Users that subscribe to such content types will not actually receive the notifications because at the time of assembling the notification message, the permissions on each specific node are tested.

This can be reproduced with the content access module, by granting view access rights for some content types and not others to a certain role and going to the user’s account page: /user/[uid]/notifications/nodetype.

There doesn’t seem to be any hook to override this and using the form alter hook seems too involved.

My work around is to add a hook call in notifications_content_page_nodetype()
Continue reading

Posted in Drupal | Tagged , , | Leave a comment

Welcome to IO Tide

Here you can find some random stuff by GeneticDrift.

Posted in Intro | Leave a comment