Detect URL Route change in ReactJS


To detect a URL change in a single page React application you can use the following code snippet:

 

import { withRouter } from 'react-router-dom';

history.listen((location, action) => {
console.log("on route change");
// Do stuff.
})

Remove a contrib module stylesheet in Drupal 8 theme


You’ll need to add the following to your info.yml, yes, not to libraries.

stylesheets-remove:
– ‘@module_name/path/to/your/file.css’

Drupal7 update hook dependencies


You sometimes find that update hooks run in an unwanted order that affects their behaviour or creates errors and makes your site crash. You can override this and specify the order that you want with the following hook in your .install file.

 function new_module_update_dependencies() {
  // Run new_module update after old_module update.
  $dependencies['new_module'][7001] = array(
    'old_module' => 7000,
  );
 
  return $dependencies;
 }

Install Compass in OSX El Capitan


After getting this error:

▶ sudo gem install compass
ERROR: While executing gem ... (Errno::EPERM)
 Operation not permitted - /usr/bin/sass

It can be fixed with:

▶ brew install ruby

▶ sudo gem install -n /usr/local/bin compass

Install MySQL in OSX El Capitan with Brew


brew doctor

brew update

brew install mysql

unset TMPDIR

mysqld -initialize --verbose --user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

(only use this last one for El Capitan)

mysql.server start

brew services start mysql

Successfully executed thanks to http://stackoverflow.com/questions/34345726/brew-install-mysql-on-mac-os-el-capitan

Drupal 8 is admin path


To check the path of the current page:

$is_admin = \Drupal::service('router.admin_context')->isAdminRoute();

to check an arbitrary path, you need to create a Request object and obtain its matching Route:

use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;

$path = '/node/1';
$request = Request::create($path);

$route_match = \Drupal::service('router.no_access_checks')->matchRequest($request);
$route = $route_match[RouteObjectInterface::ROUTE_OBJECT];
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);

 

via: https://api.drupal.org/comment/60024#comment-60024

Install Node.js & Grunt in Ubuntu 14.04


First you need to add this for add-apt-repository command to work:

$ apt-get install software-properties-common

If not you’ll get this error:

$ sudo: add-apt-repository: command not found

Install Node

$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs

Install Grunt

$ sudo npm install -g grunt-cli
 

Move up metatag in Drupal 7


/**  
* Implements hook_html_head_alter().  
* moving og:title up in head element list  
*/ 
function mymodule_html_head_alter(&$head_elements) {  
  foreach ($head_elements as $key => $element) { 
    if($key == 'metatag_og:title') { 
      $head_elements[$key]['#weight'] = -999; 
    } 
  } 
}