Skip to content

Instantly share code, notes, and snippets.

@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' => '[email protected]',
'pass' => $password,
'status' => 1,
@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: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: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: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:4079387
Created November 15, 2012 16:02
Draft of Selenium Test
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://example.com/" />
<title>checkout</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
@ss81
ss81 / gist:4086579
Last active October 12, 2015 20:58
Only one product in shopping cart.
<?php
/**
* Implementation of hook_form_alter()
*/
function hook_form_alter(&$form, $form_state, $form_id) {
if (drupal_match_path($form_id, 'uc_product_add_to_cart_form_*')) {
array_unshift($form['#submit'], 'uc_product_before_add_to_cart_submit');
}
}
@ss81
ss81 / gist:4374498
Created December 25, 2012 18:03
Get the list of form elements
$('#user-register :input').each(function(){
console.log($(this).attr('name'))
});
@ss81
ss81 / gist:4452537
Created January 4, 2013 13:19
Get list of changes, which were committed since a revision, provided in command line.
`svn diff -r #{ARGV[0]}:HEAD --summarize`.lines().each { |file|
p file.chomp.gsub(/[AM ]/, "")
}
@ss81
ss81 / gist:4546841
Created January 16, 2013 12:35
Drupal 6/7. Set one error message for several form elements.
<?php
$msg = t('Your message here.');
form_set_error('field_shopdata_paypal][0][value', $msg);
form_set_error('field_shopdata_paypal_fname][0][value', $msg);
array_pop($_SESSION['messages']['error']); // Remove doubled mesage.
form_set_error('field_shopdata_paypal_lname][0][value', $msg);
array_pop($_SESSION['messages']['error']); // Remove doubled mesage.