nerd sectionnerd section

Copy specific files to a ZIP file in Drupal


// Increase the time limit for closing large zip files.
Tags Drupal
Getting files from a folder excluding formats

Just a simple command to get a listing of files from a folder excluding certain file extensions, using regex:

user$: find ./ -type f | grep -vP "\.css$|\.gz$|\.js$|\.sql$|\/settings\..*\.php$|\/settings\.php$|\.mysql$|\.mysql.*\.info$|\/environment$|\.htaccess$"
Tags unix, find command
Dealing with field collections programmatically

In Drupal 7, Field Collections are entities in themselves and they are attached to other entities like nodes, terms or users. So a content type like a node can have a field collection field, with multiple values if you like. There are many cases when this could fit your needs, but in this short article I would just like to highlight the technical details I learned from working with field collections.

Tags field collections
Retrieve a list of module versions

Tags Drupal
Custom shortcut Sublime Text

    { "keys": ["alt+d"], "command": "goto_definition" }

You can add this in Key Bindings - User file.

Tags Sublime Text
Sublime text custom snippet autocomplete

    <!-- Optional: Tab trigger to activate the snippet -->
Tags Sublime Text, JavaScript
Use crush to install Drupal

drush site-install standard --db-url='mysql://root:123@' --account-name=admin --account-pass=admin

Tags Drush, Drupal
Check if a piece of HTML code contains a classname

 * Check if a piece of HTML code contains a classname. 
Tags html, php, regular expressions
Add contextual links on node en term pages

 * Implements hook_node_view_alter().
function TEMPLATE_node_view_alter(&$build) {
Tags Drupal, Contextual links, php
Import Drupal module translation .po files on installation


 * Helper function to (re)import all module's translations.
 * @param $module_name (string)
 *   - Machine name of the module.
Tags Drupal, Localization, Internationalization