Skip to content

Instantly share code, notes, and snippets.

View alex-moreno's full-sized avatar

Alejandro Moreno alex-moreno

View GitHub Profile
@alex-moreno
alex-moreno / your_module.info
Last active December 18, 2015 12:19
Modifying webform options with Drupal hook webform_select_options_info
; $Id$
name = Your_Module Webform options
description = Preset options for Your_Module webform fields
package = "Your_Module"
project = Your Project
core = 6.x
version = 6.x-1.0
@alex-moreno
alex-moreno / custom_form.info
Created June 25, 2013 08:27
Creating dropdown dependant forms
; $Id$
name = Custom Form dependant dropdown
description = Dropdown dependant form
project = Dependant dropdown
core = 6.x
version = 6.x-1.0
@alex-moreno
alex-moreno / gist:5920064
Created July 3, 2013 16:24
I always have the same problem when using select forms, and I always forget the solution. Instead of returning an array, like: return $competitions; you have to return a drupal_map_assoc, like this: return drupal_map_assoc($competitions); Otherwise, when selecting the form in hook_submit you will get a number, instead of a human readable string.
/**
* Competition list
*
*/
function mymodule_competitions_results_list_competitions(){
// Main sql
$sql = "SELECT * FROM `node` WHERE type='webform' LIMIT 0,30 ";
@alex-moreno
alex-moreno / gist:6206684
Last active December 20, 2015 22:39
way of deleting thousands of spam messages with a single commando and without overloading the server, timeout problems, etc... Way of executing: drush -u admin php-script sites/all/scripts/delete-spammernodes.php > drush-deletespammer.log --uri=[YOUR-DOMAIN] Do not forget the backup: drush --uri=URI sql-dump > /DIRECTORY/yourbackup.sql change no…
<?php
drush_print( 'Deleting nodes created by user');
// Select nodes from offending user
$result = db_query("SELECT * FROM node WHERE node.uid=27216 AND node.type='group_node' LIMIT 0,50000");
$number_deleted = 0;
while( $row = db_fetch_array( $result ) ) {
echo "\n\n node :: " ;
@alex-moreno
alex-moreno / download_file.module
Last active December 22, 2015 11:18
fetching a view and sending the contents via download browser. two main functions, file_save_data and file_transfer
/**
* Creates and starts client download of the distribution email.
*/
function module_download() {
// Header sets content type to HTML.
$render = '<head>
<title>EDM- </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
@alex-moreno
alex-moreno / CruiseHunterFetcher.php
Last active August 29, 2015 14:00
using symfony dependency injection in Drupal 7 (parameters)
<?php
/**
* Created by PhpStorm.
* User: Alex Moreno
* Date: 16/03/2014
* Time: 16:19
*/
namespace CruiseHunter;
@alex-moreno
alex-moreno / gist:246cd262fcf53e4a5ca7
Created July 8, 2014 08:33
Installing composer in OSX
curl -sS https://getcomposer.org/installer | php;
sudo mv composer.phar /usr/bin/
vim ~/.bash_profile
# add this in ~/.bash_profile
# alias composer="php /usr/bin/composer.phar"
# reboot console
# Original post: http://www.abeautifulsite.net/blog/2013/09/installing-composer-on-os-x/
@alex-moreno
alex-moreno / .bashrc
Last active August 29, 2015 14:03
my .bashrc
# git alias
alias gitlg="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
alias proxyon="export http_proxy='YOUR-PROXY:YOUR-PROXY-PORT'; export https_proxy='YOUR-PROXY:YOUR-PROXY-PORT'"
alias proxyoff="export http_proxy='';export https_proxy=''"
@alex-moreno
alex-moreno / my_module.module
Created January 8, 2015 15:53
Creating a Drupal context programatically
<?php
/**
* Implements hook_context_plugins().
*/
function mymodule_context_plugins() {
$plugins = array();
// Pre search context.
$plugins['mymoduleContextConditionPreSearch'] = array(
'handler' => array(
@alex-moreno
alex-moreno / latest-backup.sh
Created January 28, 2016 15:17
Get the newest file of those in the current folder
DB_BACKUP_PATH="$(pwd)/$(ls -t | grep \.sql\.gz$ | head -n1)"
echo $DB_BACKUP_PATH