10 Facts Media & Publishing Companies Should Know About Drupal To Enhance Digital Performance

Be it the most viewed’ Game of Thrones’ or the random ‘How to find your soulmate?’ article, all that matters at the end of the day is the ratings & revenue generated out of it.

So let’s cut to the chase!

How do you save millions for your company in the digital world using Drupal? Well, it’s with this total package of Drupal, being a one-stop shop. Let’s unfurl it.

1. Time is money! Manage your content better and save time.
Drupal is an open source CMS so with the community contributing modules, it reduces the effort in maintaining the web application itself. With a centralized content hub, your company with multiple child sites can share the same base for content development, which again saves time.

2. Ease out the process and reduce the effort
Let’s say, first thing in the morning you open your laptop and everything you need for the day is organized in your dashboard. That’s what Drupal does for easing out authoring experience with Editorial Dashboard. With the workflow tools, content tracking becomes simple. Now, you know how to convert this in the language of money.

3. Let’s talk business.
Drupal is highly flexible allowing easy placement of the revenue generating advertising spaces. Supporting your pay walls & online subscription management are just added advantages.

Monetise your assets

                                                                                                     Credit: Pixabay

4. Save & Earn through your assets!
You are rich when your website is rich. Video, audio and files have become the assets of a website. Drupal allows video, audio & file integration into the authoring workflow saving the authors from fragmented authoring. It will not only help you save but earn as a result of the rich media on your website.

5. Monetize your search.
Everyone is busy. Understanding this, Drupal provides enhanced search functionality getting you accurate search results saving you from hitting a wall. This reduces the development duration and saves you cost.

6. Know your audience & spend wisely.
Enhance your SEO weightage and SEO tagging with Drupal’s SEO analysis. Drupal’s market analysis modules aids in knowing the trend of your target market. To favour a personal touch of contents, browsing patterns of audience is powered by Drupal. Be smart in investing in your audience and save money.

7. Allow your money to grow from all mediums extensively.
In a world of 5 year olds running their fingers over an iphone & tablet, it’s no more about just the presence. It’s about the experience. Drupal being compatible to all devices from mobile phones to PCs, gives the customized reading experience by adjusting the screen to each device.

8. Score through social media!
Drupal makes social media integration hassle free. Newsletters and subscription management are not left out either so that you don’t miss out on your audience in any way. Reach out to your audience swiftly and save yourself from burning your pockets needlessly.

Know your audience

                                                                                                  Credit: Perspecsys

9. Scale up. Secure it. Finally speed it up.
Scalability is the biggest USP of Drupal saving you millions of dollars from getting stuck in the expansion phase. Spare your expense of site repair from crashing and have a good night’s sleep as Drupal offers top class security.

Rabbit or Hare? Rabbit of course! As no one wants to see that rolling ‘loading’ circle and for those expecting Usain Bolt’s performance in websites, Drupal comes in handy saving you from shedding those extra bucks into site maintenance. As for your users, well, they don’t get to see the rolling circle anymore.

10. Travel the world with less expense.
Get to include various languages for your website and save your cost as Drupal gives multi-lingual support. Let’s not ignore the audience belonging to different regions. Drupal also helps in region based customization of contents for multi site platforms.

If you want to execute this plan or if you plan on saving more then reach out to us. You can try our Drupal dev team for two weeks without any commitment or cost involved.

Setting up Vagrant on Windows for Drupal Development

Vagrant provides easy to configure, reproducible, and portable work environments built to improve productivity. It allows developers to build the virtualized environment once and keep sharing it for every case.

The file required to have a Vagrant machine i.e the Vagrantfile is written in Ruby, so if you are unfamiliar with it, using Vagrant can be a bit tricky. That’s where PuPHPet comes in. PuPHPet allows you to generate a package that contains all the needed code to create a virtual machine exactly as you decide on PuPHPet’s website.

Installing Vagrant on Windows environment is a multi-step process.

To install Vagrant, you need to download the appropriate version of Vagrant and VirtualBox packages.

STEP 1. Creating a location

Choose a directory where you would like your VM to be saved. This location is regardless of where you save your VM configuration and files. Create a folder where you decide to store your VM. In Windows, we can create a new folder in ‘C’ drive and name it ‘drupalvm’.

STEP 2. Installing VirtualBox

Next we need to download and install the latest version of VirtualBox for Windows from https://www.virtualbox.org/wiki/Downloads. Follow the normal installation procedure for Windows and VirtualBox should be up and running for you.

vagrant 1

 

STEP 3. Installing Vagrant

Download the Windows compatible Vagrant package from  https://www.vagrantup.com/downloads.html and follow the normal installation steps.
 

vagrant 3

 

STEP 4. Using PuPHPet to create your VM:

To create your VM configuration at PuPHPet, go to sitepoint.com/build-virtual-machines-easily-puphpet/. Here we will configure our virtual machine as per our need and customize it accordingly.

  • VM Settings: On the PuPHPet homepage, click on ‘Get started right away’. Next, you shall be directed to a page similar to the one below.

 

vagrant 5

 

  • Over here we shall select the Provider as ‘VirtualBox’ and our Distro as “Ubuntu Trusty 14.04 LTS x64”. You can select a distro as per your need and your system configurations. Leave the other details as default unless there is a need to change them.

  • Click next and move on to select the system packages. Over here select additional packages for your VM as per your need. Else, you can go on to the next step.

  • For a next few steps you can just go on clicking next leaving all the settings as default until you have to select the server.  

  • We would be using Apache as our server and so uncheck ‘Nginx’ and move next to select Apache.

vagrant 6

 

vagrant 7

 

  • Again over here we would the settings as default unless and otherwise required to be changed.
  • After this is done, you can further move on to the next few steps leaving the details as default. Next you can select the version of PHP you want to run. In my case, I would go ahead with PHP 5.6. Note that Drupal 8 needs PHP version 5.6 and up so select accordingly.
  • Next, instead of MariaDB we would be installing MySQL database. Go ahead and uncheck MariaDB to set up MySQL for the VM. You can configure MySQL as per your need. Select the MySQL version as 5.6. Further you can change the username and password if required.

vagrant 7

 

  • Further you can leave the configurations as they are for the next few steps. Next you should see a screen with the option to download the your customized archive.

vagrant 9

  • Go ahead and download the zipped folder by clicking ‘Download your custom..’. With this you are done with creating a customized VM using PuPHPet.

STEP 5. Setting up your VM:-

  • Once your download is complete, extract the folder to the location where you intend to setup your VM. In our case, we would extract the folder in C:/drupalvm created in step 1.

  • Once this is done, run your command prompt with admin privileges and point to the location of the folder with the ‘vagrantfile’. When you are inside this enter the following command in your command prompt.

vagrant up
 

  • This would set up vagrant on your system and is expect to take a while. Once this is done just type vagrant  in your command prompt. This shall start vagrant on your system. Further you can do a vagrant -v to check the version of vagrant installed.


STEP 6. Setting up the host:-

To create virtual hosts, we need to make changes to the host files on our system. Go to C:\windows\system32\drivers\etc\hosts and make changes to the host file using an editor with administrative privileges.

Go ahead and select a domain name for your Drupal project. You can use anything as  ‘drupal8.dev’ as my domain name. Accordingly add this line to the host file:

192.168.56.101   drupal8.dev

The IP address was chosen while creating our VM config file on PuPHPet. If you do not remember it now, you can find it by opening config.yaml using a text editor. The config.yaml file is located inside your puphpet folder, which you placed inside your VM folder earlier. We have just completed configuring a VM on our computer.

With this we are done with configuring a VM on our system. Go ahead and type the domain name - drupal8.dev  in your browser to access it.

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

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 additionalfunctionalities 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.
 

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