Enable Clean Url in Drupal 8 Ubuntu

Enable mod_rewrite for Apache

a2enmod rewrite

Now edit the 000-default.conf located at /etc/apache2/sites-available/

Sudo gedit /etc/apache2/sites-available/000-default.conf

Add the below mentioned lines just under DocumentRoot /var/www/html

    DocumentRoot /var/www/html
    <Directory /var/www/html>
        AllowOverride All
        Order Allow,Deny
        Allow from all
    </Directory>

This will add AllowOverride within the default website configuration

Make sure .htaccess is in the default web directory!

ls /var/www/html/.htaccess

Create a vocabularies through Entity Api Drupal

To create a vocabulary named cuisine we would use the following code

$data = array(
'name' => 'Cuisine',
'machine_name' => 'cuisine',
'description' => 'Contains terms representing different cuisines.',
);
$entity = entity_create('taxonomy_vocabulary', $data);
$wrapper = entity_metadata_wrapper('taxonomy_vocabulary', $entity);
$wrapper->save();

Adding Conditional Stylesheets for Internet Explorer in Drupal

There are two ways of doing this – you can either use drupal_add_css() with the optional browser type parameter, or go the easier route and use the Conditional Styles module which allows you to add CSS files via your themes info file. First lets use drupal_add_css() with the browser type. You should use this in themename_preprocess_html() (which goes in your themes template.php file) such as this

<?php
function my_groovy_theme_preprocess_html(&$vars) {
drupal_add_css(drupal_get_path('theme''my_groovy_theme') . '/lte-ie-8.css', array(
'group' => CSS_THEME,
'browsers' => array(
'IE' => 'lte IE 8',
'!IE' => FALSE
),
'preprocess' => FALSE
));
}
?>

This code is targeting IE8 or less

There is a much easier way to declare conditional stylesheets in Drupal – use the Conditional Styles module. This module allows you to declare conditional CSS in your themes info file, just as easily as the very first examples in this article. Just install the module and you can do stuff like this in your themes info file:

stylesheets-conditional[lte IE 8][all][] = lte-ie-8.css

I hope this helps you get started with Drupal theming a bit easier

Redis and Predis configuration for Drupal 7

Install redis module (http://drupal.org/project/redis) and put https://github.com/nrk/predis into ‘sites/all/libraries’ and put these settings into settings.php file

 

define('PREDIS_BASE_PATH', DRUPAL_ROOT . '/sites/all/libraries/predis-0.8/lib/');

$conf['redis_client_interface']  = 'Predis';
$conf['cache_backends'][] = 'sites/all/modules/contrib/redis/redis.autoload.inc';
$conf['cache_class_cache'] = 'Redis_Cache';
$conf['cache_class_cache_form'] = 'Redis_Cache';
$conf['cache_class_cache_views'] = 'Redis_Cache';
$conf['cache_class_cache_page'] = 'Redis_Cache';
$conf['cache_class_cache_menu'] = 'Redis_Cache';
$conf['cache_class_cache_path'] = 'Redis_Cache';
$conf['cache_class_cache_entity_node'] = 'Redis_Cache';
$conf['cache_class_cache_entity_taxonomy_term'] = 'Redis_Cache';
$conf['cache_class_cache_entity_taxonomy_vocabulary'] = 'Redis_Cache';
$conf['cache_class_cache_entity_file'] = 'Redis_Cache';
$conf['cache_class_cache_entity_user'] = 'Redis_Cache';
$conf['cache_class_cache_filter'] = 'Redis_Cache';
$conf['cache_class_cache_admin_menu'] = 'Redis_Cache';
$conf['cache_class_cache_bootstrap'] = 'Redis_Cache';
$conf['lock_inc'] = 'sites/all/modules/contrib/redis/redis.lock.inc';
$conf['redis_client_base'] = 1;
$conf['cache_class_cache_field'] = 'Redis_Cache';

Scale and crop image programmatically in Drupal 7

// Load image file entity.
$file = file_load($fid);

// Load image by uri.
$image = image_load($file->uri);

// Use Drupal's scale and crop function to do the work for you.
image_scale_and_crop($image, $scale['width'], $scale['height']);

// Save image to file, you don't need to save the file entity.
image_save($image);