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; 
    } 
  } 
}

Drupal Update Hook Dependencies


Sometimes, when developing an update hook, you might want it to run after or before a different module’s update hook. this is the way to do it:

Place the following code into your module’s mymodule.install file.

Where 7001 and 7140 are the hook update number.

/**
 * Implementation of hook_update_dependencies().
*/
function mymodule_update_dependencies() {
  // Make sure that mymodule runs after other_module
  $dependencies['mymodule'][7001] = 
 'other_module' => 7140,
);
  return $dependencies;
}

Drupal 7 override image styles programmatically


/**
 * Implements hook_image_styles_alter().
 */
function mymodule_image_styles_alter(&$styles) {
  // Check that we only affect a default style.
  if (isset($styles['thumbnail_large']) && isset($styles['thumbnail_large']['storage'])) {

    if ($styles['thumbnail_large']['storage'] == IMAGE_STORAGE_DEFAULT) {

      $styles['thumbnail_large'] = array(
        'name' => 'thumbnail_large',
        'effects' => array(
          1 => array(
            'label' => 'Javascript crop',
            'help' => 'Create a crop with a javascript toolbox.',
            'effect callback' => 'imagecrop_effect',
            'form callback' => 'imagecrop_effect_form',
            'summary theme' => 'imagecrop_effect_summary',
            'module' => 'imagecrop',
            'name' => 'imagecrop_javascript',
            'data' => array(
              'width' => '620',
              'height' => '350',
              'xoffset' => 'center',
              'yoffset' => 'center',
              'resizable' => 1,
              'downscaling' => 1,
              'aspect_ratio' => 'CROP',
              'disable_if_no_data' => 1,
            ),
            'weight' => '1',
          ),
          2 => array(
            'label' => 'Scale and crop',
            'help' => 'Scale and crop will maintain the aspect-ratio of the original image, then crop the larger dimension. This is most useful for creating perfectly square thumbnails without stretching the image.',
            'effect callback' => 'image_scale_and_crop_effect',
            'dimensions callback' => 'image_resize_dimensions',
            'form callback' => 'image_resize_form',
            'summary theme' => 'image_resize_summary',
            'module' => 'image',
            'name' => 'image_scale_and_crop',
            'data' => array(
              'width' => '620',
              'height' => '350',
            ),
            'weight' => '2',
          ),
        ),
        'label' => 'thumbnail_large',
      );
    }
  }
}