Skip to content

Instantly share code, notes, and snippets.

View ccamara's full-sized avatar

Carlos Cámara ccamara

View GitHub Profile
@ccamara
ccamara / drush.commands.sh
Last active December 26, 2015 03:38
#drush commands for files and databases #syncronization
# Creates a copy of current database, deletes it and syncs it with dev
drush ard && drush sql-drop && drush sql-sync @site.dev @site.local
# Sync files
drush rsync @site.dev:%files @site.local:%files
@ccamara
ccamara / drush.sh
Last active December 25, 2015 16:29
Simple #drush command to find which modules implement a certain #hook #drupal
drush php-eval 'print_r(module_implements("hook_name"))'
@ccamara
ccamara / une-50-104-94.csl.xml
Last active December 23, 2015 04:28
#zotero #citation-style #UNE 50-104-94
<?xml version="1.0" encoding="utf-8"?>
<style class="in-text" version="1.0" demote-non-dropping-particle="sort-only" default-locale="es_ES" xmlns="http://purl.org/net/xbiblio/csl">
<!-- This style was edited with the Visual CSL Editor (http://editor.citationstyles.org/visualEditor/) -->
<info>
<title>UNE 50-104-94</title>
<id>http://www.zotero.org/styles/une-50-104-94</id>
<link href="https://gist.github.com/ccamara/6580003" rel="self"/>
<link href="http://www.aenor.es/aenor/normas/normas/fichanorma.asp?tipo=N&amp;codigo=N0005073&amp;PDF=Si#.UjbzZKxTlhE" rel="documentation"/>
<author>
<name>Carlos Cámara</name>
@ccamara
ccamara / yourmodule.module
Last active December 22, 2015 10:58
How to rename a #variable in #drupal
<?php
/**
* Renames a function
*/
function yourmodule_default_theme_settings() {
$new_variable_name = variable_get('old_variable_name', NULL); //Loads the variable to be renamed from drupal's variables table and assigns it to a new one.
variable_set('new_variable_name', $new_variable_name); //Stores $new_variable_name into drupal's variables table.
variable_del('old_variable_name'); //Deletes the old variable from drupal's variables table
}
@ccamara
ccamara / drush sql-connect.sh
Last active December 22, 2015 07:29
How to import and export a #sql file into a database using #drush #drupal #database #sql-cli
# Export database.
drush sql-dump > ~/my-sql-dump-file-name.sql
# Import database.
drush sql-cli < backup.sql
@ccamara
ccamara / drushrc.php
Last active December 20, 2015 13:19
Increase #drush memory limit. #drupal
<?php
/**
* Examples of valid statements for a Drush runtime config (drushrc) file.
* Use this file to cut down on typing out lengthy and repetitive command line
* options in the Drush commands you use and to avoid mistakes.
*
* Rename this file to drushrc.php and optionally copy it to one of the places
* listed below in order of precedence:
*
@ccamara
ccamara / module-name.module
Last active December 19, 2015 22:38
Display Suite's output modification in order to add a new class under certain circumstances #drupal #displaysuite
<?php
/**
* Implements hook_theme_registry_alter().
*/
function feature_blog_theme_registry_alter(&$theme_registry) {
$theme_registry['node']['preprocess functions'][] = 'onecolumn_class_node_preprocess';
}
/*
@ccamara
ccamara / yourmodule.module
Last active December 18, 2015 21:38
Populates an existing vocabulary with terms when a module/feature is installed #drupal #taxonomy
<?php
/**
* Implements hook_install().
*/
function yourmodule_install() {
// Populates 'name_of_vocabulary' vocabulary with taxonomy terms.
// Edit name_of_vocabulary with your desired vocabulary's machine name.
$vocabulary = taxonomy_vocabulary_machine_name_load('name_of_vocabulary');
$terms = array();
@ccamara
ccamara / gist:5772934
Last active December 18, 2015 10:59
Example of implementation of a hook validate #drupal
<?php
/**
* Implements hook_node_validate().
*
* Makes image field required.
*/
function mymodule_node_validate($node, $form, &$form_state) {
if ($node->type == 'carrousel_item') {
if (! isset($form_state['values']['field_summary_image'][LANGUAGE_NONE]['0']['entity']->field_media_summary_image[LANGUAGE_NONE][0]['fid']) ||
@ccamara
ccamara / drush_alias.bash
Last active December 18, 2015 00:29
Drush aliases. Copy of https://github.com/nuvoleweb/drush_alias #drush #drupal #alias
# Drush-Bash tricks 0.1
# Copyright Nuvole 2010.
# License: GPL 3, see http://www.gnu.org/licenses/gpl.html
# For a quick start: copy this entire file to the end of the .bashrc
# file in your home directory and it will be enabled at your next
# login. See http://nuvole.org/node/26 for more details and options.
# Drupal and Drush aliases.
# To be added at the end of .bashrc.