Drupal
Drupal 6. Показываем тип ноды для админов.
<?php
/**
* Implementation of hook_perm
*/
function [your module]_perm() {
return array(
'view node type'
);
}
function [your module]_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
switch ($op) {
case 'view':
if (user_access('view node type')){
$node->content['node_type']['#value'] = '<div class="node-type">'. t('Material type :: '). node_get_types('name', $node) .'</div>';
$node->content['node_type']['#weight'] = -10;
}
}
}
?>Чтобы это работало, в теме в файлах типа node.tpl.php должна выводиться переменная $content.
(Если же вам не нужны какие-то поля в этой переменной, удалите их оттуда с помощью настроек - галочка в настройках полей Display fields )
How to show list of grouped categories
This is a snippet about creating grouped categories list with views - how it is popular in russian forums - see the picture.
1. First of all - this is term type view (displaying items of type Term). You have to choose this option on the first step of creating view.
2. We need two columns, that's why I use 2 displays: page display and attachment to the page.
2. For grouping terms by the parent term, I use relationship Taxonomy: Parent term.
- that is all main key points, everything I can see on the second picture, attached to the post.
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 Theme by pieces. Menu links (Primary and Secondary)
В этом сниппете из цикла Theme by pieces о главном меню.
в page.tpl.php:
<?php if ($primary_menu): print $primary_menu; endif; ?>
<?php if ($secondary_menu): print $secondary_menu; endif; ?>В template.php в функции
mytheme_preprocess_page(&$vars, $hook):
Стандартный вариант:
<?php
if (!empty($vars['primary_links'])) {
$vars['primary_menu'] = theme('links_primary', $vars['primary_links'], array('class' => 'bookmarks'));
}
?>Дополнительный шаблон
Для сложной верстки, когда не хватает стандартных тегов ul/li,
например, когда меню имеет круглые края.
В этом случае удобнее включить дополнительный шаблон.
<?php
?>
Plain links
For example for Secondary links:
_preprocess_page(&$vars, $hook)
<?php
if (!empty($vars['secondary_links'])) {
$vars['secondary_menu'] = theme('links_secondary', $vars['secondary_links'], array('class' => 'static-menu'));
}
?><?php
/**.
* Implementation of hook_theme.
*
* Register custom theme functions.
*/
function renlife_theme() {
return array(
'links_secondary' => array(
'arguments' => array(
'links' => NULL,
'attributes' => array('class' => 'links'),
'settings' => array(
'delimiter' => '',
'leftcab' => NULL,
'rightcab' => NULL,
)
),
'template' => 'links-plain',
)
);
}
?>Для plain меню, когда разметка меню не содержит ul/li,
но содержит разделители между пунктами тип "|",
используем дополнительный шаблон
plain
<?php
/**
* This snippet changes links layout.
*/
$output = '';
if (
count($links) > 0) {
$output .= '<div'. drupal_attributes($attributes) .'>';
// Display the right cap of the 'button bar'.
if (!empty($settings['leftcab'])) {
$output .= $settings['leftcab'];
}
// Build the list of themed links.
$link_list = array();
foreach ($links as $link) {
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$link_list[] = l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$link_list[] = '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
}
// Add delimiter between the links.
if (!empty($settings['delimiter'])) {
$output .= implode($settings['delimiter'], $link_list);
}
else {
$output .= implode('', $link_list);
}
// Display the right cap of the 'button bar'.
if (!empty($settings['rightcab'])) {
$output .= $settings['rightcab'];
}
$output .= '</div>';
}
print
$output;
?>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;
}
?>Drupal 6. Alter links
How to remove unnecessary links from the group of links under node.
How to change Description textfield for filefield to textarea
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
It is a snippet - how to create custom tokens for specific replacements that can improve other modules relying on Token.
Featured articles changed every 24 hours
So here’s the scenario. For one site it’s been decided that every 24 hours they want the frontpage to change featured article.
Is there a way to do two things.
1) Change featured article (homepage only) every 24 hours.
2) Have the ability to change the article to anything they want.



