Installing PhpStorm IDE for Drupal Development on Windows

Hey all, I’m a Drupal enthusiast, an engineer in the making from Goa College of Engineering with interests in web technologies and internet of things and currently doing internship in Valuebound. Stay tuned for my upcoming blogs.

In this blog, I would be installing PhpStorm IDE for Windows and configure it to work with Drupal. This post is for the benefit of all those who are new to Drupal and the learnings have been inspired from the book Drupal 8 Development: Beginner's Guide. There are many other alternatives to PhpStorm such as Eclipse, NetBeans, Komodo IDE etc. but of late PhpStorm has emerged as the preferred choice of the developers. There are quite a few advantages of using PhpStorm over other IDE’s. It’s Drupal friendly, and drupal development plugin comes pre-installed with PhpStorm. Although it’s a paid software you might qualify for free license if you are a student or working on open source projects.

Developing in Drupal involves a lot of testing and debugging at various stages. Using an IDE for the development work helps this task and is the most  preferred approach adopted, while developing in Drupal.

Before the PhpStorm installation, it is assumed that Drupal has been previously installed on your system. If not, it can be installed via XAMPP over the localhost or via Acquia Dev Desktop. Over here, we’ll be linking PhpStorm to our existing Drupal installation over XAMPP server.

So let’s dive in and start the process.

STEP 1:- Downloading PhpStorm IDE

PhpStorm is a product of JetBrains (previously IntelliJ).

  1. Visit the link www.jetbrains.com/phpstorm/download/ to get a list of all the versions of PhpStorm for different OS’s. As mentioned earlier, we are going to install PhpStorm for Windows, so go ahead and download the Windows compatible version of PhpStorm.

phpstorm_1

 

STEP 2:- Installing PhpStorm IDE

Once the download is complete, open up the file to start  the installation process. Go ahead and click next.

phpstorm_2

  • A. On the next screen, select the appropriate option for your system to create a desktop shortcut and choose the associations that you want PhpStorm to have. Selecting a particular association would enable the IDE to recognize and highlight the syntax of that option while using  that particular line of code in the IDE.

phpstorm_3

To keep things simple, let us select all the available associations. That will also help us in the long run. These associations can be created post the installation too, so you don’t have to worry much about them. 

  • B. Click Next, for a couple of more steps involved in the installation and finally, you should be having a window saying ‘Phpstorm has been installed on your computer’. Go ahead and run PhpStorm.

phpstorm_4

 

Congratulations!! You have successfully installed PhpStorm on your system.

STEP 3:- Linking PhpStorm to the existing Drupal installation

So now that PhpStorm has been installed, let us link our existing Drupal installation to it.

  • A. Run your newly installed PhpStorm IDE and you should see a screen similar to what is present below. Select the option ‘Create New Project’ and point to the location of your existing Drupal installation on the system. As mentioned, I’ve my Drupal installed over the XAMPP server. So I’ll be pointing out the project location to the location of existing Drupal installation over XAMPP. You can go ahead and point the location to where you have installed your Drupal.

phpstorm_5

 

  • B. On the next screen, you should see that PhpStorm recognizes that the directory is not empty. Go ahead and Click ‘Yes’ so that PhpStorm creates a project from the existing Drupal installation.

phpstorm_8

After all this is done, your PhpStorm IDE should be ready with all the existing Drupal installation files in the Projects window. Also as soon as the project is imported, the IDE starts indexing the project files on the system. Once this is done, you should see a screen similar to the one below.

phpstorm_10

 

As evident from the screen, PhpStorm has already recognized that the new project is a Drupal module and would ask you to enable Drupal support for the same. This option pops out on the top right corner of the screen.

phpstorm_11

  • C. Go ahead and click ‘Enable’ so that PhpStorm extends the Drupal support for the newly imported Drupal project. Next you would be asked to enable Drupal integration and to select the version of Drupal to extend support to. In my case, I’ve Drupal 8 installed on my XAMPP server so I will select version 8 on the pop up window.

 

phpstorm_12

 

  • D. Next, we will configure PhpStorm to follow the Drupal coding standards. For that - go to setting from file menu > Editor > PHP > Set from > Predefined style > Drupal. Most of the configurations would be handled by this. If not, you would have to configure it manually and cross check all the configurations.

phpstorm_13

 

Congratulations! The installation of PhpStorm and the linking of the existing Drupal project to PhpStorm is complete. You can now go ahead and develop, test or debug your Drupal modules, themes etc. right from your PhpStorm IDE.

You can learn more on Drupal development in our upcoming book co-authored by team at Valuebound.

Create custom Entity Type in Drupal8 for better content management

Entities were introduced from Drupal 7.  I would say in Drupal 8 , entities are essential part takers like node, users, files, images and comments, etc.. Still sometimes you need to create Drupal custom entities according to your requirements. From the experience of working with some of the top Media companies in the world, sometimes we need to create custom Drupal 8 entity types. Example like recently we got the requirement to create the entity for string the analytic data of the Articles. Why  we need to create  the custom drupal entity instead of using nodes  or exiting entities, because the client doesn’t want to show the data in content administration page (‘admin/content’). Still it should be able to manipulate the data and also easy to administrate with views, fields, etc. So finally we architect to create the custom Drupal 8 entity types.

Here in this tutorial, we will go through how to  create custom Entity type in Drupal 8. Entity is fully fieldable and uses most of the new entity concepts available in Drupal 8. We will be creating an entity type let’s say “inventory” and will also see how to create edit and delete

How to create a Drupal 8 Entity Type Programmatically?

So let’s create a module called “Manage Inventory” with the custom entity type ‘inventory’. And the details to create the module is explained in following steps,

Module Setup :

manage_inventory.info.yml

Routing :

In Drupal 8, menu system has been replaced by routing system.

manage_inventory.routing.yml

The route names for actions, defined in the 'link' section of the entity annotation must follow the right pattern.

manage_inventory.links.menu.yml

In addition of routing file, this replaces hook_menu for the module.

manage_inventory.links.action.yml

manage_inventory.links.task.yml

The "View/Edit/Delete" tabs will appear on the entity view page. The "Settings" tab will appear on the entity settings page.

Entity type classes

src/InventoryInterface.php

It’s better to provide an interface to define the public access to an entity. Here we invoked EntityOwnerInterface to get access to additional functionality.

src/Entity/Inventory.php

This file defines the Inventory entity class. The database schema is automatically determined from the definition of the base fields and here we can define the required fields for the content types. As mentioned in the routing section, the routes for the 'links' section must follow the right pattern. It is documented in the annotations section below.

Controllers

Let’s rewind. Until now we have seen routing, links and interface as well as Entity class. Once the entity type is created we need to provide an interface to the user for creating the entity.

Now let’s create form for creating entity.

src/Form/InventoryForm.php

Here we will define Entity form for adding and editing Inventory entity content. We can call this _entity_form defined in routing.

InventoryDeleteForm.php

Confirmation form while deleting the entity.

In above class we have submission handler for deleting any content and also for creating a log for the same.

src/Entity/Controller/InventoryListBuilder.php

Here we will be defining a listing page for the Entity type. In list we will be extending EntityListBuilder class to create list. We will be adding header with desired fields and later constructing row using rowBuilder method. Operation link will be added automatically from the parent class.

 

Field Settings

Till now we have seen,

  • How we can add routing
  • Creating Entity class for defining the entity with the default required field
  • Form for adding, editing content and deleting.

Now we will see how to add more fields from user interface. For that we need to define field settings class. So let’s create InventorySettingsForm.

src/Form/InventorySettingsForm.php

Access control handler

Entity type creation is done. Now we need to create access control handler for the same. With the implementation of EntityAccessControlHandler we will able to restrict the access of the content which we can manage from interface.

src/InventoryAccessControlHandler.php

After this, we need to register this entity type, which we will achieve by enabling the module. Incase you have enabled this module in the middle of this blog before creating Inventory class you will land up with error as  Drupal won’t have created the database table.

To overcome the error you can simply execute drush updatedb --entity-updates.When executing this command, Drupal will inform you that it found a new entity and that there's a pending update. After applying the pending update, you will be able to start using the new entity on your Drupal website!

 

 

Free Drupal Training by Valuebound, Bangalore on Drupal Global Training Days

We, at Valuebound, are excited to announce a hands on ‘Drupal-in-a-day' training session on the 10th of September ‘16, Friday. This is an initiative coordinated by the Drupal Association as a part of the  Global Training Days to introduce new people to the wonderful world of Drupal.

Come and be a part of world wide Drupal community! Make a live website yourself and know how Drupal can help you!

Difficulty Level: Introductory

Proposed Session: 

Get a leap on to the world of Drupal 8 . Learn about the main features and concepts of Drupal with live practice sessions. By the end of this training session you will know about the terminologies associated with Drupal and will be able to understand how Drupal sites are constructed. You will be equipped with the knowledge of how to differentiate and choose modules to get the functionality you want.

Duration: 1 day

Why is this workshop free?

Valuebound has been an active contributor to the Drupal Community and has achieved the second position worldwide through the same. This free event is part of our many more efforts to give back to the community.

Valuebound is solely dedicated in helping organizations and individuals to adopt Drupal in their operations in the most effective manner. We believe in giving result oriented training sessions which will equip you to build the perfect websites you visualize.

Who Should Attend?

  • PHP/Web developers: Give an edge to your career with a little more insight about how things work.
  • Students: Give a boost start to your IT career path as Drupal developer. Drupal is widely used by Fortune 500 companies, governments and startups.
  • Career switchers: Looking for the next opportunity to switch or learn what more  is there for you in Information Technologies? Come explore.
  • Project managers: Do you manage or are you considering Drupal projects? Know what you should know!
  • Decision makers: Evaluating Drupal to build your product on? Know why it’s the perfect fit.
  • Everyone, who is interested in knowing what Drupal is, evaluating or implementing Drupal.

Things you should know:

A little knowledge of what is a Content Management System would be great. Experience in using and creating websites using systems such as Wordpress, Joomla!, or HTML and CSS is a plus but  NOT a mandate. We encourage the newbies and shape up the Ninjas!

This session would present an outline of concepts of Drupal and not an in-depth course. It is awesome for folks  who are looking to get a head start or the ones looking for an edge in their career or profile.

By the end of the training you will be able to:

  • Build and make a basic Drupal site.
  • Select, install and configure modules and themes from Drupal.org
  • Create content and configure content types, create listings of content.
  • Manage user roles and accounts.
  • Manage aliases and URL paths.
  • Create blocks and place them in the layout

Bring along your laptop to make best use of this workshop.

How to register : The event is free but registration is mandatory. RSVP below to register.

RSVP

How to enhance your content authoring by adding custom CKEditor plugin in Drupal 8?

CKEditor is a popular WYSIWYG (What You See Is What You Get). In Drupal default WYSIWYG editor is CKEditor. CKEditor has many of its own plugins.

Recently I got an opportunity to work for some top level media companies like Time Inc and Farm Journal with my Valuebound Teammates. It was a challenging experience , especially on the area of content creation and management work flow.  

We got a requirement where “Content Authors” should be able to upload the images in between  paragraphs of content. When the end user clicks on those images, the image has to be shown as a popup. So we decided to create a CKEditor plugin so that the users who are having  “Content Author” or “Content Editor” roles will be able to upload the image which will show up in a popup when it’s clicked. Because of this requirement, we were fortunate to develop a module called Simple Image Popup and  contribute back to Drupal Community.

Here we are going to see how to create a new plugin for CKEditor in Drupal 8, which inserts image wrapped in anchor tag.

Steps to create CKEditor plugin.

  1. Define and add basic plugin info in hook_ckeditor_plugin_info_alter() in your module file.
    File: my_module.module
     
  2. Define MyPlugin class which defines plugin, extending CKEditorPluginBase and implementing CKEditorPluginConfigurableInterface. In this plugin class we need to define the following methods:
    File: MyPlugin.php
    1. isInternal - Return is this plugin internal or not.
    2. getFile - Return absolute path to plugin.js file.
    3. getLibraries - Return dependency libraries, so those get loaded.
    4. getConfig - Return configuration array.
    5. getButtons - Return button info.
    6. settingsForm - Defines form for plugin settings, where it can be configured in ‘admin/config/content/formats/manage/full_html’. For example, this form shown below is where we can set the max size, width and height of the image, against which image will be validated when uploading an image.CKEditor Plugin setting form.

       

  3. Define client side plugin.js. Basic things we need to implement in plugin.js are:
    File: js/plugins/myplugin/plugin.js
    1. Add the new plugin to CKEditor. In beforeInit method we have to define our plugin command and add UI button which in turn triggers our plugin command on click of UI button as follows,
    2. Define routing for the dialog, which points to Form controller.
      File: my_module.routing.yml
    3. Define plugin dialog form and its form submit handler as we normally do in Drupal 8. In addition, on form submit we need to return ajax response command like below
      File: my_module\Form\EditorImagePopupDialog
      And whenever edit operation happens we need to populate existingValues json object in plugin.js file, so we can get those values in buildForm with the below line of code.

Finally configurations.

  1. Go to ‘admin/config/content/formats’, then click on configure action link for which format this plugin needs to be added.
  2. In configuration form, we can drag and drop newly created plugin button to CKEditor toolbar.
  3. Now, save the configuration form.
     

Hurray…! Now we can use our newly created CKEditor plugin. For more reference, find the contributed module, in which we have created CKEditor plugin for Drupal 8 Simple Image Popup.

How to reduce your development hours by Creating an Installation Profile or Distribution in Drupal 8!

Creating an installation profile in Drupal 8 is quite easy according to my humble opinion. Why? Because of the Configuration Management System in Drupal 8. In Drupal 7 we had lot of amazing contributed Installation profiles like Commerce Kick Start, Open Atrium, aGov, etc. Here we are going to discuss about how to create the installation profile in Drupal 8 and the benefit of using an installation profile in our Drupal Development World. Before that let us find out the answers for the following questions….

  • What is the Usage of installation profile?

  • Why do we need to create installation profile?

  • When do we need to think about architecting an installation profile?

  • How to reduce the development hours by creating an Installation Profile or Distribution in Drupal 8?

Thank God, I was one of the fortunate to work along with my Valuebound team members for some top Media companies like Time Inc and FarmJournal Media. All of these companies have a lot of websites with similar basic features, so it makes sense to create an installation profile with the basic set of features / functionalities. Similarly, developing websites for Universities, each University will be having multiple websites for different departments and branches. By creating an installation profile or distribution for the same, with the basic set of features will ease the development and deliver the Websites on time. Why? Because it reduces more than 30% (minimum) of development time. Thunder is one of the best example of an installation profile / distribution created by the media publishing company Hubert Burda Media.

How to create installation profile in Drupal8?

There are couple of steps involved in it, which is

  1. Selecting the machine name for the installation profile.
  2. Creating the Structure.

Selecting the machine name for the installation profile.

In this step we can decide what should be the machine name for our profile. Suppose our profile name is ‘Example Profile’ and machine name for this will be ‘example_profile’. The machine name can contain only lowercase letter and underscore.

Creating the Structure.

The structure has following files.

  1. Profilename.info.yml
  2. Profilename.profile
  3. Profilename.install
  4. Config folder.
  5. Translation folder(optional).

All the above steps should be inside the ‘/profile/your_profile’ folder under your ‘Drupal root Folder’. Here our profile name is “Example Profile”, So we have to do the action under the following directory.

“Drupal_root_folder/profile/example_profile”

1) Creating the Profilename.info.yml

Here we are creating the ‘example_profile.info.yml’.

In the ‘example_profile.info.yml’, We are having the following terms.

  • name:  This the name of  your profile.
  • type: What type it is whether it is module, theme or profile. Here we having ‘profile’.
  • description: Describe about your profile / distribution.
  • distribution: (Optional) Declare your installation profile as a distribution, This will make the installer auto-select this installation profile. The distribution_name property is used in the installer and other places as a label for the software being installed.
  • dependencies: Required modules.

2) Creating profilename.profile

.profile file is very much like .module on the module. It has all the access like .module has. Here we having ‘example_profile.profile

3) Creating profilename.install

In this file provide Install, update and uninstall functions for the profile.

4) Config folder

Config folder makes the difference from Drupal 7 to Drupal 8. Because of CMI in Drupal 8, it is very easy to add the features or function as config files under ‘config/install’ in your profile root directory. You can import the configuration from an existing site and keep it in in the ‘config/install’ folder. For an example we have created and exported the configuration for a view called “Example View For Example profile”. But we need to carefully follow the couple of steps which are mentioned below,

  • Copy all of the modules and themes listed within core.extension.yml into your profile's info file (using the new info file's format).
  • Delete core.extension.yml, file.settings.yml and update.settings.yml
  • Remove all of the UUIDs from your config files so that they don't conflict with those of new sites. Use phpstorm and  use following regular expression in the ‘Replace option under  Find in View options’. [View >> Find >> Replace]         
    “^uuid: .*\n”

Please check the following image for more clarity.

Installation Profile

Now our installation is ready to use.

The source of our example is: https://github.com/rakeshjames/example_profile

Conclusion:

If you are developing  ‘x’  number of websites having basic features / functionality / requirements which are similar, then it is always good to consider  creating an installation profile and Keep it. So that it will save at least 30% of overall development time. Which means you can use that time more effectively on your development to manifold your productivity.

How to create Form table in Drupal 8

In one of our project we came across a scenario where we need to update/delete the user field values based on the user detail. These can be seen on the users administration page (admin/people) or the content administration page (admin/content), There we will use this form table In these cases changing forms into a table of information helps us to do operations such as delete or edit in the form submit.

In this blog, I will be putting together a table form that looks like the following one

Table form   d8.png

Step 1:

Get the data:

The first thing we need to do is get the data which we will use in our table. This will be entirely dependent on what data it is that you want to show. The table shown above is displaying user info from the database. In this case, am fetching user detail and creating the array

$query = \Drupal::database()->select('users_field_data', 'u');
$query->fields('u', ['uid','name','mail']);
$results = $query->execute()->fetchAll();

As you can see, fetching rows data from the database and putting them in the array format

Step 2:

Build the header:

The next thing we need to do is put together an associative (keyed) array defining the header of the table. The keys here are important as we will be using later in this blog. The table we are building here  has four cells in the header; one for the checkbox column, one for userid,one of username and one for email. However, we can ignore the cell for the checkbox column, as Drupal will take care of this for us later. As such, we can build our header as follows:

$header = [
     'userid' => t('User id'),
     'Username' => t('username'),
     'email' => t('Email'),
   ];

Step 3:

Build the data

Next, we need to build the array that will contain the data of the table. Each element in the array will correspond to one row in the HTML table we are creating. Each element of the array will be given a unique ID.

This will be the value of the checkbox when the form is submitted (if selected). In this case, we want to get the UID of the user, so each row will be keyed with the UID of the user. We then, will key the cells of the table with the keys we used for the header.

// Initialize an empty array
$output = array();
// Next, loop through the $results array
foreach ($results as $result) {
     if ($result->uid != 0 && $result->uid != 1) {
       $output[$result->uid] = [
         'userid' => $result->uid,     // 'userid' was the key used in the header
         'Username' => $result->name, // 'Username' was the key used in the header
         'email' => $result->mail,    // 'email' was the key used in the header
       ];
     }
   }

Step 4:

Form Table

So now we have built a header ($header), and the rows of the table ($options). All that is left is to bring it all together. Drupal 8 has a nice little theme function that we will use for this, theme_tableselect(). theme_tableselect() takes the data, turns it into a table, adds a checkbox to each row, and adds a 'select all' checkbox to the header. Handy! So let’s look at how to tie this all together:

 $form['table'] = [
'#type' => 'tableselect',
'#header' => $header,
'#options' => $output,
'#empty' => t('No users found'),
];

That's it. This is simple table form with the list of user from the database and display in the table form,

In the next blog will discuss about the table form with the pager.

Drupal 8 Why & How to Migrate - Part1

 

As I was working with the migration towards Drupal 8 scenarios, I was pondered with this question of why are we migrating to Drupal 8 and how to go about it. So, I decided to go ahead and share a few case scenarios which will be helpful for you in case you are looking forward to gather info on Drupal 8 migration. This guide will be useful who are looking for a basic idea of Drupal 8 & migrating to the same.

We will look into migration of different entities in the upcoming articles. In this article I will be explaining about term migration.

WHY Migrate?

The migrate module provides a flexible framework for migrating content into Drupal from other sources (e.g., when converting a website from another CMS to Drupal). Out-of-the-box, support for creating core Drupal objects such as nodes, users, files, terms, and comments are also included - it can easily be extended for migrating other types of content. Content is imported and rolled back using a bundled web interface (Migrate UI module) or included Drush commands.

In one of the recent projects, we needed to migrate terms,nodes and author from external sources. For this scenario  we are implementing our own migration script.

HOW to migrate?

For implementing migration script, there are some dependencies for which you need to install all the required modules which are listed below.

Migrate Module (Included in Drupal 8 core)

The migrate module provides a flexible framework for migrating content into Drupal from other sources.

Related: How to migrate your website to Drupal 8

Drupal Console
The new CLI for Drupal. Drupal Console is a tool to generate boilerplate code, interact and debug Drupal. From the ground up, it has been built to utilize the same modern PHP practices which were introduced in Drupal 8.

Migrate Plus
The migrate_plus project contains three modules:

  • migrate_plus - Extends the core migration framework with additional functionalities to tweak incoming source data in migrations, also to code examples for making custom migrations
  • migrate_example - A carefully documented implementation of a custom migration scenario, designed to walk you through the basic concepts of the Drupal 8 migration framework.
  • migrate_example_advanced (still in progress) - Examples of more advanced techniques for Drupal 8 migration. 


Migrate Tools

Drush commands supported include:

  • migrate-status - Lists migrations and their status.
  • migrate-import - Performs import operations.
  • migrate-rollback - Performs rollback operations.
  • migrate-stop - Cleanly stops a running operation.
  • migrate-reset-status - Sets a migration status to Idle if it gets stuck.
  • migrate-messages - Lists any messages associated with a migration import.

To use Drupal with Drush in Drupal 8 it requires a minimum of Drush version 8. Before you get your hands dirty, you can go thru' this article on Custom Drush commands in Drupal 8. This should give you a good understanding about writing custom Drush commands in Drupal 8. It is not exactly like Drupal 7 but similar.

First, connect Drupal with an external database and add this code in settings.php
We are going to instruct migrate source to use this database target and use the key name as “source_migration” which will be  used in every migration file.

Here we go, with our Custom script for creating Taxonomy Term From External Source.

Which will eventually help to organize your site by assigning descriptive terms to each piece of content

Open terminal and enter 

drupal migrate:debug

As our migration resources are not showing yet we have to create a custom module for this. We can do this by the following steps -

  1. Create folder for custom Drupal module in my Drupal site: /modules/custom/migration_fj
  2. Create a new file migration_fj.info.yml with below code
  3. Migration plus module allows you to specify even the migration group. For grouping our migration we need to create a config entity. Create a new file migration_fj.migration_group.fj.yml using code below in the module folder custom/migration_fj/config/install/

    Here we have used our Key “source_migration” for connecting migration script with external database from where we would be fetching the content.

  4. Now let’s move on to defining source class.

    In our project, we needed to import category from a custom application as taxonomy terms in Drupal. In this case, the category didn’t have unique ids, instead, it was just a column having table name as a category with the values in rows.

    To create source class, create a new file.
    custom/migration_fj/src/Plugin/migrate/source/FjTerm.php
     

  5. Now for term migration, we need to create a new config entity.
    custom/migration_fj/config/install/migration_fj.migration.fj_term.yml

Our module is complete and ready for term migration using Drush. Now we can execute it with the migrate_tools

drush migrate-import example_term

Related: Migrating address book using process plugin in Drupal 8

WHAT if you have to roll it back?

For rollback, we can use drush migrate-rollback

I hope now it will be easier to migrate to Drupal 8.

Comment below if you come across any difficulties during the process. Read more of my experiences with Drupal.

Read More Relevant: How to migrate Users from a CSV file in Drupal 8?

Ref:
http://studio.gd/node/5

How to Render a Slideshow using new module imagefield_slideshow


Overview of the Module:

This module is developed specifically to render the slideshow from the image field.
Imagefield Slideshow module will provide a field formatter for image fields, so that multiple images are uploaded to that particular image field and the formatter helps you to render those images a slideshow.

Potentially the administrator would be able to change the rendering settings of the slideshow like transition effects and image size to render.

Works with all entity display formatters like node, user  etc, and also with the views module.

 

How to install the module?

  1. Create a libraries directory on your drupal instance's root folder.

  2. Create a directory within libraries named jquery.cycle.

  3. Download the latest version of the jQuery Cycle plugin (http://jquery.malsup.com/cycle/download.html) place it inside the jquery.cycledirectory. The filename should be: jquery.cycle.all.js

  4. Enable the Imagefield Slideshow module from the modules page.

  5. You should now see a new field formatter for image fields display settings
    Ex: under Manage display section of content types


How to configure the module?

When you visit any image fields display settings, you will be able to find the Imagefield Slideshow formatter, as shown in the image below.
Ex: admin/structure/types/manage/article/display

imagefield_slideshow1.png


You can configure the setting for rendering the slideshow, as shown in the following  image.
1. Select the image style required.
2. Then  select the transition effect to be applied in the slideshow.

imagefield_slideshow2.png



This module is best suited, if you need a unique slideshow on every node of a content type.


If you have new ideas to improve this module further, or want to customize it for your own projects feel free to contact us.
 

Drupal 8 Commerce is on the Way! DrupalCon New Orleans 2016.

A lot of thanks to the commerce guys for contributing the Drupal commerce module to Drupal community, which took drupal to a different level in the CMS world. Its very exciting, Commerce 2.x which is the Drupal 8 version of drupal commerce. As like any other drupal developer / architect, I am also excited about Commerce 2.x

Thank God, I was one of the fortunate ones to attend the Commerce Guys session on DrupalCon New Orleans 2016, the very first session after the release of ‘8.x-2.0-alpha4’  version of drupal commerce. It was an amazing session, which made a lot of things clearer,a lot of unanswered questions were answered by the Commerce guys themselves. Here we are going to discuss about the take away of the Commerce Guys session on DrupalCon New Orleans 2016.
 

No more Commerce Kickstart in Drupal 8, Why?

No more Commerce Kickstart in Drupal 8, because Commerce 2.x is developed as loosely coupled by using a lot of PHP 5.4+ libraries like tax [tax library], addressing [addressing library powered by Google’s dataset], intl [internationalization library powered by CLDR data], zone [zone management library]. Using composer we can create a new site as like commerce kick start in Drupal 7. For that we have to use the following command.

$ composer create-project drupalcommerce/project-base mystore --stability dev

 The above command will download Drupal 8 + Commerce 2.x with all dependencies to the ‘mystore’ folder. Before running the above command please make sure you have installed composer globally on  your system.

How to install Commerce 2.x on existing site?

For Installing Commerce 2.x in existing Drupal8.x site,  we need to do the following steps.

Step 1: Add the Drupal packagist repository which allows Composer to find Commerce and the other Drupal modules. For that run the following command, 

$ composer config repositories.drupal composer https://packagist.drupal-composer.org

 

Step 2: The following command will help us to download the required libraries and modules (Address, Entity, State Machine, Inline Entity Form, Profile).

$ composer require "drupal/commerce 8.2.x-dev"

 

Step 3: Enable the modules “commerce_product commerce_checkout commerce_cart commerce_tax” , Use drush or drupal console

Read more about the commerce documentation on: http://docs.drupalcommerce.org/v2/

The above steps help you to install the commerce 2.x on the existing site. Moreover  that in Drupal 8 commerce 2.x  requires lot of contrib modules developed and contributed by commerce guys themselves. The following ones are the famous ones.

  1. Inline Entity Form
  2. Address
  3. Profile
  4. State Machine

What is new in Commerce 2.x?

  1. Currency Management :  Integrated the Unicode CLDR project. So it is easy to use the currency inside and outside the US.                                                                                     
  2. Price Formatting: Price format  varies from country to country and language to Country.  Like German(Austria) Vs German(Germany)                                                                       
  3. Taxes: Imports the tax rates automatically on country basis depending upon the product like B2B, B2C, digital or physical products.                                                                           
  4. Stores: Multiple stores in same Drupal Commerce Instance, hence there will be majorly two types of use cases, first one is where User can create their own stores based on their own products. Which means multiple cart from multiple stores, from the buyer’s perspective. The Second one being this, that the Company has billing location in multiple countries.                                                                                                                                
  5. Products: Instead of nodes we hare having Product entity itself. On the production creation page using inline entity to create individual product variations. And those variations holds the SKUs and sets of attributes.                                                                  
  6. Product Attributes: In Commerce 2.x product attributes are its own entities, So it is easy to edit, delete, create new attribute from. Suppose you want to add the attributes to the product variation type,  you have to edit the respective production variation type and select the checkbox under the ‘Attributes’. So it is easy to use different form of modes to display fields.                                                                                                                           
  7. Order and Line Item Types: This will provide the option to have separate order types for different types of products like physical and digital products, event registration, training payment etc. So it s provide different checkout flow, different workflow, different logic  or different experience to the customers.                                                                                  
  8. Order Editing: Order is in step by step. Right columns provide the IP address  and the geo location of the order.                                                                                                            
  9. Add to Cart Forms: In the add to cart forms,we can have the variation attributes fields and line item fields as well. Now we have full control add to cart forms powered by Form display mode and field widget plugin.                                                                                   
  10. Shopping Carts: If you having multiple shopping carts, the ui will help to see and checkout each of them separately.                                                                                        
  11. Shopping Cart block: Easily customizable shopping cart block.                                           
  12. Checkout Flows: You can define your own custom checkout flows.                                    
  13. Improved Checkout UX:  It provides the option to do checkout as a guest user, or can also be registered as a new user while doing checkout.                                                       
  14. Payments: Under active development, Currently integrating Braintree and Authorize.Net as reference implementations.                   

Conclusion

Early in 2017 or even before Commerce 2.x will be fully functional. Commerce 2.x  with Drupal 8 will make a difference in the ecommerce world.

When can we start using the Drupal8 Commerce 2.x ?

See the bellow comment by Bojan Živanović

Thanks, that's a great summary. We're tracking the beta1 blockers here: https://www.drupal.org/node/27..., once beta1 gets released people will be able to start building production sites on Commerce 2.x. See you in the issue queues!

Image credits: https://www.flickr.com/photos/comprock/26392816934/in/pool-drupalconneworleans2016/

Send Message to Slack from Drupal

We moved to Slack few months back and the one thing that I love about Slack, is the integration of various apps with it. Most of the integration are out of the box like Google documents, Dropbox, Git and Bitbucket. But we wanted to integrate Drupal with it. Our need was to send a notification message to the #general channel whenever a new Blog post is published.

We start off by adding a Custom Integration from the Slack App Directory.

Salck custom integration

We will be using the Incoming Webhook as we will be sending data from our Drupal site to Slack.

Select the channel where you want to post the message or create a new one. Once the channel is selected it gives you the setup instructions. The most important part is the Webhook URL which we will be used in our Drupal site. You also get a level of customisation about the slack bot like the name and image.

Next we come to our Drupal site. Drupal 8 has a development release for the module which allows integration of Slack. Once the module is installed go to Slack configuration page at “admin/config/services/slack/config”. Here you will enter the Webhook Url as provided by Slack when the integration was added. Additionally you can also change the username and image of the username who will be sending the message to Slack.

Slack configuration


Try sending a test message from the Slack configuration UI and when everything is setup correctly you will receive a message in Slack.

Now, to send a message to Slack when a node is created or update add the following code:
 


/**
 * Send message via slack.
 * @param $node
 * @param $op
 */
function send_message($node, $op) {
 global $base_url;
 $config = \Drupal::config('slack.settings');
 $channel = 'test';
 $url = Url::fromUri($base_url . '/node/' . $node->id());
 $node_title = $node->label();
 $snippet_user_id = $node->get('field_user')->target_id;
 $account = Term::load($snippet_user_id)->getName();
 $username = $config->get('slack_username');
 $link = render(Link::fromTextAndUrl("here", $url)->toRenderable());
 $webhook_url = $config->get('slack_webhook_url');
 
 if ($op == 'insert') {
   $message = 'Snippet `' . $node_title . '`` was added by *' . $account . '*. Click ' . $link . " to view.";
 }
 else {
   $message = 'Snippet `' . $node_title . '`` was updated by *' . $account . '*. Click ' . $link . " to view.";
 }
 // This will send your message to Slack.
 \Drupal::service('slack')
   ->sendMessage($webhook_url, $message, $channel, $username);
}

 

Salck message


Finally we are trying to integrate Disqus comments with Slack so that when there is a new comment we get a notification about it and respond. 

There you go!
 

Download the Drupal Guide
Enter your email address to receive the guide.
get in touch