Skip to content

Instantly share code, notes, and snippets.

View cesarmiquel's full-sized avatar

Cesar Miquel cesarmiquel

View GitHub Profile
@cesarmiquel
cesarmiquel / module.info
Created January 30, 2014 15:05
A stub Drupal .info file. Complete options here: https://drupal.org/node/542202
name = Really Neat Widget
description = Provides a really neat widget for your site's sidebar.
core = 7.x
package = Views
dependencies[] = views
dependencies[] = panels
files[] = tests/example.test
configure = admin/config/content/example
@cesarmiquel
cesarmiquel / module.install.php
Last active August 29, 2015 13:55
Sample .install file which enables/disables modules, features, etc.
<?php
/**
* Update site to ...
*
* First comment is used when displaying updates to perform. Implementation of
* hook_update_N().
*/
function xxxx_update_700X() {
@cesarmiquel
cesarmiquel / module.js
Last active August 29, 2015 13:57
This is a basic pattern for an extensible JavaScript module. This example is based off: http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html where you can find several more snippets.
var UTIL = (function (my, $) {
// private variables
var privateVariable = 1;
// private methods
function privateMethod() {
// ...
}
@cesarmiquel
cesarmiquel / solr-test-query.php
Created May 25, 2014 04:41
Call Apache Solr usings the apachesolr Drupal module and parse the response.
<?php
// -------------------------------------------------------------------------
//
// Taken from:
// http://worldofdrupal.blogspot.com.ar/2014/01/drupal-7-apache-solr-custom-query.html
//
// -------------------------------------------------------------------------
// Search parameters
@cesarmiquel
cesarmiquel / row-count-2.sql
Last active December 6, 2019 17:57
Show all tables (and their row count) for tables with more than 10000 rows for MySQL. Taken from: http://stackoverflow.com/questions/286039/get-record-counts-for-all-tables-in-mysql-database. The second version from here: https://www.lullabot.com/articles/importing-huge-databases-faster
SELECT table_name, table_rows, data_length, index_length,
round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "drupal"
ORDER BY round(((data_length + index_length) / 1024 / 1024),2) DESC
LIMIT 0,30;
@cesarmiquel
cesarmiquel / add_nodes_to_nodequeue.php
Last active August 29, 2015 14:03
Add nodes to a Drupal nodequeue programatically
<?php
// List of nids of the nodes to add
$nids = array(6474, 6475);
// Get queue and subqueue information
$queue_machine_name = 'queuename';
$queue = nodequeue_load_queue_by_name( $queue_machine_name );
// Get subqueues
@cesarmiquel
cesarmiquel / import-translations.php
Last active August 29, 2015 14:04
Import translations into Drupal from a .po file
<?php
//
// This code uses the _locale_import_po() function call from includes/locale.inc. This
// is a private function so use with care. Here's the function:
// https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_po/7
//
// example usage:
$translation_filepath = drupal_get_path('module', '<module>') . '/translations-es.po';
@cesarmiquel
cesarmiquel / drush-create-site.md
Last active August 29, 2015 14:12
Create a Drupal site using drush and an installation profile

How to generate a new Drupal site via drush

  1. Edit your settings.php file and add a database connection setting db, user and pass. For example append the following to your empy settings.php:

      $databases['default']['default'] = array(
        'driver' => 'mysql',
        'database' => '<db>',
        'username' => '<user>',
        'password' => '<pass>',
    

'host' => 'localhost',

@cesarmiquel
cesarmiquel / entity-metdata-wrapper-examples.md
Last active September 15, 2017 20:16
Entity Metadata Wrapper API examples

Entidades en Drupal 7

En Drupal 7 se 'mergearon' los usuarios, nodos y taxonomías en una entidad. Las entidades pueden tener campos adicionales a los que ya tenían. Adicionalmente, cada campo puede estar traducido y, por lo tanto, tener distintos valores dependiendo del idioma. En general es mejor acceder a los valores de los campos via APIs en lugar de acceder directamente al campo. Listamos algunas de las funciones más útiles y recomendadas para utilizar:

  • entity_load() - permite cargar una entidad. Los tipos de las entidades pueden ser 'node', 'user', etc. Ver: entity_load()
  • field_get_items() - devuelve, dada una entidad y el nombre de un campo la lista de valores que contiene el campo. Ver: field_get_values()
  • field_view_value() - devuelve un array rendereable con el valor. Para obtener HTML hacer drupal_rend
@cesarmiquel
cesarmiquel / kickstart-drupal.sh
Last active August 29, 2015 14:25
Configure a new Drupal site
#!/bin/bash
# ---------------------------------------------------------------------------------------
# Configuration options
# ---------------------------------------------------------------------------------------
DEFAULT_ADMIN_THEME='adminimal' # Other common options: seven - adaptivetheme_admin
DEFAULT_THEME='bartik' # Other common options: omega - zen - bartik
ADMIN_PASSWORD='<strong-password>'