nerd sectionnerd section

Copy specific files to a ZIP file in Drupal

<?php

// Increase the time limit for closing large zip files.
drupal_set_time_limit(300);
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

<?php
$dir 
'public://directory';
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

  <snippet>
    <content><![CDATA[console.log()]]></content>
    <!-- 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@127.0.0.1:3306/dbname' --account-name=admin --account-pass=admin --account-mail=info@your-site.com

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

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


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

<?php

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

Pages