just photo

snippet

Drupal 6. Disable mail field on the user account page

Julia 08/06/2010

If you need to make email field disabled, it won't be anough just make it #disabled.
You have to add the same hidden field:

<?php
function [modulename]_form_alter(&$form, $form_state, $form_id) {
    global
$user;

  switch (
$form_id) {
      case
'user_profile_form':
          if (
$user->uid != 1){
         
// fields must have a hidden field w/ proper value as disabled fields are not submitted.
       
$form['account']['readonly']['mail'] = $form['account']['mail'];
       
$form['account']['readonly']['mail']['#type'] = 'hidden';
           
$form['account']['mail']['#disabled'] = TRUE;
          }
          break;
  }
}
?>

Drupal. How to use an image field from the profile node instead of user picture (avatar)

Julia 19/01/2010

I've recently had to make default pictures for user pictures,
but they had to be defferent for different user roles.

I used the module content_profile
and created two profile content types for Student and Teacher roles.
So I decided to change a user picture derectly in my theme.

I change the preprocess function mytheme_preprocess_user_picture from the user module in the template.php file:

<?php
function mytheme_preprocess_user_picture(&$variables) {

$variables['picture'] = '';
 
   
$account = $variables['account'];
   
   
$user = user_load(array('uid' => $account->uid));   
   
$roles = $user->roles;

   

$profile = '';   
    if (
is_array($roles)) {     
      if (
array_search('student', $roles)) {
         
$profile = 'studentprofile';
      } else if (
array_search('sensei', $roles)) {
         
$profile = 'profile';
      }
    }
   
    if (!empty(
$profile)) {
     
$node_profile = content_profile_load($profile, $account->uid);
     
$field_photo = content_fields('field_photo', $profile);
     
     
$picture = content_view_field($field_photo, $node_profile);
    } else {
   
       
// from default preprocess_user_picture:
       
if (!empty($account->picture) && file_exists($account->picture)) {
         
$picture = file_create_url($account->picture);
        }
        else if (
variable_get('user_picture_default', '')) {
         
$picture = variable_get('user_picture_default', '');
        }
   
        if (isset(
$picture)) {
         
$alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
         
$variables['picture'] = theme('image', $picture, $alt, $alt, '', FALSE);
          if (!empty(
$account->uid) && user_access('access user profiles')) {
           
$attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
           
$variables['picture'] = l($variables['picture'], "user/$account->uid", $attributes);
          }
        }
       
//
       
   
}
   
$variables['picture'] = $picture;

}

?>

How to change Description textfield for filefield to textarea

Julia 15/01/2010
Imagefield with textarea for Description

This is a little snippet for Drupal6 for changing a textfield to a textarea
in the Description field of the CCK file field (filefield module).

By default, you can enable Description field, but that will be a textfield input with 128 charecters length,
but already two customes have asked me to make this field longer, because this field is shown
under images in the lightbox box.

<?php
variable_set
('filefield_description_length', 300);
variable_set('filefield_description_type', 'textarea');
?>

Although the author of this module use variables,
he doesn't give the settings form for them.

тэги:

How to add a custom token

Julia 06/01/2010

It is a snippet - how to create custom tokens for specific replacements that can improve other modules relying on Token.