Skip to main content

Drupal 8 is highly secure, scalable, modular and, most notably, feature-rich and built for high-performance. Drupal’s advantages for running enterprise web sites are well established by such companies as FedEx, The Economist, and The White House. Drupal 8 has 200+ features to integrate in your own site for free.  

Drupal 8 is a great example of continuous quality improvement, with its foundations in the Symfony2 framework. Everything in D8 has been standardized in such a way that maintenance is a lot easier and time-effective.

Install the contrib migrate modules in D8

While migrating a Drupal 8 site, you must install the contributed modules to be configured and run your Drupal migration service. Using your favorite build method, add the following modules to your project which are available in your Drupal 8 core:     

Migrate Plus

Migrate Tools

Migrate Upgrade

After enabling the above mentioned modules we need to visit the /upgrade page. When you do so you will view this screen:

Start_upgradeWe need to click on continue and proceed to configure the migration source (Check the screenshot below). We need to enter the database of the Drupal 7 site and its database credentials as we need to provide the path of your Drupal 7 site's files and press ‘Review Upgrade.’ 

Continue_upgrade

Next_step_in_upgrade

If the provided database credentials are correct, then it show the upgrade review page with the available and missing analysis with list of modules available on the site as shown below:

Next_step_is_here

It will show missing upgrade paths as shown above. You cannot do anything directly on this page to fix these missing migrations. Develop the implementations that are missed while other modules may be excluded on the deployed website.

Next_step_mig

Next_step_mig_1

If you press the ‘perform upgrade’ button, the process will start, depending on the size and types of content/configuration on the source site, the upgrade may take a very long time. It will take long for the user accounts to be imported due to password encryption.

All the feedback and errors are made in the process and while new messages will be displayed on the top, while old messages can be found at the bottom as shown in the image below: 

Next_step_in_solo

However, all of these messages are logged and can be viewed later. Once the upgrade process is finished, you are directed to the site's front page with messages summarizing the results:

After upgrading all the content types, content, taxonomy, static blocks, users are imported from Drupal 7 site to Drupal 8 successfully.

tags_migrate

Migrate_content

 

By using this amazing module all the content types were just re-created by D8 using their structures from D7, at the click of a button!

Content & Content Types 

Content was successfully migrated using the migration tools and techniques. During migration content types were created automatically on D8. All nodes were migrated without leaving out any. Anyone else can replicate most of the field and content type display configuration on the Drupal 8 website.

Block and Site Configuration

I’ve been most surprised with this part. Blocks, Block Configuration, Content type Configuration (Comments etc.), Site-wide configuration (Image Styles) were migrated from the source D7 site to D8 without any effect. 

Taxonomy

Taxonomy is inspiring. There was only one vocabulary. It was replicated on D8 and all terms were auto-migrated.

Images

The Image field was created on the D8 content type automatically by Drupal. The files were fetched and copied from the source site into the D8 sites/default/files folder. An entry was created for each file in the D8 site files table and these files can be managed from “admin/content/files” on the D8 site.

Clean URLs / Aliases 

All the path aliases were migrated from D7 to D8. 

With the help of ‘Migrate’ contributed module, the process of moving a Drupal 7 site to Drupal 8 with regard to content, content types, blocks, taxonomy, users is a lot less painful than I would have anticipated.

Whether you want to upgrade from Drupal 7 to Drupal 8 or altogether migrating from a legacy system to Drupal 8, Anubavam assists enterprises in making a seamless transition to a new CMS. Anubavam's Drupal 8 migration experts can make that happen quickly leveraging the features and functions of Drupal 8 it comes with. In addition to Drupal 8 migrations and upgrades, Anubavam offers a full suite of Drupal development services including design, development, strategy, integration, support and maintenance. 

What is Twig?

Twig is a faster, and more secure template system than PHP. Twig is brought by a wider PHP world. Twig was built  by SensioLabs, the creator of Symfony2 framework. Drupal 8 is using Symfony2 to overhaul its codebase. Twig was the right choice to use for Drupal themes.

Using Twig in Drupal

Twig is the default templating engine in Drupal 8.

One of the results of this change is that all of the theme_* functions and PHPTemplate based *.tpl.php files have been replaced in by *.html.twig template files.

Comparison of PHP template & Twig theming

1. Docblock

PHP Template

<?php 
/** 
 * @file
 * File description
 */
?>

Twig

{# 
/** 
 * @file
 * File description
 */
#}  

File Names

PHP Template file : node--article.tpl.php
Twig file : node--article.html.twig
PHP Template function : page.tpl.php
Twig file : page.html.twig

Variables

You can use a dot (.) to access attributes of a variable (methods or properties of a PHP object, or items of a PHP array), or the so-called "subscript" syntax ([]):

{{ user.name }}
{{ user['name'] }}

Printing a variable

PHP Template

<div class="content"><?php print $user; ?></div>

Twig

<div class="content">{{ user }}</div>

Printing a hash key item

PHP Template

<?php print $user['#item']['alt']; ?>

Twig

{{ user['#item'].alt }}

Assigning a variable

PHP Template

<?php $new_var = $content->comments; ?>

Twig

{% set new_var = content.comments %}

Assigning an array

PHP Template

<?php $arguments = array('!author' => $author, '!date' => $created); ?>

Twig

{% set arguments = {'!author': author, '!date': created} %}

Setting Variables

You can assign values to variables inside code blocks.

{% set user = 'ram' %}
{% set num = [1, 2] %}
{% set ral = {'foo': 'bar'} %}

Conditionals

PHPTemplate

<?php if ($content->comments): endif; ?>

Twig

{% if content.comments %} {% endif %}

PHPTemplate

<?php if (!empty($content->comments)): endif; ?>

Twig

{% if content.comments is not empty %} {% endif %}

PHPTemplate

<?php if (isset($content->comments)): endif; ?>

Twig

{% if content.comments is defined %} {% endif %}

PHPTemplate

<?php if ($count > 0): endif; ?>

Twig

{% if count > 0 %} {% endif %}

Filters

Check_plain:


PHP Template

<?php print check_plain($name); ?>

Twig

{{ name|striptags }}

Translate
 

PHP Template

<?php print t('Navigate'); ?>

Twig

{{ 'Navigate'|t }}

Implode a list

PHP Template

<?php echo implode(', ', $regions); ?>

Original Twig:

{{ regions | join(', ') }}

Drupal 8 Twig:

{{ regions }}

How to enable debugging?

  1. Locate your site's services.yml file, likely located in sites/default/services.yml
  2. Edit the services.yml file and enable one or more of the debugging options defined below.

Parameters:

  twig.config:
    debug: true

Dump

The dump function dumps information about a template variable. This is mostly useful to debug a template that does not behave as expected by introspecting its variables:

{{ dump(user) }}


In an HTML context, wrap the output with a pre tag to make it easier to read:
 

{{ dump(user) }}

Empty

Determine whether a variable is empty:

{# evaluates to true if the user variable is null, false, an empty array, or the empty string #}
 

{% if user is empty %}
    ...
{% endif %}

Advantage of using Twig

Concise: The PHP language is verbose and becomes ridiculously verbose when it comes to output escaping:

<?php echo $variable ?>
<?php echo htmlspecialchars($variable, ENT_QUOTES, 'UTF-8') ?>
{{ variable }}
{{ variable|escape }}
{{ variable|e }}         {# shortcut to escape a variable #}

Template oriented syntax

Twig has shortcuts for common patterns, like having a default text displayed when you iterate over an empty array:

{% for region in regions %}
    * {{ region.name }}
{% else %}
    No regions have been found.
{% endfor %}

Full featured

Twig supports everything you need to build powerful templates with ease such as multiple inheritance, blocks, automatic output-escaping, and much more:
 

{% extends "sample.html" %}
{% block content %}
    Content of the page...
{% endblock %}

Functions

Functions can be called to generate content. Functions are called by their name followed by parentheses (()) and may have arguments.

For instance, the range function returns a list containing an arithmetic progression of integers:
 

{% for i in range(0, 3) %}
    {{ i }},
{% endfor %}

Twig: Fast Template

Using Twig will accelerate the performance in Drupal 8. In order to achieve the best speed possible and save time during Drupal development, Twig compiles templates down to plain optimized PHP code.

The overhead compared to regular PHP code was reduced to the very minimum.

A control structure refers to all those things that control the flow of a program - conditionals (i.e. if/elseif/else), for-loops, as well as things like blocks. Control structures appear inside {% ... %} blocks.

For example, to display a list of users provided in a variable called users, use the following tag:

Example

<h1>List</h1>
<ul>
    {% for region in regions %}
        <li>{{ region.name|e }}</li>
    {% endfor %}
</ul>

Example

The if tag can be used to test an expression:

{% if regions|length > 0 %}
    <ul>
        {% for region in regions %}
            <li>{{ region.name|e }}</li>
        {% endfor %}
    </ul>
{% endif %}

Comments

To comment-out part of a line in a template, use the comment syntax {# ... #}. This is useful for debugging or to add information for other template designers or yourself:

{# note: disabled template because we no longer use this
    {% for region in regions %}
        ...
    {% endfor %}
#}

 

Subscribe to Drupal 7 to Drupal 8 Migration
 

start with anubavam today

You have an idea we have engineers to convert your ideas into reality

Request Quote