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

Routing system in Drupal 8

This routing system replaces the routing parts of hook_menu() in Drupal 7. The parts of hook_menu() that were for creating menu entries, tabs, actions and contextual links are taken over by other subsystems.

Overview

route is a path which is defined for Drupal to return some sort of content on. For example, the default front page, ‘/node’ is a route. When Drupal receives a request, it tries to match the requested path to a route it knows about. If the route is found, then the route’s definition is used to return content. Otherwise, Drupal returns a 404.

Routes and controllers

Drupal’s routing system works with the Symfony HTTP Kernel (that you need to know very little about to do basic route operations). This is how the components relate to each other:

 

 

 

 

 

Drupal8Routing

 

The routing system is responsible for matching paths to controllers, and you define those relations in routes. You can pass on additional information to your controllers in the route and access checking is integrated as well.

5 key features to be excited about in Drupal 8

1. Manage your site’s content…from your phone. 
Anyone that’s ever administered a website knows that it’s best done while using a desktop or laptop. Much of the backend functionality simply doesn’t work, or doesn’t support mobile platforms. The Drupal 8 Mobile Initiative is a group effort to make Drupal 8 a great platform for tablets, smartphones and other mobile devices. Not only will administration go mobile but themes that are available for Drupal 8, will be responsive. This means a better experience for not only administrators, but also mobile visitors to your site.

2. Take your website around the world.
Drupal 7 supports multi-lingual functionality, but not at the level that Drupal 8 will. Imagine translating your site’s content to any one of the 110 different support languages. You’ll be able to not only translate a page’s content for a specific language, but also build views and determine what blocks should appear for that language. Translation updates will also be pushed to the site automatically to make sure your site has the latest dictionary.

3. HTML5 takes the stage. 
HTML5 is a big improvement over the current XHTML that Drupal 7 uses. HTML5 represents a giant step forward in how content is structured and presented on the web. As Dries Buytaert explains, “simply put, it (HTML 5) can provide a much better user experience on both desktop and mobile devices, and could lead to a convergence between native applications and the mobile web.”

4. Change the parameters for your views without a developer.
Views are a set of parameters which determine what content is shown on a page, what field
should be shown, in what order etc. In Drupal 7, the Views module is separate from Drupal Core and has a dependency on the CT Tools Suite. The VDC initiative has built Views into Drupal 8 core so it is available with a fresh install. This means better integration. Drupal 8 also promises to make the application of Views much easier, meaning site administrators can take control rather than relying on a more technical development team.

5. Less modules for faster page loads and reduced server load. 
Each time a page loads on a Drupal 7 site, all of the enabled modules are loaded as well
while Drupal determines which ones implement a required “hook”. Every module may not be needed for each page, and this can lead to longer load time while the user peruses the site. As part of the overall transition to the Symfony framework, Drupal 8 will load only the modules which a page needs, and not more. This will mean faster page loads for your visitors, as well as a likely decrease in the amount of run time memory required for smooth performance.

These are just a few of the many changes which are coming with Drupal 8. Lastly, for those of you who are on Drupal 6 or 7 now, have no fear; Drupal 8 will support content import tools to make your migration much more smooth.

– See more at: http://www.acquia.com/blog/5-key-features-be-excited-about-drupal-8#sthash.MJcY2eqn.dpuf

Caching in Drupal

I’m talking about the core Drupal caching: page cache and block cache which are available in Drupal 7 core. Drupal 6 is similar but works a but differently because page caching was simplified for Drupal 7 (e.g. aggresive mode is now a available as a settings.php var) and the entire system also has become pluggable.

Page caching:

  • If enables, page caching will only be used for anonymous users.
  • If you enable page caching, the entire HTML of each page will be stored in the database. This significantly reduces the amount of queries needed.
  • This automatically means that blocks will also get cached, disregarded their own cache settings.
  • If Varnish is configured, this will also enable varnish caching
  • The page cache max-age will be used (see below) for each page.
  • You can check the “X-Drupal-Cache” HTTP header to check if this cache is HIT.

Block caching:

  • If you enable block caching, without enabling page caching, the block cache settings will be used (for anonymous and authenticated).
  • The defaults for most blocks is “don’t cache” because that is the default for blocks who don’t have their cache settings specifically declared.
  • You can use block_cache_alter module to set this for each block.
  • When it’s block created by Views, you can set the cache settings for a block in Views.

Minimum cache lifetime:

  • This is the amount of time before the page cache is cleared.
  • Page caches are cleared on each cron run (system_cron).
  • Be warned: incorrect settings of your cron and this setting might kill your website performance. See also this issue.

Expiration of cached pages:

  • This only applies for external caching mechanisms, for example your browser cache or Varnish.
  • It sets the Cache-Control max-age value in the HTTP-HEADERS.
  • This setting only takes effect when page caching is turned on.