My git commands cheatsheet

Basic commands

Configure the author name and email address to be used with commits
      
git config --global user.name "Roland dela Pena"
git config --global user.email [email protected]
      
    
Initialize a new local repository
      
git init
      
    
Check out a local repository
      
git clone /path
      
    
Check out a remote repository
Tags

Using Google Contacts API as server to server PHP application

You've got a website for your business and most of your new customers are reaching you via your "Contact us" form page. You're probably manually adding your customers' phone number, email, their preferred product, etc. in your Google Contacts. Would it be nice if your "Contact us" form page has the ability to save a visitor's contact and other details to the database of your account's Google Contacts app automatically? With this kind of application, server to server authentication is needed.

Override a CKEditor notification message

There are some applications that needs changing the default notification message of a CKEditor plugin. Like this case, I have application that needs to check the size of a file being uploaded against the maximum file size limit allowed on a Drupal site and the upload should abort if it exceeds. Using this upload.abort(); method will display "Upload aborted by the user." notification message which obviously not applicable to the situation. The following code snippet will override the notification generated by uploadwidget plugin:

Adding external javascript library available to all pages with query string value came from PHP in Drupal 8

In Drupal 7, adding external javascript library available to all pages with query string value came either from PHP computed value or from database this can be done by:

  
/**
 * Implements hook_init()
 */
function mymodule_init() {
  drupal_add_js('//maps.googleapis.com/maps/api/js?key=' . variable_get('mymodule_google_map_api_key', NULL), 'external');
}
  

For Drupal 8 this is possible by:

Installing geoip2 required library for Smart IP's data source MaxMind GeoIP2 binary database

The MaxMind GeoIP2 binary database is a custom binary format and there are two available APIs that read this binary database: MaxMind DB Reader PHP API which includes an optional C extension that you may install to improve binary database lookup performance and the default is GeoIP2 PHP API. We will discuss how to install these two APIs in your system.

Passing data from PHP to javascript variable available to all pages in Drupal 8

Most of us pass data from PHP to javascript variable available to all pages in Drupal 7 is by:

  
/**
 * Implements hook_init()
 */
function mymodule_init() {
  $computed_data = mymodule_get_data();
  drupal_add_js(array('mymodule_computed_data' => $computed_data), 'setting');
}
  

We can access this data in javascript by:

Setup Drupal 8 module using Composer

Drupal uses an externally-maintained repository the https://packagist.drupal-composer.org but this repo is scheduled to be deprecated in January 2017 by then we will be using https://packages.drupal.org/8 repo URL.

It is assumed that composer is already installed in your system. Make sure your composer version is 1.0.0 or higher, to check execute:

  
composer -V
  

If it is lower than version 1.0.0, update it by:

  
composer self-update
  

Change directory to your Drupal root path.