Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Implements hook_user_presave().
*/
function yourmodule_user_presave(&$edit, $account, $category) {
// 'n' should equal the role id.
if ($account->is_new && isset($edit['fboauth']) && $edit['fboauth']) {
$edit['roles'][n] = TRUE;
}
}
@hanamizuki
hanamizuki / Remove Drupal system stylesheets (CSS)
Created December 18, 2012 14:05
In the .info of your theme, after adding your own css files, add this
; REMOVE THESE DEFAULT STYLESHEETS
stylesheets[all][] = ctools.css
stylesheets[all][] = field.css
stylesheets[all][] = node.css
stylesheets[all][] = system.messages.css
stylesheets[all][] = system.menus.css
stylesheets[all][] = system.base.css
stylesheets[all][] = user.css
stylesheets[all][] = views.css
preferred_syntax = :sass
http_path = '/'
css_dir = "assets/css"
sass_dir = 'assets/sass'
images_dir = 'assets/images'
In a view
<?php print count(views_get_current_view()->result); ?>
Not in a view
<?php
$view = views_get_view('MY_VIEW_NAME');
$view->set_display('MY_DISPLAY'); // like 'block_1'
$view->render();
print sizeof($view->result);
?>
@hanamizuki
hanamizuki / Drupal : Getting flag counts (1)
Created December 18, 2012 14:12
Getting the number of times an item is flagged Whenever an item is flagged, or unflagged, a counter field is updated. To read this counter, use the get_count() method:
<?php
$flag = flag_get_flag('votes') or die('no "votes" flag');
print "The number of people who voted for this proposal:";
print $flag->get_count($node->nid);
?>
@hanamizuki
hanamizuki / Drupal : Getting flag counts (2)
Created December 18, 2012 14:13
A different approach is to use tokens. This module provides a count token for each flag, and you can use it in email messages, for example, and in every place that accepts tokens:
<?php
Hello, [node-author].
Your post has been bookmarked [flag-bookmarks-count] times.
?>
@hanamizuki
hanamizuki / Drupal : Getting flag counts (3)
Created December 18, 2012 14:13
A different method, get_user_count(), is used for counting the items a user has flagged. This method is less efficient than get_count() because an SQL COUNT query is issued.
$flag = flag_get_flag('votes') or die('no "votes" flag');
// We assume an $account variable exists in this template.
print format_plural($flag->get_user_count($account->uid),
'This user has participated in 1 voting.',
'This user has participated in @count votings.');
Deregister migrate classes which is not exist:
drush migrate-deregister —orphans
Other common commands:
migrate-audit (ma) View information on problems in a migration.
@hanamizuki
hanamizuki / gist:4328307
Created December 18, 2012 14:14
Drupal : Render a block programmatically
Drupal 6:
<?php
$block = module_invoke(‘MODULE_NAME’, ‘block’, ‘view’, MODULE_DELTA);
print $block[‘content’];
?>
Two ways,
<?php
print ‘$base_path’;
print ‘$GLOBALS[base_url]’;
?>