Skip to content

Instantly share code, notes, and snippets.

@ss81
ss81 / gist:4079378
Last active October 12, 2015 19:58
How to change the title of a Drupal View via code
<?php
function customModule_views_pre_render(&$view) {
if ($view->name == 'view_name' && $view->current_display == 'display_id') {
// Here you can do any php you want to get the title you need for your view.
$view->build_info['title'] = "My custom title!";
}
}
@ss81
ss81 / gist:3910883
Created October 18, 2012 10:20
Open new popup window and maximize it.
var w = window.open(jQuery(this).attr('href'), 'real-size-photo', 'width=500,height=500');
w.moveTo(0, 0);
if (document.all) {
w.resizeTo(screen.availWidth, screen.availHeight);
}
else {
if (document.layers || document.getElementById) {
if (w.outerHeight < screen.availHeight || w.outerWidth < screen.availWidth) {
w.outerHeight = top.screen.availHeight;
@ss81
ss81 / gist:3828375
Last active October 11, 2015 08:07
How to get All options of a 'select' field?
<?php
$field = field_info_field('field_name');
$allowed_values = list_allowed_values($field);
@ss81
ss81 / gist:3828368
Last active October 11, 2015 08:07
Creating and Updating Nodes Programmatically in Drupal 7
<?php
/**
* Basic Node Creation Example for Drupal 7
*
* This example:
* - Assumes a standard Drupal 7 installation
* - Does not verify that the field values are correct
*/
$body_text = 'This is the body text I want entered with the node.';
@ss81
ss81 / gist:3828364
Last active October 11, 2015 08:07
Create a user account in Drupal 7 programmatically
<?php
//This will generate a random password, you could set your own here
$password = user_password(8);
//set up the user fields
$fields = array(
'name' => 'user_name',
'mail' => 'user_name@example.com',
'pass' => $password,
'status' => 1,