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

Using Rules to publish/unpublish based on a Date field in Drupal

At /admin/config/workflow/rules/components/add

Create a “Action set”:
Name = Unpublish Content
Variables:
Data type = Node
Label = Node
Machine name = node
-Continue-

Actions:
  Node > Unpublish content
  Data selector = node
  -Save-

At /admin/config/workflow/rules
Create a “rule”:
Name = Unpublish Rule
React on event = Node > After saving new content
Restrict by type = your content-type
-Save-

Conditions:
  Content is published
  Data selector = node
  -Save-

Actions:
  Schedule component evaluation
  Component Value = Unpublish Content
  Scheduled evaluation date data selector = node:field-your-node-date-field
  Identifier value = Unpublish content ID [node:nid] ([node:title]).
  Node Data selector = node
  -Save-


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

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

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.

Adding Javascript to your Drupal 7 Module

It starts with adding the following line to your modules .info file (rename MYMODULE to your module name or the name you want to give to your javascript file):


scripts[] = MYMODULE.js

The next step is to create the MYMODULE.js file. The general template of the javascript file looks like:

(function ($) {
  Drupal.behaviors.MYMODULE = {
    attach: function (context, settings) {
      // Your Javascript code goes here
 
    }
  };
}(jQuery));

You can pass variables from your PHP to your Javascript file by adding the following code somewhere in your module.

drupal_add_js(array(‘MYMODULE’ => array(‘tax_rate’ => ‘0.06’)), ‘setting’);
You can now access this variable in your JavaScript:

(function ($) {
  Drupal.behaviors.MYMODULE = {
    attach: function (context, settings) {
      // You can access the variable by using Drupal.settings.MYMODULE.tax_rate
      alert(Drupal.settings.MYMODULE.tax_rate);
 
    }
  };
}(jQuery));

create a custom rule action in drupal

<?php
/**
 * Implements hook_rules_action_info().
 */
function mysite_rules_action_info() {
  return array(
    'mysite_action_foo' => array(
      'label' => t('Klaatu Barata Necktie'),
      'group' => t('Silly Rules Examples'),
    ),
  );
}

/**
 * Rule action foo.
 */
function mysite_action_foo() {
  drupal_set_message("I'm a foo for you!");
}
?>