
Drupal 6
Drupal module Features. Some Tips.
Module features is necessary for site builders in order to maintain big projects.
Some tips about this great module:
Doesn't want to be reverted
It happens sometimes that overridden feature pack doesn't want to be reverted,
for example after updating it in another system.
The solution is simple, if this feature pack has views objects.
You just have to flush views cache and try again.
Show views that are overridden
If you have a lot of feature packs with many views in them
and one of views was changed - in the overridden section
you won't understand the name of view that was changed.
To see it - add template file to your theme:
features-admin-components.tpl.php
<div class='clear-block features-components'>
<div class='column'>
<div class='info'>
<h3><?php print $name ?></h3>
<div class='description'><?php print $description ?></div>
<?php print $dependencies ?>
</div>
</div>
<div class='column'>
<div class='components'>
<?php print $components ?>
<div class='buttons clear-block'><?php print $buttons ?></div>
</div>
</div>
<?php print $form ?>
<?php
$component = 'views';
$normal = features_get_normal($name, $component);
$default = features_get_default($name, $component);
foreach (
$normal as $k => $view){
$compare = array('normal' => features_var_export($normal[$k]), 'default' => features_var_export($default[$k]));
if (_features_linetrim($compare['normal']) !== _features_linetrim($compare['default'])) {
$changed .= l($k, 'admin/build/views/edit/'. $k) . '<br/>';
}
}
if (
$changed) {print '<div><h4>Changed views:</h4>'. $changed .'</div>'; }
?>
</div>Drupal 6. Disable mail field on the user account page
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)
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;
}
?>