- Accueil
- Info légales
- Aide (FAQ)
- Les tags de ce site
- Bloc note
- Articles techniques
- Notes system
- Divers articles
- Drupal
- Notes ITIL 2007
- Notes MS
- Dans le quartier...
- Emploi
- Recettes de cuisine et adresses gourmandes
- mes applis ubuntu préferées
- Divers acronymes du monde social
- Internet 2018
- P2 meublé à louer - quartier du Poteau 75018
- apcos - réseaux sociaux et outils
- Articles techniques
- Divers liens
- Fun
- Mon CV IT
- Nouveautés
preprocess et ex de modification template user - drupal 7
Sous theme corolla. Pour modifier la page d'édition du profile user => user-profile.tpl.php mais comment utiliser le preprocess ?
Il a trouvé le code suivant (qui permet à son thème de voir le tpl ie de charger les variables), mais comment accéder au contenu du tableau $user_profile ?
function mytheme_theme(&$existing, $type, $theme, $path){
$hooks = array();
// Make user-profile.tpl.php available
$hooks['user_profile_form'] = array (
'render element' => 'form',
'path' => drupal_get_path('theme','mytheme'),
'template' => 'templates/user-profile',
'preprocess functions' => array('mytheme_preprocess_user_profile_form'),
);
return $hooks;
}
function mytheme_preprocess_user_profile_form(&$vars) {
$args = func_get_args();
array_shift($args);
$form_state['build_info']['args'] = $args;
$vars['form'] = drupal_build_form('user_profile_form', $form_state['build_info']['args']);
}
user_profile
(user/%user) vs user_profile_form
(user/%user/edit) ?
Pour avoir dans le template $user_profile (en tableau rendu), il faut faire comme le module user: créer un contenu pour l'objet user, faire une boucle sur chaque champs et l'assigner à une variable $user_profile :
function mytheme_preprocess_user_profile_form(&$vars)
{
// load user
$account = user_load(arg(1));
if (!$account) {
// user not found
return;
}
// retrieve all profile fields and attach to $account->content.
user_build_content($account);
// loop through each field attached to the user object
$vars['user_profile'] = array();
foreach (element_children($account->content) as $key) {
// add it to the $user_profile variable, which will be available in tpl
$vars['user_profile'][$key] = $account->content[$key];
}
$args = func_get_args();
array_shift($args);
$form_state['build_info']['args'] = $args;
$vars['form'] = drupal_build_form('user_profile_form', $form_state['build_info']['args']);
}