AddThis

Thursday, 4 May 2017

How to install a module in Drupal 8

There are many ways to install modules in Drupal. But for every time, I chose to go through the following steps to get it done.

Let us assume we are trying to install the module,
Custom Landing Page Builder


Download the version from the module page on drupal.org.



Once downloaded, extract it. 
At the project folder, locate the modules folder, create a new folder as contrib to hold all the contributed modules used for the website. Move the extracted folder at Downloads to the contrib folder.

Navigate to Admin -> Manage -> Extend. Search for landing page in the search field. The system will short list the modules in that name.


Check the check-box and proceed with install button. The module has susuccessfully installed. If any errors encountered, check the Recent log message at Admin -> Reports or else check the apache log.

  

Tuesday, 25 April 2017

How to install Drupal 8.3

Few prerequisites are considered to get Drupal installed by the following tutorial,
  1. Ubuntu 14.04
  2. MySQL
  3. PHP 
Assuming http://localhost points to /var/www/html.

Download Drupal 8.3

Download the latest Drupal package from https://www.drupal.org/project/drupal/releases/8.3.1. Find the zip file at Downloads. Extract the zip content and rename it to, let's say test. Move the test folder to /var/www/html from Downloads to make a folder structure as /var/www/html/test.

Navigate to http://localhost/phpmyadmin to create database. Create one as test.

Access http://localhost/test to start installation prcedures. 

Language
 
Choose the language from the first window to proceed further. By default it will be English. You can add as many as languages as Drupal 8 support multi-language

Profile

Chose Standard as the profile.   

Requirements

If you've no proper files and permissions for the website, it will throw two errors at the requirements page.

   
The first error indicates sites/default/files doesn't exist. To erect the issue, navigate the sites/default folder and give 755 permission. 

 
 
Reload the requirements page and the first error is vanished

For the second error, there is no settings.php. To meet this let us make a copy of default.setttings.php in sites/default. And rename it to settings.php. Once it is done, refresh the requirements page. It will let you move further.

Configure Database

Enter the database name, user-name and password created for the website. Click on to proceed.

Configure Site

To complete the Drupal installation, enter the values you find to be relevant for the application that are asked for. The usual values asked for are, Site name, Site email, User name, Password etc. 
  
Installation has completed and will show the front page of the website.

  
Hope this helps. 
:)
  

  
 

 

Friday, 21 April 2017

How to setup a virtual host in Ubuntu 14.04

 What is a virtual host? A virtual host is a invisible host to a location somewhere with in your machine.

When I've setup a virtual host, what I literally found to be missing on Internet was a complete and guided documentation. So I thought I would write on how to set up a virtual host on Ubuntu 14.04.

Let us assume, Apache, PHP and MySQL are configured in the working environment. Now you are all set to figure out how to setup a virtual host.

The only reason I'm working as a Programmer nowadays is the show off by bloody Napster, aka Seth Green from The Italian Job. Somehow, I'm happy the way I'm today.

Now let us create a create a folder inside /var/www/html/ as test. So the path is /var/www/html/test. Let us create a file, as index.php

 

And enter the below content,

<?php
  phpinfo();
?>

The terminal was a nightmare to me, but more you learn, more they become your friend.

So let us start by opening the terminal. You are ready to open a terminal by Ctrl+Alt+T. Anyways it is your choice. So this is how the terminal looks like.



Let us assume, the http://localhost points to var/www/html. The apache web server configuration files are located at /etc/apache2. Let us move to /etc/apache2/sites-available. This is where all the virtual hosts set up in your machine resides.









Now let us create a file inside sites-available using the following command.

sudo touch test.loc.conf

Open the file using,

sudo nano test.loc.conf

Copy the below contents to the test.loc.conf

<VirtualHost *:80>
    ServerName test.loc
    DocumentRoot /var/www/html/test/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost> 


Here ServerName is the url we are using to access the directory. 
DocumentRoot is the path to the contents to be shown when the ServerName is accessed from browser.

ErrorLog is to log the errors that occur in the website. It is very useful for debugging.

Now you've created the files required for the virtual host. Now you need to register the host at /etc/hosts file.

To do that, open /etc/hosts file.

sudo nano /etc/hosts

Add the following line to file as 

127.0.0.1    test.loc

 

 Now you are ready to enable the virtual host.

sudo a2ensite test.loc.conf

And restart apache

sudo service apache2 restart
  
To check whether the host has been enabled you can move to /etc/apache2/sites-enabled 

There you'll see your virtual host file. 

Now you're good enough to access your content at test as http://test.loc

QBurst Drupal Interview Questions

  1. How do you reduce the size of css and js in Drupal?
  2. How to get the id of a javascript element on click event?
  3. Suppose you've a table named pen, with columns id, color, brand and count. Write a query to list the color of pens from highest to the lowest count?
  4. Write the syntax to create a custom block?
  5. What is an entity, entity type, field and properties?

Capgemini Drupal Interview Questions

  1. What is git tagging?
  2. What are the differences between Drupal 7 and 8?
  3. How do the search in Drupal works?
  4. What is Data Abstraction Layer?
  5. What is the software development approach you follow?
  6. What is Scrum, Sprint?
  7. What is Waterfall model?
  8. How do you do theming in Drupal?
  9. How do you deployment in Drupal. What are the tools used?

Digital Craft API Drupal Interview Questions

  1. How will you create a page with the url /page in Drupal website. For example, example.com/page.
  2. If you want to restrict a users on meeting a certain condition, how will you do that?
  3. Have you worked on Rules module? Do you know rules events, actions?
  4. Have you worked on Drush? How do you create custom drush command?
  5. How do you join a table in Views?
  6. Suppose you've a view in your system. You want to include that in a module. How do you do that?
  7. hook_node_view is a hook provided by node module. How to create a hook in your module so that it could be used by other modules?
  8. Assume you've two form fields, and they are select list. First one for country and the other is  for states. The second select list is populated only when the first one is selected. How do you do that?
  9.  How do you theme the components in a page?
  10. How do you format the fields in a form?
  11. What are Drupal behaviours?
  12. How to integrate custom table in views?
  13. Have you ever made any modification on searching functionality in Drupal?
  14. How do you create new version of the module in drupal.org?
  15. How to create a table at the time of module installation. hook_schema() or hook_install() is the right hook to create table at the time of module installation?
  16.  How do you add a new field to the existing table in Drupal?

Wednesday, 15 March 2017

[Drupal 8] Modify the breadcrumb text

Breadcrumbs are considered as a secondary navigation, as it let the user know the current, as well as the path through to the location.

In Drupal 8, Menu breadcrumb is used to set breadcrumbs for the pages. In one of the websites I was working on had sub menu's with html tags. For the About menu, the sub menu was as 'All about Organisation'Menu breadcrumb would show the breadcrumb for the page, 'All about Organisation' as,
 

Home > About > All about <i>Organisation</i>


The breadcrumb is not presentable to the visitor, without stripping or by formatting the html tags. 

To do this, we need to implement hook_preprocess_breadcrumb().


function test_preprocess_breadcrumb(&$variables) {
    foreach ($variables['breadcrumb'] as $key => &$value) {
      $value['text'] = strip_tags($value['text']);
    }
  }

In the hook, $variables['breadcrumb'] contains the details of breadcrumb. 
In our case, there would be three key value pairs($key, $value), first for Home, second for About, and the last one for All about <i>Organisation</i>. Each value contains an array of text($value['text']) and url($value['url']) of each level. By iterating through the key value pair, we strip the tags from Home, About and All about <i>Organisation</i>, which will result in the below breadcrumb.

Home > About > All about Organisation

We've made a presentable breadcrumb for the visitor and that is it.  I would be glad to hear if it helped you. Happy Coding :)

QED42 Drupal Interview Questions

  1. What is #states in form?
  2. What is features module? When do we revert and update a features module?
  3. How to show longitude and latitude in text fields separated by comma in google map in a node?
  4. Architecture of Drupalize.me?
  5. Alter a user login form to include an email field and validate in same?
  6. What is the order of preprocess functions in template.php?
  7. How to bring change in result of a 42 views shown as a slideshow?
  8. How do we theme a view?
  9. Share fields between content types?
  10. How to remove ?q=user while setting up Drupal?
  11. For companies they've jobs. For applications has applicants. Get all jobs of a company and for all company, get all the applications for a particular job?

TCS Drupal Interview Questions

  1. How to add a new field to user account? How to validate the same?
  2. Which database engine used by Drupal?
  3. What is the difference between InnoDB and MyISAM?
  4. Difference between UNIQUE and PRIMARY key? 
  5. Explain the following contributed modules
    Features
    Views
  6. How to add JavaScript and CSS to Drupal?
  7. How to create a branch in Git?
  8. How to use ORDER BY and GROUP BY in database?
  9. What are the contributed modules used?
  10. Explain Web Service, CURL?
  11. What is hook_menu(), page arguments, page callback etc?
  12. Experience in Drupal?
  13. How to get id in JavaScript? Write a JavaScript function to get the id of the button?
  14. What is taxonomies and Vocabulary in Drupal?
  15. How to give connection to a field as taxonomy?
  16. What are exposed filter in Views?
  17. What are contextual filters?
  18. How to theme a form in Drupal?
  19. Use of template.php?
  20. How to create a tpl for a particular content type in Drupal?

I had a telephonic interview from TCS Mumbai. Hope this helps.. :)

[Drupal 8] Include html tags in link function in twig

It is obvious to have a difficult client, who can ask you to do things that are a bit messy. 

I had to face many such situations while working on different projects. One such situation has inspired me to start writing on Drupal. 

To an extend user experience of a website is dependent on its navigation. Main navigation accounts to a measurable heights in it. In this case, one of the menu item has had a text aligned in italics, eg., About the Organisation. The term Organisation has to be in italics. 

I've started by adding a menu link at Structure -> Menus -> Main navigation, as About the <i>Organisation</i>.

In the template, we are rendering the menu item as,
{{ link(item.title, item.url) }}

Output of the above link will be, About the <i>Organisation</i>. Which is not what we're expecting to show to the visitors. 

To format the html for the above link, pass the raw filter on item.title. This filter is used to format text containing html in the twig file. Later assign the formatted text to a variable, here it is title. At last in link function, replace item.title with title. 
{% set title %}
    {{ item.title|raw }}
{% endset %}
{{ link(title, item.url) }}