Quedada diciembre Drupal Sevilla
The Coding Dead
global $user;
$account = user_load($user->uid);
$output = '<div class="logged-user-info">';
// User picture:
$output .= "<a href='/user/$account->uid'>";
$output .= "<img src='/sites/default/files/pictures/" . $account->picture->filename ."'>";
$output .= "</a>";
// User roles:
$output .= '<ul>';
foreach($user->roles as $rid => $role) {
$output .= '<li>'. $role .'</li>';
}
$output .= '</ul>';
// User achievements:
$output .= '<div class="user-achievements">';
$output .= '<span class="user-points">' . t('User points: @points', array('@points' => 4)) . '</span>';
$output .= '<span class="highlighted-achievement">';
$output .= t('Highest score: @score', array('@score' => 16));
$output .= '</span>';
$output .= '</div>';
$output .= '</div>';
return $output;
}
global $user;
$output = '<div class="logged-user-info">';
// User picture:
$output .= theme('user_picture', array('account' => $user));
// User roles:
$output .= theme('item_list', array('items' => $user->roles));
// User achievements:
$output .= theme('user_achievements', array('points' => 4,'score' => 16));
$output .= '</div>';
// Add custom css & js:
drupal_add_js(drupal_get_path('module', 'render_examples') . '/js/user_achievements.js');
drupal_add_css(drupal_get_path('module', 'render_examples') . '/css/user_achievements.css');
return $output;
global $user;
$render = array(
'user-picture' => array(
'#theme' => 'user_picture',
'#account' => $user,
),
'item-list' => array(
'#theme' => 'item_list',
'#items' => $user->roles,
),
'user-achievements' => array(
'#theme' => 'user_achievements',
'#points' => 4,
'#score' => 16,
'#attached' => array(
'js' => array(drupal_get_path('module', 'render_examples') . '/js/user_achievements.js'),
'css' => array(drupal_get_path('module', 'render_examples') . '/css/user_achievements.css'),
),
),
'#attributes' => array('class' => array('logged-user-info')),
'#theme_wrappers' => array('container'),
);
Más en Form API Reference
Render API & Theming
'user-achievements' => array(
'#theme' => 'user_achievements',
'#points' => 4,
'#score' => 16,
'#attached' => array(
'js' => array(drupal_get_path('module', 'render_examples') . '/js/user_achievements.js'),
'css' => array(drupal_get_path('module', 'render_examples') . '/css/user_achievements.css'),
),
),
$themes['user_achievements'] = array(
'path' => drupal_get_path('module', 'render_examples') . '/templates',
'template' => 'user-achievements',
'variables' => array(
'points' => '',
'score' => '',
),
);
#theme_wrappers
'#theme_wrappers' => array('container'),
'#theme_wrappers' => array('container', 'render_array'),
$themes['render_add_span'] = array(
'render element' => 'element',
);
1.- Defino el theme
2.- Implementamos
/**
* Implements theme_THEME().
*/
function theme_render_add_span(&$variables) {
$element = $variables['element'];
$output = '<span class="render-wrapper-span">';
$output .= $element['#children'];
$output .= '</span>';
return $output;
}
3.- Lo añadimos
'#theme_wrappers' => array('container', 'render_add_span'),
4.- Lo comprobamos
'#attached' => array(
'js' => array(drupal_get_path('module', 'render_examples') . '/js/user_achievements.js'),
'css' => array(drupal_get_path('module', 'render_examples') . '/css/user_achievements.css'),
),
drupal_add_js(drupal_get_path('module', 'render_examples') . '/js/user_achievements.js');
drupal_add_css(drupal_get_path('module', 'render_examples') . '/css/user_achievements.css');
'element_cached' => array(
'#markup' => '',
'#pre_render' => array('render_element_cached_pre_render'),
'#cache' => array(
'keys' => array('render_examples', 'cache-element'),
'bin' => 'cache',
'expire' => time() + 10,
'granularity' => DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_USER,
),
),
1.- El elemento
2.- El pre_render
/**
* Custom pre_render callback for caching example.
* @param $element
* @return mixed
*/
function render_element_cached_pre_render($element) {
$element['#markup'] = render_elements_expensive();
$element['#children'] = $element['#markup'];
return $element;
}
Valencia : http://www.meetup.com/Drupales/events/219173581/
Cáceres : http://www.meetup.com/Drupales/events/219170420/
Madrid : http://www.meetup.com/Drupales/events/219038959/
Sevilla