Here we have mentioned most frequently asked Drupal Interview Questions and Answers specially for freshers and experienced.


 

1. Explain what is Drupal?

Ans:

Drupal is a Content Management System (CMS). It’s an open source content and free CMS framework written in PHP. It enables you to organize, manage and publish content with ease and comes with a variety of customization option.

2. Why Drupal is considered powerful CMS compare to other CMS system?

Ans:

Using content construction kit Drupal allows you to create multiple content types without any programming skills. And for each content type it allows customize theme template. You can have an article, story, slideshow, content type and so on.

3. Mention what are the key features of Drupal?

Ans:

There are two key features of Drupal

  • Upload Module: It enables users to attach different types of files to node types of your liking.
  • Embedding: It enables to embed media within nodes that are hosted on your websites.

4. Explain how caching work in Drupal?

Ans:

Through caching Drupal allows to speed up website using different configuration like page caching, block caching and lifetime for cached pages.

  • Page Caching: It enables the entire HTML of each page to be stored in the database. It reduces the amount of queries needed
  • Block Caching: You can set the cache setting for a block in views, when block created by views
  • Minimum cache lifetime: It is the amount of time before the page cache is cleared. On each cron run, page caches are cleared.
  • Expiration of cached pages: It only applies for an external mechanism, for example, your browser cache or varnish

5. What is a patch?

Ans:

A patch is a file that contains a list of differences between one set of files, and another. Through patches, all the changes in code like additions or deletions to Drupal core can be made. Also, patches can be used to make changes to another copy of the original or main file.

6. What do PDO mean?

Ans:

PDO means PHP Data Object; it is a lean and consistent way to access databases. It allows developers to write portable code with ease.

7. Explain how database system of Drupal works?

Ans:

In a database Drupal stores information, and each information has its own database table. For example, the basic information regarding the nodes of your site are stored and kept in the node table, and if you use the CCK module to add fields to your nodes, the field information is stored in a separate table.

8. Name some of the most commonly used PHP based CMSs?

Ans:

Some of the commonly used PHP are

  • Drupal
  • Joomla
  • WordPress
  • TYPO3

9. What is DRUSH in Drupal?

Ans:

DRUSH is a command line shell and UNIX scripting interface for Drupal

10. Explain what is module in Drupal? List out some of the modules used in Drupal?

Ans:

Modules are like plugin for your site. It allows you to add different functions to your site such as polls, contact forms and search fields. Some of the modules recommended are

  • Views
  • Token
  • Ctools
  • Quicktabs
  • Pathauto


 

11. Explain what Drupal distributions is and when to use?

Ans:

Distributions are full copies of Drupal, which includes Drupal Core, along with additional software as modules, themes, libraries and installation profiles. You can use distributions for

  • Evaluating Drupal
  • Demoing Drupal
  • Learning Drupal
  • Quickly binding Site

12. List out the SEO modules available in Drupal?

Ans:

Some of the SEO modules available in Drupal are

  • Pathauto
  • Meta tags/ Node words
  • Service Links
  • Google Analytics
  • Related Links
  • Search 404
  • Site map
  • Url list

13. Explain what is Drupal weight?

Ans:

The term Drupal weight is used to describe the priority or order in which the function is processed, or block/ node is displayed.
A heavier (+10) weights will appear lower in lists while a lower weight (-10) will float to the top of lists.

14. Explain what is Drupal cron?

Ans:

To execute commands or scripts automatically at specified time and date intervals, you have to use Drupal cron.

15. Why Drupal needs database? What databases are supported?

Ans:

Drupal stores its information in the database like individual pages, registered users and so on. For your Drupal site, database forms the back end; it supports MySQL /MariaDB, PostgreSQL and in Drupal 7, SQLite.

16. Explain what is render array in Drupal?

Ans:

For Drupal content render arrays are the basic building blocks. In Drupal, render arrays provide you a structured way to programmatically change the content before it is displayed.

17. Explain what is the use of Ctools in Drupal?

Ans:

This suite is a set of APIs and tools, and it makes easier to handle AJAX requests and tell the client what to do with them.

18. What are the files required for theme and module?

Ans:

Drupal uses .info files to store metadata about themes and modules.
The files required for

Theme: style.css , page.tpl.php , template.php, block.tpl.php
Module: modulename.info , modulename.module , optional modulename.install

19. Explain using module how you can drop the table?

Ans:

To drop the table you can use db_drop_table in install file.

20. What are the translations available in Drupal?

Ans:

Drupal is translated into all popular languages including

  • Catalan
  • French
  • Hungarian
  • Dutch



 

21. Does Drupal provides support?

Ans:

Like with all open-source projects there is no commercial support available. Though, there is a vast online community for Drupal available via Forums and IRC online chat who are more than eager to answer your queries.

22. Where do I download a base theme for Drupal 8?

Ans:

As of this writing, you don’t. It’s true that there are a few themes that have tried to keep pace with Drupal 8 in the pre-beta phase. These are admirable efforts, but none have kept up with the rapid pace of D8 development.
I tried my normal go-to, Adaptive Theme, but the D8 version was unusable, and threw tons of fatal errors as soon as I installed it. I took a look at Zen, but the D8 version hadn’t been updated in a year, and its own release notes called it “completely broken.” Bootstrap offered a similar caution on their project page.
I’m sure circumstances will improve, but as of today, if you want to theme your D8 site, you’re going to have to work from scratch. But I promise it’s really not so scary.
EDIT: see this blog post, which is still relevant (2016-12-22). At least Bootstrap, Basic, Neato!, Beginning, FortyTwo, xtheme and mbase have stable versions.
EDIT II: Multiple contrib D8 themes exist as do Classy and Stable which are included in core.”

23. How do I create a new theme in Drupal 8?

Ans:

Here’s the folder structure of my custom theme.
http://i.imgur.com/SHHgxhV.png
The only file that absolutely must exist in order for your theme work is theme_name.info.yml. As you might have guessed, this is equivalent to the old theme_name.info that we used in D6 and D7. Of course, a theme with just an .info file doesn’t do very much—enabling a theme with just an .info file is essentially the same thing as enabling Stark (still shipping with D8 by the way). Here’s my .info file, you can probably intuit most of what it does:
https://gist.github.com/MKorostoff/562e4ef59a4a563c0452
A side note here that I won’t dwell on: you’ll probably find YML pretty hard to read for the first little while. I still haven’t gotten all the way used to it, but it’s gotten a lot better in just a few weeks. I also find that liberal use of code folding in Sublime Text makes YML a lot easier to digest.
http://i.imgur.com/0UqKV47.gif
The other files that you’ll almost definitely want are theme_name.theme, a php file, equivalent to the template.php and used mostly for preprocessor functions, and page.html.twig, equivalent to page.tpl.php in D7.

24. How do I declare a new template file in my Drupal 8 theme?

Ans:

No real changes here from Drupal 7, other than the fact that php templating is gone, and replaced with Twig templating. Just like Drupal 7, you can instantiate new template files in the root of your custom theme folder simply by giving them the same name as one of the template files in core.
http://i.imgur.com/E7o0yUE.png
Like Drupal 7, you can limit the scope of your template file by giving it a specific name, according to that element’s “theme suggestions.” (The new documentation is no longer calling these “theme hook suggestions.”) So for instance, you can create a node.html.twig which will apply to all nodes, and then a node–article.html.twig which will apply only to nodes or the type article. Note that the available theme suggestions is vastly improved in D8, giving you out-of-the-box ability to target by content type, view mode, and a wide variety of other conditions. Improved theme suggestions is one of my favorite new features in D8.

25. How do I find out what template files I can use?

Ans:

The easiest thing to do here is to just turn on twig debug mode. This is by far my favorite new feature of D8. When turned on, you get an output like:
http://i.imgur.com/OX5122C.png
You can also accomplish a pretty much identical thing by implementing a new API hook added for D8, hook_theme_suggestions_alter or hook_theme_suggestions_HOOK_alter.
http://i.imgur.com/QWwIV6m.png

26. How do I turn on twig debug mode?

Ans:

D8 ships with a new file called services.yml. It contains global configuration for php services. See instructions on drupal.org. You’ll find the file at sites/default/services.yml. Here’s my services.yml
https://gist.github.com/MKorostoff/df31c7b219a8f412f092

27. Why do I have to clear cache after every change anything in my template file?

Ans:

You have to set auto_reload to true in services.yml (see #5 above, note lines 30 and 41 of the code sample).

28. I did set twig auto_reload to true, why do I still have to clear cache all the time to see my Twig changes?

Ans:

Some elements have an additional layer of caching. I ran into this trying to edit the ‘submitted by’ information in node.html.twig. To disable this during development, do the following:
http://i.imgur.com/calZTfi.png
Then, in settings.php, uncomment these lines:
http://i.imgur.com/Zx4kvEm.png

29. How do I preprocess my template files?

Ans:

It’s about the same as D7 actually.
http://i.imgur.com/H1u9iSw.png
Note that, like D7, only the base hook can be used for preprocessing templates. So if you declare node–article–teaser.html.twig you cannot declare hook_preprocess_node__article__teaser, but instead must use hook_preprocess_node and then add conditional logic inside to limit the scope of your preprocessing.

30. Why am I unable to save services.yml?

Ans:

That’s a great question, I have no idea. I was unable to save this file regardless of file permissions or ownership, using Sublime Text or PHP Storm.
http://i.imgur.com/hImibbU.png
I didn’t encounter this problem with any other D8 file, and it is no longer reproducing for me in D8 beta2. I was ultimately able to save using Atom. ::shrug::


 

31. Where is jQuery?

Ans:

jQuery is still shipping with D8 (version 2.1.0 by the way!), but it is not injected into the page by default.

32. How do I enable jQuery in Drupal 8?

Ans:

It’s pretty easy actually. In your_theme_name.theme:
https://gist.github.com/MKorostoff/0d1af8f4fc8da6681745

33. How do I add my own custom Javascript in Drupal 8?

Ans:

This took me a while to figure out. I wanted to add a custom version of the Modernizr library. Though a version of Modernizr ships with
D8, I wanted a different version. Here’s how I attached it:

  • Save your custom script in themes/theme_name/js/script_name.js. Technically this can be any path.
  • Declare your script in themes/theme_name/theme_name.libraries.yml:
  • https://gist.github.com/MKorostoff/a36a1a15f14f43c8b1e2
  • Line 4 is just the path to the javascript file. I’m not sure what line 2 (“version: VERSION”) is all about, but I’m being literal here, you actually write the word version in all caps like that. I guess there’s a way to allow for multiple versions of the same library, though I’m not sure how to do it.
  • In theme_name.theme, do this:
  • https://gist.github.com/MKorostoff/285f88996fb12f32a03b
  • Note that “matt” on line 7 is just the name of the theme, and “matt-corescripts” is the name I chose on line 1 of matt.libraries.yml
  • Here’s an overview of the way these files are connected:
  • http://i.imgur.com/zyYr23O.png

34. How do I add external CSS libraries? (e.g. google fonts)

Ans:

I’m pretty sure there’s a more native way to do this, but the only solution I could find was to do it in html.html.twig. Note line 7.
ss
https://gist.github.com/MKorostoff/d623201067250714091b
It’s preaty simple, We need to add external library (CSS, JS) into your_theme.libraries.yml and attach the library either to twig or in your controller

myLibrary:

js:
https://stackpath.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js: { type: external, minified: true }

css:
component:
https://stackpath.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css: { type: external, minified: true }
{{ attach_library (‘mythemename/mylibrary’) }}

35. How do I disable commenting on articles?

Ans:

Comments on nodes are now fields, and thus controlled with field settings.
http://i.imgur.com/ouTKvMA.png
http://i.imgur.com/fKCO71y.png
Or, better yet, just delete the field:
http://i.imgur.com/9J8qcjm.png

36. How do I change the submitted by information?

Ans:

This is one of the first things I do on any Drupal site build. I can’t stand the format “Posted by admin on 2013-02-03 24:32:34”. This has been mercifully moved into node.html.twig for D8:
http://i.imgur.com/7v4xCWb.png
Just copy this file into your custom theme and edit as needed.

37. Why can’t I disable modules in Drupal 8?

Ans:

http://i.imgur.com/34ispJO.png
Technically, D8 has dropped the distinction between “disable” and “uninstall” but that’s fairly academic. Let’s not dwell on that. As it turns out, these check boxes serve no purpose other than to confuse you—I assume they’ll be removed in the full release of D8. To uninstall a module, simply navigate to admin/modules/uninstall
We can uninstall module from terminal or console aswell
Using DrushDrush pmu module_name or Drupal mou module_name -y could be used to to avoid prompt massage
http://i.imgur.com/AdCCMBb.png

38. How do I create a custom module in Drupal 8?

Ans:

Creating a bare-bones, “hello world” type module is about the same in Drupal 8 as it was in 7. You only need two files your_module.info.yml and your_module.module. I’m told that the .module is actually optional now, but I’ve yet to figure out how to produce a functioning module without it, so I’m not sure if that’s true.
https://gist.github.com/MKorostoff/8d646585a95ba511d1fe
My first Drupal 8 module
http://i.imgur.com/5hEFkr1.png

39. What the hell happened to all the fonts on the node add page?

Ans:

I have no idea. I think this happened after I disabled CKeditor. The following screen shot is definitely not how the node add page looks out of the box:
http://i.imgur.com/mPIz3ne.png
I never solved this, but I also never reproduced it. Once I reproduce it, I’ll open an issue thread on drupal.org, but for now I don’t really have anything to report.

40. How do I version my configuration with git?

Ans:

You’ve probably heard a lot about the configuration management initiative over then last few years. You probably also heard recently that active configuration is now stored in the database by default. In the end, this turns out to be a pretty trivial change to the overall architecture of CMI as far as most users are concerned, because the only CMI files that you meaningfully interact with are still stored in code.

If you’re familiar with the Features module from D7, the new Config module is exactly the same paradigm. The upshot is that, this is how you export your configuration:
drush @yoursite.local config-export
git add -f sites/default/files/config_wNOLcmycPFZCrXJ9wis9dCdSR4lpYILdBsFxSWuK5Hzhcr-irILQ0u25dfasd9sdfsadWaUDwMg
git commit -m ‘Exporting configuration to code.’
git push origin master
drush @yoursite.production config-import

CMI is alive and well
http://i.imgur.com/Vvhqfjg.png
One last thought, that confused the hell out of me initially: the “config” directory comes with two subfolders, “active” and “staging”. In the default configuration, only “staging” will ever be used, and “active” will remain empty forever.
http://i.imgur.com/uAJM99G.png
http://i.imgur.com/MrkY1c8.png
Of course this language “default configuration” implies that there’s some other not defaultstrategy in which the “active” directory would be used. I haven’t figured out how to do that yet, but I’m reasonably sure it would be done in services.yml.

Note also that .gitignore is still shipping with Drupal core, but it’s now called example.gitignore. The idea is that you copy example.gitignore to your git root, which would be above the Drupal root, and then rename it “.gitignore” so that you’re not modding core. For my first build, I just made my git root and my Drupal root the same directory, and renamed this file in place.



 

41. How do I deploy this thing?

Ans:

To deploy this to my server on Digital Ocean, I did the following:

  • Exported my database from my local with Sequel Pro.
  • Imported my database to production with Sequel Pro.
  • SFTPed my code to production with Cyberduck.
  • SSHed to production and edited my database credentials with Nano.
  • While SSH’ed to production, edited services.yml to match its default, production ready state.
  • Ran drush @matt.production cr
  • Navigated to my new site in Chrome. It works!
  • Navigated to the performance settings page in the Drupal UI, enabled caching, CSS aggregation, and javascript aggregation.

One important note, if you’re server is currently running php 5.3 or less, you’re going to have to upgrade to 5.5.9 or greater.

42. How do I upgrade to php 5.5.9+?

Ans:

Of course, the upgrade procedure is going to vary wildly with OS, but for me, I was running OS x locally, and Ubuntu on the server.
Mac OS x
On my local (Mac OS X 10.8.5) I installed php 5.6 with homebrew and then pointed my httpd.conf file to point at the new 5.6 binary provided by homebrew:
http://i.imgur.com/G5d90uE.png
then I restarted apache with the command sudo apachectl restart
Ubuntu
I found this answer here.
sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php-pear php5-cli php5-common php5-curl php5-dev php5-gd php5-mcrypt php5-mysql php5-pgsql php5-xdebug

43. Why am I getting a white screen of death in production?

Ans:

Tons of possible reasons, but for me all I needed to do after importing my database was clear the cache with drush one time. I couldn’t access any page (including the performance settings page with the “clear cache” button) until this was done.

44. Why is `drush cc all` not working?

Ans:

It’s `drush cr` now. Which stands for ‘cache rebuild.’ Also, you’re gonna need to upgrade to Drush 8, more on that below.

45. Why isn’t drush working at all with Drupal 8?

Ans:

You need to upgrade to Drush 7.

46. How do I upgrade to Drush 8?

Ans:

You need to install Composer to install drush:
https://getcomposer.org/doc/00-intro.md#globally
https://github.com/drush-ops/drush#installupdate—composer

47. OK so I upgraded to php 5.4, installed composer, installed drush 8, and then ran `drush cr` in production now what?

Ans:

Now your site is ready. Enjoy 🙂

48. How do I integrate with Varnish?

Ans:

Much like Drupal 7, Varnish configuration is more or less out-of-the-box.
http://i.imgur.com/WAqH5jq.png
Note that this page is trying to guide you toward using Varnish without really saying it. If you don’t plan on running varnish, you’ll probably want to check off “Use internal page cache”.
One thing I always do when working on a site for which I’m the only logged-in user is omit the “vary cookie” in settings.php.
http://i.imgur.com/R8FLmZm.png
This bumps your varnish hit rate to just about 100%. In D7 it also broke user login. In D8, as far as I can tell, user login works even without the vary cookie, so there might be no downside here.

49. what is entity and entity api?

Ans:

They provide a unified way to work with different data units in Drupal. Drupal 7 is all about entities. They are everywhere: nodes, users, taxonomy terms, vocabularies.

But how, as developers, can we create our own entities? When do we really need to do that? I think these questions are really very project-specific. We can probably use nodes for nearly everything. But when it comes to performance-sensitive projects, nodes should really only be used for content, and we should separate as much as possible from nodes. Why? Nodes are revisioned, they fire a lot of hooks, and they have functionality that we likely won’t need. Also if we know exactly what fields we should have in our entities, we can create our own custom entities to avoid all those joins of Field API tables.

50. How to do the for drupal debugging

Ans:

Simple using print_r or var_export , you can debug code within Drupal.

$node = node_load(123);
print_r($node);
?>

Drupal devel module provides dsm and dpm functions to debug code within drupal.

$node = node_load(123);
dpm($node);
?>

Drupal latest version provides debug inbuilt function to print errors, notices and warnings as well.
This could be in the page or in the logs depending on how php is configured.
For example

$node = node_load(123);
debug($node);
?>

The full options for debug function are:

debug($data, $label, $print_r);

The $data is pretty self explanatory. It can be anything you could pass through print_r or var_export. The $label allows for a custom label to be added.
This is ideal when you are sending the information to a log and you want a key to search the logs for. The 3rd argument is whether to use print_r or var_export. The default is var_export.
If you are interested between the two I’d suggest reading the manual pages




 

51. Which files are required for theme?

Ans:

style.css, page.tpl.php, info file, template.php, node.tpl.php, block.tpl.php

52. Which files are required for module?

Ans:

modulename.info, modulename.module, optional modulename.install

53. What is Drush – how drush is used?

Ans:

Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.

54. Where to use the theme hook?

Ans:

template.php in theme folder

55. What is use of template.php file?

Ans:

Overriding other theme functions. If you want to override a theme function not included in the basic list (block, box, comment, node, page), you need to tell PHPTemplate about it.
To do this, you need to create a template.php file in your theme’s directory. This file must start with a PHP opening tag

56. What is subtheme?

Ans:

A Drupal subtheme (or sub-theme) is a theme that is based on a “base theme”. The base theme provides basic (and sometimes more than basic) functionality. The subtheme styles the site with a unique look, and adds any unique extra functionality.

57. How to use the multiple themes in one project?

Ans:

use the global variable, default_theme.

58. How can we set the region in drupal theme?

Ans:

You can set the regions in themename.info file.
regions[header] = Header
regions[content_header] = Content Header
regions[content] = Content
regions[sidebar_second] = Right sidebar

59. How to create the table using module?

Ans:

Use following code:

/**
* Implements hook_schema().
*/
function module_name_schema() {
$schema[‘module_name’] = array(
‘fields’ => array(
‘type’ => array(‘type’ => ‘varchar’, ‘length’ => 15, ‘not null’ => TRUE, ‘default’ => ‘node’),
‘id’ => array(‘type’ => ‘int’, ‘unsigned’ => TRUE, ‘not null’ => TRUE, ‘default’ => 0),
‘module_name’ => array(‘type’ => ‘varchar’, ‘length’ => 255, ‘not null’ => TRUE, ‘default’ => ”)
),
‘primary key’ => array(‘type’, ‘id’),
);

return $schema;
}

/**
* Implements hook_uninstall().
*/
function module_name_uninstall() {
// Clear variables
variable_del(‘module_name_default’);

}

60. How to update table using module?

Ans:

You can check the following code:

/**
* Implements hook_update_n().
*/
function module_name_update_6200() {
$ret = array();

if (db_column_exists(‘module_name’, ‘id’)) {
return $ret;
}

db_create_table($ret, ‘module_name_temp’, array(
‘fields’ => array(
‘type’ => array(‘type’ => ‘varchar’, ‘length’ => 15, ‘not null’ => TRUE, ‘default’ => ‘node’),
‘id’ => array(‘type’ => ‘int’, ‘unsigned’ => TRUE, ‘not null’ => TRUE, ‘default’ => 0),
‘module_name’ => array(‘type’ => ‘varchar’, ‘length’ => 255, ‘not null’ => TRUE, ‘default’ => ”)
),
‘primary key’ => array(‘type’, ‘id’),
));

$ret[] = update_sql(‘INSERT INTO {module_name_temp} (id, module_name) SELECT nid, module_name FROM {module_name}’);

db_rename_table($ret, ‘module_name’, ‘module_name_old’);

db_rename_table($ret, ‘module_name_temp’, ‘module_name’);

$display_settings = variable_get(‘module_name_display’, array());
foreach ($display_settings as $type) {
if ($type) {
variable_set(‘module_name_type_’ . $type . ‘_showfield’, 1);
}
}
variable_del(‘module_name_display’);

return $ret;
}


 

61. Which hooks you used and what is the purpose of using the those hooks?

Ans:

Drupal’s module system is based on the concept of “hooks”. A hook is a PHP function that is named foo_bar(), where “foo” is the name of the module (whose filename is thus foo.module) and “bar” is the name of the hook. Each hook has a defined set of parameters and a specified result type.
Hooks are how modules can interact with the core code of Drupal. They make it possible for a module to define new urls and pages within the site (hook_menu), to add content to pages (hook_block, hook_footer, etc.), to set up custom database tables (hook_schema) and more. This page lists the hooks provided in the core, but modules can define hooks of their own. For example the cck module defines hook_field_info, which can be used by modules that want to define a new type of content field. Most modules that define hooks will also provide documentation about them.
For example, if the module file is called example.module, then hook_help() as implemented by that module would be defined as example_help().

62. What is responsive theme?

Ans:

A responsive theme (as the one used for this website), is an approach to web development that allows a website to break itself down smoothly across multiple monitor sizes, screen resolutions, and platforms, be it a computer, tablet or mobile device. It allows the developer to create a site that is optimized for each platform, both in navigation, readability and load time.
As you can see when resizing the window (if you are viewing this site on a computer), the layout of the page shifts depending on the size of the screen; with different layouts for content depending on viewing area. Themes (or layouts) such as this, allow for a single site and single look to the site, to be viewed on various devices without the need for additional themes or resizing by the user.

63. What is difference between innodb and myIsam?

Ans:

First major difference I see is that InnoDB implements row-level lock while MyISAM can do only a table-level lock. You will find better crash recovery in InnoDB. However, it doesn’t have FULLTEXT search indexes, as does MyISAM. InnoDB also implements transactions, foreign keys and relationship constraints while MyISAM does not.

64. What is difference between update and alter query?

Ans:

ALTER is a DDL (Data Definition Language) statement. Whereas UPDATE is a DML (Data Manipulation Language) statement. One is used to update the structure of the table (add/remove field/index etc). Whereas UPDATE is used to update data.

65. What is purpose or use of .htaccess file?

Ans:

File_HtAccess provides common methods to create and manipulate Apache / NCSA style .htaccess files. These files together with accompanying password files are used to protect webserver directories. Since File_HtAccess does not provide any means to manipulate or create password files you should use it together with File_Passwd.

66. When do I need a contextual filter vs. a relationship?

Ans:

A relationship is a join.
Acceptd Just think of it terms of SQL:
a ‘relationship’ is a JOIN on another table
a ‘filter’ (contextual or not) is a WHERE clause.
‘Contextual’ just means the parameter comes from the current context, e.g. part of the URL, something in the session,
I think you described it well yourself. A relationship is a join. You are joining another table to the base table for the view you are creating. A contextual filter is an argument you are passing to the query created by the view.
If you are creating a list of node titles a simplified query you are creating might be:
SELECT title FROM {node};

A contextual filter would pass an argument into that query. You can grab the argument from the URL or a number of other places. In this example the type would be an argument you are passing using a contextual filter:
SELECT title FROM {node} WHERE type = ‘page’;

An example of a relationship might be accessing user info about the node author. If you added a relationship to the user on the user id the query might look something like this:
SELECT title n, username u FROM {node} n JOIN {user} u ON n.uid = u.uid WHERE type = ‘page’;

67. How to use the contextual filter?

Ans:

In Drupal, each type of information has its own database table. For instance, the basic information about the nodes of your site are stored in the Node table, Comments and Users also have their own database tables, and roles, permissions, and other settings are also stored in database tables.

68. How database system of Drupal works ?

Ans:

Taxonomy, a powerful core module, gives your sites use of the organizational keywords known in other systems as categories, tags, or metadata. It allows you to connect, relate and classify your website’s content. In Drupal, these terms are gathered within “vocabularies.” The Taxonomy module allows you to create, manage and apply those vocabularies.
New under Drupal 7 is the ability to add taxonomy fields to vocabularies and terms.

69. What is Database abstraction layer in Drupal ?

Ans:

Allow the use of different database servers using the same code base.Drupal provides an abstraction layer with the ability to support multiple database servers easily. The intent of this layer is to preserve the syntax and power of SQL as much as possible, while letting Drupal control the pieces of queries that need to be written differently for different servers and provide basic security checks.
Most Drupal database queries are performed by a call to db_query() or db_query_range(). Module authors should also consider using pager_query() for queries that return results that need to be presented on multiple pages, and tablesort_sql() for generating appropriate queries for sortable tables.

70. How does caching work in Drupal?

Ans:

Drupal caching system allows customized settings to speed up website using different configuration with page caching, block caching and lifetime for cached pages.

Page caching:

  • If enables, page caching will only be used for anonymous users.
  • If you enable page caching, the entire HTML of each page will be stored in the database. This significantly reduces the amount of queries needed.
  • This automatically means that blocks will also get cached, disregarded their own cache settings.
  • If Varnishis configured, this will also enable varnish caching
  • The page cache max-age will be used (see below) for each page.
  • You can check the “X-Drupal-Cache” HTTP header to check if this cache is HIT.

Block caching:

  • If you enable block caching, without enabling page caching, the block cache settings will be used (for anonymous and authenticated).
  • The defaults for most blocks is “don’t cache” because that is the default for blocks who don’t have their cache settings specifically declared.
  • You can use block_cache_altermodule to set this for each block.
  • When it’s block created by Views, you can set the cache settings for a block in Views.

Minimum cache lifetime:

  • This is the amount of time before the page cache is cleared.
  • Page caches are cleared on each cron run (system_cron).
  • Be warned: incorrect settings of your cron and this setting might kill your website performance.

Expiration of cached pages:

  • This only applies for external caching mechanisms, for example your browser cache or Varnish.
  • It sets the Cache-Control max-age value in the HTTP-HEADERS.
  • This setting only takes effect when page caching is turned on.


 

71. How do you handle upgrades in Drupal?

Ans:

Steps to Upgrade drupal minor version.

  • backing up the site,
  • putting it into maintenance mode
  • downloading the new version of the module
  • uncompressing it
  • running update.php
  • testing the site
  • taking the site out of maintenance mode

Steps to Upgrade Drupal major version.

  • Backup your existing site and database.
  • Log in as user ID 1
  • Put your site in maintenance mode
  • Change all themes to Garland
  • Disable non-core modules
  • Remove default settings file
  • Remove all old core files and directories
  • Remove uninstalled modules
  • Download Drupal 7
  • Re-apply modifications to core files
  • Make your phpfile writeable
  • Run the update script
  • Backup your database
  • Upgrade fields
  • Update contrib modules and themes
  • Check the Status Report
  • Make sure settings.php is secure
  • Check Drupal Core Modules
  • Remove your site from Maintenance Mode

72. What makes “Search” in drupal as an excellent feature than Other CMS?

Ans:

Drupal uses search indexing using content type, classification information from taxonomy system and the content meta data.
Drupal treats its content as fine-grained semantic information that Drupal knows about can be used to fine-tune search results.
Also, you can tweak and override the search system to adjust the user interface, the way content is ranked, and the way results are displayed. That said, Drupal integrates well with external search engines such as Apache Solr, Xapian, and Sphinx if the built-in search does not meet your needs very easily.

73. if we delete the page.tpl.php then drupal site will work or not?

Ans:

Yes. will work. It will check for node.tpl.php file.

74. Do you have profile on drupal site? Do you write the comments on Drupal site?

Ans:

If you have drupal profile then say yes. If not then create profile now.

75. What modules do you always recommend to your clients?

Ans:

Views, Panels, Ctools, Token, Pathauto, Webform, Rules, Features, Strongarm, Date, view slideshow, Drush, Entity Reference, QuickTab, Libraries, Google Analytics, Display Suite, Context, Module Filter, CSS Injector, Diff

76. What is the use of taxonomy and vocabulary in Drupal?

Ans:

Taxonomy, a powerful core module, gives your sites use of the organizational keywords known in other systems as categories, tags, or metadata. It allows you to connect, relate and classify your website’s content. In Drupal, these terms are gathered within “vocabularies.” The Taxonomy module allows you to create, manage and apply those vocabularies.

77. How to interact with Drupal search system ?

Ans:

The search module lets users search for specific content on your site. You can search both for users and for particular words. When you are on the “content” tab of Search, you will be able to search for words appearing in the default rendering of node content on your site, which would include the default rendering of any CCK fields, Location fields, Taxonomy, etc., as well as comments. When you are on the “users” tab of Search, you will be able to search the user names of registered users on your site, and if you have sufficient permissions, also their email addresses.

78. What does Views do and how do you use it?

Ans:

You need Views if:
You like the default front page view, but you find you want to sort it differently.
You like the default taxonomy/term view, but you find you want to sort it differently; for example, alphabetically.
You use /tracker, but you want to restrict it to posts of a certain type.
You like the idea of the ‘article’ module, but it doesn’t display articles the way you like.
You want a way to display a block with the 5 most recent posts of some particular type.
You want to provide ‘unread forum posts’.
You want a monthly archive similar to the typical Movable Type/Wordpress archives that displays a link to the in the form of “Month, YYYY (X)” where X is the number of posts that month, and displays them in a block. The links lead to a simple list of posts for that month.
Views can do a lot more than that, but those are some of the obvious uses of Views.

79. How can we modify the form validation of Drupal?

Ans:

Use form alter hook and use this “‘#required’ => TRUE”

80. What is PDO?

Ans:

PDO is an acronym for PHP Data Objects. PDO is a lean, consistent way to access databases. This means developers can write portable code much easier. PDO is not an abstraction layer like PearDB. PDO is a more like a data access layer which uses a unified API (Application Programming Interface).




 

81. What is a patch in Drupal and how will we apply patch in drupal?

Ans:

A patch is a file that consists of a list of differences between one set of files and another. All code changes, additions, or deletions to Drupal core and contributed modules/themes between developers are done through patches. The differences are presented in a structured, standard way, which means that a program (also named patch) can be used to apply the changes to another copy of the original file.

82. Explain Region, Block, Menu in drupal ?

Ans:

Pages on your Drupal site are laid out in regions, which can include the header, footer, sidebars, and main content section; your theme may define additional regions. Blocks are discrete chunks of information that are displayed in the regions of your site’s pages. Blocks can take the form of menus (which are concerned with site navigation), the output from modules (e.g., hot forum topics), or dynamic and static chunks of information that you’ve created yourself (e.g., a list of upcoming events).
There are three standard menus in Drupal: Primary Links, Secondary Links, and Navigation. Primary and Secondary links are built by site administrators, and displayed automatically in the page header of many themes (if not, you can enable their blocks to display them). Navigation is the catch-all menu that contains your administration menus, as well as links supplied by modules on your site. You can also create your own custom menus, and display them by enabling their blocks.
You can customise menus in several ways, such as reordering menu items by setting their “weight” or simply dragging into place, renaming menu items, and changing the link title (the tooltip that appears when you mouse over a menu item). You can move a menu item into a different menu by editing the Parent property of the menu item.
You can also add custom menu items to a menu, from the Add menu item tab of the Menu administration screen. To create a menu item, you will need to provide the path to the content (see above).
In all cases a menu item will only be shown to a visitor if they have the rights to view the page it links to; e.g., the admin menu item is not shown to visitors who are not logged in.

83. Difference between Region and Blocks in drupal ?

Ans:

Regions:
Regions in Drupal 7 are predefined areas in your template where content can be added to. For example, the header, footer, and sidebar are all regions.
In the example to the right, you can see the basic concept of regions in Drupal 7. There are different sections (aka regions) highlighted on the page. When you add content to your page, you’ll need to choose into which of these regions you will add the content to.
Blocks:
If you start off with a blank template, you need to fill it with content. Each piece of content that you put on your page is referred to as a block. Blocks are assigned to regions. For example, you can assign a menu (block) to your sidebar (region), or you can assign a site search form (block) to your header (region).
We’ve highlighted a few blocks in screenshot to the right. As you can see, we have a site search form (block) in our header (region). In our left sidebar (region), we have a Navigation menu (block) and a section where we typed in some custom HTML (block).

84. Name and describe the five conceptual layers in a Drupal system.

Ans:

The five layers, starting from the bottom layer, are as follows:

  • Data (nodes, etc.). Before anything can be displayed on the site, it must be input as data.
  • Modules. Modules are functional plugins that are either part of the Drupal core or are contributed modules that build on Drupal’s core functionality.
  • Blocks and menus. Blocks can be used to present anything, so just about any piece of content on a Drupal site (other than main content, breadcrumbs, and primary/secondary menus) is usually a block. Blocks are an extensible core feature of Drupal with a simple API provided by the block module. Blocks are similar to “widgets” in content management systems, but are highly generalized. Menus are a collection of links (menu items) used to navigate a website. The Menu module provides an interface to control and customize the menu system that comes with Drupal. By default, new menu items are placed inside a built-in menu labeled Navigation, but administrators can also create custom menus.
  • User permissions. User permissions are defined for various roles and users are assigned to these roles in order to grant them the defined permissions.
  • Themes and templates. The top conceptual layer of the drupal architecture is the theme. This consists primarily of XHTML and CSS, with some PHP variables intermixed, so Drupal-generated content can go in the appropriate spots. Also included with each theme is a set of functions that can be used to override standard functions in the modules in order to provide complete control over how the modules generate their markup at output time. A theme may contain one or more templates, depending on the complexity of the site and the way it has been designed.

85. What is Drupal’s taxonomy system and what are some of its key features?

Ans:

Drupal comes with a built in taxonomy system that allows for categorization of the nodes on a site.
The taxonomy system allows for arbitrary definition of terms, as well as arbitrary organization of those terms into vocabularies. There is no limit to the number of vocabularies that can be created, nor is there any limit to the number of terms that can be included in a vocabulary.
A vocabulary can also have free tagging which means that, instead of entering specific terms ahead of time, users may enter tags freely at the time the content is created and those tags automatically become terms in that vocabulary.
Drupal’s taxonomy system is one if its most powerful and flexible features.

86. Describe the Field API that was introduced into core in Drupal 7.

Ans:

The Field API allows custom data fields to be attached to Drupal entities and takes care of storing, loading, editing, and rendering field data. Any entity type (node, user, etc.) can use the Field API to make itself “fieldable” and thus allow fields to be attached to it. Other modules can provide a user interface for managing custom fields via a web browser as well as a wide and flexible variety of data type, form element, and display format capabilities.
The Field API defines two primary data structures, Field and Instance, and the concept of a Bundle. A Field defines a particular type of data that can be attached to entities. A Field Instance is a Field attached to a single Bundle. A Bundle is a set of fields that are treated as a group by the Field Attach API and is related to a single fieldable entity type.
For example, suppose a site administrator wants Article nodes to have a subtitle and photo. Using the Field API or Field UI module, the administrator creates a field named ‘subtitle’ of type ‘text’ and a field named ‘photo’ of type ‘image’. The administrator (again, via a UI) creates two Field Instances, one attaching the field ‘subtitle’ to the ‘node’ bundle ‘article’ and one attaching the field ‘photo’ to the ‘node’ bundle ‘article’. When the node system uses the Field Attach API to load all fields for an Article node, it passes the node’s entity type (which is ‘node’) and content type (which is ‘article’) as the node’s bundle. field_attach_load() then loads the ‘subtitle’ and ‘photo’ fields because they are both attached to the ‘node’ bundle ‘article’.
Field definitions are represented as an array of key/value pairs.

87. Explain the concept of “nodes” in a Drupal system.

Ans:

All content on a Drupal website is stored and treated as “nodes”. A node is any piece of individual content (e.g., a page, article, forum topic, blog entry, etc.). Note, though, that omments are not stored as nodes but are always connected to a node.
The ability to create different “content types” is a way Drupal allows you to have different kinds of nodes for different purposes. For example, an “article” is one content type, a “book page” is another, and a “blog entry” yet another. You can also create new content types of your own.
Treating all content as nodes provides a great deal of flexibility that facilitates and simplifies creating new types of content. It also makes it easy to apply new features or changes to all content of a particular type.

88. Describe the features and uses of the Views module.

Ans:

Using the Views module, you can fetch content from the database of your site and present it to the user as lists, posts, galleries, tables, maps, graphs, menu items, blocks, reports, forum posts etc. Different content types including nodes, users, and other bundles can be displayed.
Views UI, a submodule within Views, provides a graphical interface underneath which lies a powerful SQL query builder that can access virtually any information in your database and display it in any format.
Different displays can present the query results as pages with fixed URLs on your site (or URLs accepting arguments), blocks, feeds, or panel panes.
You can also use Views to present related content or implement contextual filters. For example, you can display a list of users along with links to the content they have created and/or you can display customized content to a user according to their user ID.

89. What are appropriate use cases for Drupal as opposed to a lower-level framework like Ruby on Rails?

Ans:

Rails is a general purpose web application framework for Ruby. It’s designed to help programmers be more productive in building web sites of all types, not just CMSs. And note that it’s for “programmers”. Unless you intend to write server-side code, you can’t hope to get much done with just Rails alone (but if you do intend to write code, both Ruby and Rails are known to be very productive).
Drupal is a Content Management System, of which there are hundreds. It happens to be written in PHP, but it’s modular design and large collection of available modules and themes make it possible to design and implement a large variety of web sites without writing a line of code. Most importantly, though, it is fundamntally a CMS. The further your site’s needs are from the CMS sweet-spot, the less likely it is that Drupal will be your best choice.

90. Explain the “hook” system in Drupal. How and why would you use it?

Ans:

Drupal’s hook system is essentially a mechanism for implementing custom features without needing to make any modifications to the Drupal core. There are specific places where the Drupal core can invoke custom functions defined in modules to enhance the functionality of core. These places are referred to as “hooks” and have a well-defined interface.
Hooks make it possible, for example, for a module to define new URLs and pages within a site (hook_menu), to add content to pages (hook_block, hook_footer, etc.), set up custom database tables (hook_schema), and so on.
Let’s say you want to change the core “Contact” form. To do so, you can implement hook_form_alter in your custom module and provide any cuistom functionality that you’d like in that function. Drupal will check all form_alter hooks in all modules, so your hook will be picked up and your custom code will be applied to the “Contact Form”.
So overall, Drupal hooks are just functions defined per the Drupal standards that allow you to extend Drupal and alter or extend core functionality without modificing any core code.


 

91. How to drop the table using module?

Ans:

Use db_drop_table method in install file