Wednesday, 15 April 2015

what is entity in Drupal 7

Answer:- In Drupal 7 each individual node, user, term and comment is now called an entity.
Nodes (content), comments, taxonomy terms and users profiles are now called entity types.

 You can also build new kinds of entity types where the options above don't suit your needs. For more information, read further about using the hook_entity_info and extension by Entity API: entity_crud_hook_entity_info.

In OOP terminology concept of entities is like:
  • An entity type is a base class
  • A bundle is an extended class
  • A field is a class member, property, variable or field instance (depending on your naming preference)
  • An entity is an object or instance of a base or extended class

Bundles

Bundles are an implementation of an entity type to which fields can be attached. You can consider bundles as subtypes of an entity type. With content nodes (an entity type), for example, you can generate bundles (subtypes) like articles, blog posts, or products.

Fields

A field is a reusable piece of content. In technical terms, each field is a primitive data type, with custom validators and widgets for editing and formatters for display.

Entity

An entity would be one instance of a particular entity type such as a comment, taxonomy term or user profile or a bundle such as a blog post, article or product.
You can use entity_load to load any entity. Note, however, that the core does not provide a save or delete function, but thanks to Entity API module the missing pieces are added (entity_create(), entity_save(), entity_delete(), entity_view() and entity_access()).

Difference b/w Drupal 6 concept of nodes and Drupal 7 concept of entities

Imagine that you want to collect more than information when people leave comments. If you want to collect more than name, email and comment, you can add a field. For example, you might want to allow commenters to leave a link to their homepage. Let's assume that is the case for our Article content type.

This was not possible in Drupal 6 with concept of nodes but with Drupal 7 it is in following manner:
  1. Click on Structure in the black admin menu bar
  2. Click on Content types
  3. Click on Manage fields for the Article content type
  4. Observe the tabs shown in the screen shot above.
  5. You have the option to add fields to the content type via the Manage Fields tab and you have the option to add fields to comments via the Comment Fields tab. The fields you add to the Article content type will not automatically apply to comments on other content types.
 In Drupal 6 and before, users and comments didn't have the same power that nodes (content) had. They couldn't have translations, fields, versioning, and so on. It also meant that systems such as Views, which relied on controlling the selection and listing of fields didn’t work as well with comments and users.

what is the Difference between Drupal 6 and Drupal 7

Content Construction Kit (CCK)

Content Construction Kit (CCK) has moved to core in the Drupal 7.
Custom data fields are available to nodes, users, comments and taxonomy terms.
Fields are translatable.

Entity

Entities were introduced in Drupal 7.
An entity would be one instance of a particular entity type such as a comment, taxonomy term or user profile or a bundle such as a blog post, article or product.
You can use entity_load to load any entity. Note, however, that the core does not provide a save or delete function, but thanks to Entity API module the missing pieces are added (entity_create(), entity_save(), entity_delete(), entity_view() and entity_access()).

Security

  • Modules can be updated via the web.
  • More secure log-in system.
  • More secure password system.
  • More secure implementation for scheduled tasks (cron.php).

Update Manager

Introduced an Update manger in Drupal 7 which perform updates directly through the administration interface.

File handling

  • Files are now first class Drupal objects with file_load(), file_save(),and file_validate() functions and corresponding hooks.
  • Files use PHP stream wrappers to enable support for both public and private files and to support pluggable storage mechanisms and access to remote resources (e.g. S3 storage or Flickr photos).
  • Added a field specifically for uploading files, previously provided by the contributed module FileField.

Image handling

  • Improved image handling, including better support for add-on image libraries.
  • Added a field specifically for uploading images, previously provided by the contributed module ImageField.

Search

Improved search support language-aware searches

Database

  • Added query builders for INSERT, UPDATE, DELETE, MERGE, and SELECT queries.
  • Support for master/slave replication, transactions, multi-insert queries,delayed inserts, and other features.
  • Added support for the SQLite database engine.
  • Default to InnoDB engine, rather than MyISAM, on MySQL when available for greater scalability and data integrity.

jQuery

  • Upgraded the core JavaScript library to jQuery version 1.4.2.
  • Upgraded the jQuery Forms library to 2.36.
  • Added jQuery UI 1.8, which allows improvements to Drupal's user experience.

Multisite

Better Support for Multisite Installations

Installer can be run from the command line

Added RDF support

 

what is Drupal weight?

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.

how to add extra fields in druapl registration form

Answer:-Use profile module. In drupal 7 Profile is in core.

How can add the Captcha in registration page for drupal?

Answer:-Use the captcha and recaptcha module.

What is the use of taxonomy and vocabulary in Drupal?

Answer:-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.

List the SEO modules available in Drupal.

Answer:-
Pathauto
Nodewords/ Meta tags
Service links
Google analytics
Related Links
Search 404
Site map
Url list

List the modules required for building a social networking website in Drupal.

Answer:-
• Advanced Forum
• Advanced Profile Kit
• Application Toolbar (Appbar)
• Author Pane
• Buddylist2 Package
• Buddylist: list your social network
• CiviCRM: manage community contacts, relationships, and activities
• CiviNode and CiviNode CCK: Tools For Integrating CiviCRM Contacts Into Drupal Content
• Comment Notify
• FOAF: friends of a friend
• Facebook-style Statuses
• Family: Record, display, and analyze genealogical data.
• Flag Friend
• Friend
• FriendList
• Front: Show group membership and events
• Gigya Socialize Module
• Invite: send invitations to join your site
• Notice Feed
• Organic Group
• Profile Setup
• Radioactivity
• Sports Pickem
• Tellafriend Node
• User Invite
• User Relationships
• UserTag:Tag …

Which ORM is used in Drupal 7?

Answer:-Doctrine

What is the use of Drupal features module?

Answer:-The features module enables the capture and management of features in Drupal. A feature is a collection of Drupal entities which taken together satisfy a certain use-case.
Features provides a UI and API for taking different site building components from modules with exportables and bundling them together in a single feature module. A feature module is like any other Drupal module except that it declares its components (e.g. views, contexts, CCK fields, etc.) in its .info file so that it can be checked, updated, or reverted programmatically.

What is Drupal Panel module

The Panels module allows a site administrator to create customized layouts for multiple uses.
At its core it is a drag and drop content manager that lets you visually design a layout and place content within that layout.
Integration with other systems allows you to create nodes that use this, landing pages that use this, and even override system pages such as taxonomy and the node page so that you can customize the layout of your site with very fine grained permissions.

Which Drush commands you use while development?

Answer:-
Drush cc – clear cache
pm-disable (dis) Disable one or more extensions (modules or themes).
pm-download (dl) Download projects from drupal.org or other sources.
pm-enable (en) Enable one or more extensions (modules or themes).
pm-info (pmi) Show detailed info for one or more extensions (modules or themes).
pm-list (pml) Show a list of available extensions (modules and themes).
pm-refresh (rf) Refresh update status information.
pm-releasenotes
(rln) Print release notes for given projects.
pm-releases (rl) Print release information for given projects.
pm-uninstall Uninstall one or more modules.
pm-update (up) Update Drupal core and contrib projects and apply any pending database updates (Same as pm-updatecode + updatedb).
pm-updatecode (upc) Update Drupal core and contrib projects to latest recommended releases.

For better search what we can do in Drupal 7?

Answer:-Use the Solr module

For Drupal module development code review which module can be used?

Answer:-Use the the coder moduble

What is responsive theme?

Answer:-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.

How to drop the table using module?

Answer:-Use db_drop_table method in install file

How to create the table using Drupal module?

/* 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() {
    variable_del(‘module_name_default’);
}

/* 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;
}

How can we improve the Drupal site performance?

Answer:-Use following modules
1) PHP APC

2) Memcache

3) Varnish - an advanced and very fast reverse-proxy (to understand reverse-proxy visit here)system. Basically, Varnish handles serving static files and anonymous page-views for your site much faster and at higher volumes than Apache, in the neighborhood of 3000 requests per second

Note: In case of Drupal 6 it is advisable to use pressflow as it offers integration with Varnish and allows for MySQL replication. If you have mostly anonymous traffic, using Varnish as a reverse proxy cache is the most effective change you can make to improve performance.

4) Boost- provides static page caching for Drupal enabling a very significant performance and scalability boost for sites that receive mostly anonymous traffic

5) Views Cache
6) Block Cache
7) CDN
8) JavaScript Aggregator
9) CSS GZip

How can we set the region in drupal theme?

Answer:-You can set the regions in themename.info file. Following is the example:
regions[header] = Header
regions[content_header] = Content Header
regions[content] = Content
regions[sidebar_second] = Right sidebar

How can prevent or restrict multiple login in drupal

Answer:-Use the Session Limit Module – https://drupal.org/project/session_limit

What is use of template.php file?

Answer:-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.

How to use preprocess function?

Answer:-The main role of the preprocessor is to set up variables to be placed within the template (.tpl.php) files. From Drupal 7 they apply to templates and functions, whereas in Drupal 6 preprocess functions only apply to theming hooks implemented as templates

How PDO used in drupal?

Answer:-PDO is an acronym for PHP Data Objects. PDO is a more like a data access layer which uses a unified API to provide developers 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

What is Drush – how drush is used?

Answer:-Drush is a command line shell and scripting interface for Drupal

which are the most common or popular modules used in Drupal project?

Answer:-
Administration:
1) Administration Menu:
2) 
1) Ctools (Chaos Tools) : is a set of APIs that assist other modules.
CTools is used by Views, Views Slideshow, Webform. It's also required by popular layout modules such as Panels and Display Suite

2) Views:
3) Token: allows you to create re-usable patterns across your site. For example, the Pathauto module (#5 in this list) uses Token to create URL patterns. Here are some examples of Token in action:
  • Automatically generate node titles
  • Automatically create metadata
  • Automatically change usernames

4) Libraries API: It's an essential part of the WYSIWYG and Colorbox module and powers several Views Slideshow features.
5) Path Auto: creates clean, keyword rich URLs in Drupal.
6) Entity API: Entity API provides a unified way to deal with entities.
Entity API is an essential part of the Rules, Features and Search API modules amongst others.
7) Webform
8)
9) Date:allows you to add Date fields to your Drupal content. It also has an API so that other modules can more easily handle the complexity of dates (timezones etc)
10) IMCE
11) WYSIWYG
12) Google Analytics
13) CKEditor
14) Link: allows you to add a field with links to external websites
15) Backup and Migrate: simplifies the task of backing up, restoring or moving your Drupal site
16) Rules: is used to automate actions on your Drupal site. You can make site changes automatically, based on "rules" ... if X happens, then do Y.
17) Module Filter: The Drupal modules page can become very long and difficult to navigate once you've installed a lot of modules. Module Filter provides a much better interface for navigating through a long list of modules.





, Devel, Drush, Views, Backup & Migrate, Date, Address field, file field, link, media, Rules, SMTP, View Slideshow, Print,
Lightbox2, Varnish, memcache, Wysiwyg, ckeditor, Google Analytics, Metatag, XML Site Map, Redirect, Page Title, Chaos Tools,Token, Entity, Panels, Features, Coder

Which files are required for a Drupal module?

Answer:-
modulename.info,
modulename.module,
optional modulename.install

Which files are required for theme in Drupal?

Answer:-
style.css
template.php 
page.tpl.php
node.tpl.php
block.tpl.php
info file 

How to do debugging in drupal

Answer:- use devel module

What is hooks in Drupal?

Allow modules to interact with the Drupal core.
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.

Explain the menu system in Drupal? Purpose of menus?

Drupal’s menu system follows a simple hierarchy defined by paths.
Implementations of hook_menu () define menu items and assign them to paths (which should be unique).
The menu system aggregates these items and determines the menu hierarchy from the paths.

When responding to a page request, the menu system looks to see if the path requested by the browser is registered as a menu item with a callback. If not, the system searches up the menu tree for the most complete match with a callback it can find,
The found callback function is called with any arguments specified in the “page arguments” attribute of its menu item. The attribute must be an array. After these arguments, any remaining components of the path are appended as further arguments. 

Access to the callback functions is also protected by the menu system. The “access callback” with an optional “access arguments” of each menu item is called before the page callback proceeds. If this returns TRUE, then access is granted; if FALSE, then access is denied.

Everything is stored in the menu_router table.
The menu_links table holds the visible menu links.
By default these are derived from the same hook_menu definitions, however to add more use menu_link_save ().

How to interact with Drupal search system?

Answer:- There are three ways to interact with the search system:
1) Specifically for searching nodes, you can implement nodeapi (‘update index’) and nodeapi (‘search result’). However, note that the search system already indexes all visible output of a node, i.e. everything displayed normally by hook_view () and hook_nodeapi (‘view’). This is usually sufficient. You should only use this mechanism if you want additional, non-visible data to be indexed.
2) Implement hook_search (). This will create a search tab for your module on the /search page with a simple keyword search form. You may optionally implement hook_search_item () to customize the display of your results.
3) Implement hook_update_index (). This allows your module to use Drupal’s HTML indexing mechanism for searching full text efficiently.
If your module needs to provide a more complicated search form, then you need to implement it yourself without hook_search (). In that case, you should define it as a local task (tab) under the /search page (e.g. /search/mymodule) so that users can easily find it.

How to Customize my Drupal Syndicate Feed Icon?

Answer:- by overriding theme_feed_icon($url, $title)

How do I Remove Breadcrumbs from my Drupal pages?

Answer:- hide it using CSS (eg. .breadcrumb {display: none;}) or in the page.tpl.php file remove the line that says <?php if ($breadcrumb) print $breadcrumb; ?>

How can I add custom PHP codes in my Drupal pages or blocks?

Answer:- By default, drupal will not allow inserting PHP code directly inside a post or in a block.
To do this, you need to activate a drupal module called PHP filter via, Administer » Site building » Modules. Even though this module ships with drupal, it remains disabled by default.

How can I add a new Block In Drupal?

Answer:- Adding a new block is a simple process in drupal 6.
·         Go to Administer » Blocks and click on the Add Block link (tab).
·         Fill in the form with the necessary PHP/HTML code in the block body. 
      Click the ‘Save Block’ button.

How can I customize my 404 – Page not found page?

Answer:- Create a new page with some extra information.
Once this page is created:
·         Remember its node ID,
·         Go to Administer > Site configuration > Error reporting
·         Set Default 404 (not found) page to the node ID you just created
·         Save your settings
You can also use the Search 404 module as an alternative.

How do handle drupal upgrades?

Answer:- 
·         backing up the site (using Administer » Content Management » Backup and Migrate module or taking backup using PHPMyAdmin),
·         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

How do I show different Drupal themes on different pages?

Answer:- using module called ‘Sections’.

How do I add images to Drupal?

Answer:- Image module allows users with proper permissions to upload images into Drupal. Thumbnails and additional sizes are created automatically.

How do I remove the title ‘Navigation’ from the navigation block?

Answer:- Navigate to
Administer » Site building » Blocks
and click the configure link next to the Navigation block.
In the block configuration page, enter <none> in the Block title filed.
This will override the default title for the block and remove the title.

How do I get my site to have SEO-friendly URLs?

Answer:- The Pathauto module automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users) without requiring the user to manually specify the path alias. This allows you to have URL aliases like /category/my-node-title instead of /node/123. The aliases are based upon a "pattern" system that uses tokens which the administrator can change

How can I enable clean URLs in Drupal?

Answer:-  Navigate to 
Administer » Site configuration » Clean URLs. 
By default, it will be disabled. Select enabled and click the save configuration button. You are done.
You can make your URLs even more cleaner with the help of path module.
Home » Administer » Site building » Modules: enable the Path Module.

How can I change the favicon in my Drupal Site?

Answer:-Navigate to
admin » site building » themes
and click the configure link next to your current theme.
This will bring up the theme configuration page.Here you will see a section titled Shortcut icons settings.
You can either upload your favicon file or specify the path to your customized icon file.
The changes may not appear immediately in your browser, you need to clear your browser’s cache and reload the page.
If you have bookmarked your site, you may need to delete the bookmark and then recreate it again so that the new favicon will appear in the bookmarks menu.

How to make my Drupal site offline to public, while it is under construction?

Answer: - You can set your Drupal site in off-line mode, while it is being developed.
Just click
Administer » Site maintenance.
There you can set the status to off-line. If you wants, you can also set your own custom off-line message. When set to Off-line, only users with the administer site configuration permission will be able to access your site to perform maintenance; all other visitors will see the site off-line message configured there.
Authorized users can log in during Off-line mode directly via the user login page.

How do I access the Drupal admin panel, when the login block is disabled?

Answer :- In those cases, we can access the login screen simply through the following URL.
http://sitename.com/?q=user
or if the clean URL is enabled
http://sitename.com/user
Similarly if you can’t access the logout link and need to logout, you can do so by using the URL
http://sitename.com/?q=logout
alternatively with clean URLs enabled you can try
http://sitename.com/logout