Hot Lines

Loading...

Tuesday, July 12, 2011

Interview Questions & Answers in Drupal

  1. Whether drupal is written in procedural-style or object oriented? (Procedural oriented)
  2. why not object oriented? ( when drupal is in initial stage, PHP is not full integrated with OOPS. Also absence of class and constructors. )
  3. Why Drupal? Advanced URL Control,Custom Content Types and Views,Revision Control,Taxonomy,User Management,Page Titles and Meta Tags,Excellent Documentation,PHP Template, Drupal Cookbooks, Large and Friendly Community
  4. How does drupal know when to invoke a module to handle the particular request? ( This is done by hook mechanism. Drupal check currently enabled modules and find the call back functions and then execute it ).
  5. how can we prevent to load all the modules while the page is render? (we can change the module_load_list function in module.inc. Here we can set the modules to load based on the page.)
  6. what are the three argument for hook_block? ($op,$delta,$edit)
  7. what are the possible values for $op?
    1. list :- This is passed when the module should provide information about itself.
    1. view :- This value is passed in $op when Drupal expects the block hook to
      provide content for displaying to the user.
    2. configure :- This value is passed when Drupal expects an administration
      form used to configure the block.
    3. save :- value is passed when configuration information from the form
      data generated by configure needs to be saved.
  1. $delta contains extra information about what content should be displayed.
  1. $edit parameter is used during configuration.
  2. what is the purpose of the t()?. This is translation function. Its is used to provide multi-language support. To do this, we need to enable the content translation module.
  3. what are the placeholders? !,@,%
  4. how do declare private function & purpose? leading underscore char in the function name tells that its private function. function _test(). its called by other function with in the module.
  5. How to you prevent the XSS (cross site scripting)? we can use check_plain(). It will encode the HTML tags into  entities. check_plain('<em>Example</em>') would return the
    string &lt;em&gt;Example&lt;/em&gt;.
  6. what is the disadvantage of check_plain? if encounter the HTML entity then it will encode again. Ex. &lt; would become &amp;lt;. The initial ampersand (&) is encoded into &amp;.
  7. what is derivative theme? Derivative theme is theme. its derive the CSS,images and JS from parent theme. To call the parent theme, we need to call them basetheme = themename in theme.info file.
  8. Advantage and disadvantage of derivative theme? It call the CSS,images and JS from parent theme except the info file of parent theme. it can override the behavior of parent. Disadvantage :- if CSS or images changed in parent it will reflect into derivative theme too.
  9. what is derivative theme of garland? minelli
  10. why we put our custom module in sites/all/ path? To keep the core and custom modules in different location. If we upgrade into new version, then custom modules won't affect.
  11. styles[all][]. what is mean by [all] :-  It [all] indicates that media type of pages the given style sheet should be used in. common media types are screen, print. so that, we are using styles[print][] in some case.
  12. All the engines are not having the template.tpl.php. but chameleon theme having the template.tpl.php without using any engines.
  13. Difference between theme and theme_function? theme() makes use of the full theme system. theme_hook function directly may cause your application to ignore
    the current theme configuration and use only the default. themes better than use theme_hook. (theme, check the function (phptemplate_image) or template (image.tpl.php) that overrides the theme_function, if function found then that used as.) theme_hook can overrides by templates like image.tpl.php
  14. The template.php file provides a convenient way to override the default theme behavior. It also provides access to data before the data is handed on to the template. Accessing such data before it is themed is called preprocessing.
  15. Template.php Gotchas:-
    1. you can only override a theme function once. While this seems simple, there is one circumstance in which this may be surprising. While you can declare a template.php file in a sub-theme even if there is a template.php in the parent, you cannot override functions declared in the parent. If the parent's template.php declares phptemplate_breadcrumb(), then the sub-theme's template.php cannot declare phptemplate_breadcrumb(). Doing so will result in a PHP errors for redeclaring a function.
    1. we have seen that theme hooks (theme_<hookname>()) (theme_block) can be overridden by PHPTemplate templates (block.tpl.php) and also by functions (phptemplate_block) in the template.php file. But what happens if you declare both?
      The phptemplate_<hookname>() function overrides the theme function that would otherwise load the template. Therefore, if phptemplate_block() is defined in template.php and there is a template named block.tpl.php, the phptemplate_block() function will be called to render all blocks, and the block.tpl.php file will never be used.
    2. If you need to manipulate some content before it is passed to a template, don't do this by defining phptemplate_<hookname>(). Instead, use one of the preprocessor
      functions, such as phptemplate_preprocess_block(), phptemplate_preprocess_node(), or phptemplate_preprocess_page().
  1. while we use drupal_goto and $form['#redirect'], drupal_goto overrides the $form[#redirect];
  1. Table name placeholders ({node}) provide administrators the ability to change table names to better fit existing conventions. For example, some ISPs require that all tables have certain pre-determined prefixes. By using table name placeholders, we can avoid the need to make changes to code when table names are changed in the database.
  2. what will happen if admin delete the user account suppose the user logged in the site? If user is in my account page, then its shows page not found. If user is in common page (ie, static page, access for all) then simply it will be in same page.
  3. what is the purpose of the table placeholders in query? Some ISPs require that table prefixes. In that case, we can simply give the prefix in settings.php and add the prefix to add all the tables. No need to change that in code of modules.
  4. Note that instead of hook_form_alter(), which is called for all forms, you can also use hook_form_FORM_ID_alter() to alter a specific form.
  5. how to delete module via application?
  6. what is the difference between l() & Url()? Both is used to format the link. l() handles the aliased paths, and allows themes to highlight links to the current page correctly. we can use l() than url();
  7. The data is divided between two tables: {menu_router} and {menu_links}. The {menu_router} table is built based on the callbacks defined by implementations of hook_menu, and Drupal now looks in this table to determine access and the appropriate callback function when a site visitor tries to navigate to a particular path. Everything belonging to one path is one row in a database table, so the memory footprint is significantly smaller. The inheritance rules for access, etc. are cleanly laid out in the documentation. The {menu_links} table contains the links that are displayed in the Navigation and other menu blocks. Some of these items are derived automatically from {menu_router}, but others may be added by the site administrator using the menu module or other modules. 
  8. When you open a page, then the system will generate the ancestors of the given path, and ask the database for the menu entry of the ancestor which best fits this path. Then it calls the access callback to determine access. If it's given, then it hands over execution to the page callback.
  9. What is ancestors:- node/12345/edit, node/12345/%, node/%/edit, node/%/%, node/12345, node/%, node. These we call the ancestors of node/12345/edit.
  10. What is fitness:-  So let's add fitness number to these paths:
  11. Path Fitness Fitness in binary
  12. node/12345/edit 7  111
  13. node/12345/% 6  110
  14. node/%/edit 5  101
  15. node/%/% 4  100
  16. node/12345 3   11
  17. node/% 2   10
  18. node 1    1
  19. What will happen if page call back is not defined?
  20. If a page callback is not defined for a path, then we look at the closest parent that has one and use it. If the page callback is inherited from a parent, then the page arguments, the file and the file path are inherited from the parent as a whole, but can be overridden. Most of the time it is only required to overwrite the page arguments and nothing else.
  21. What will happen if parent also not defined? It will display you are not authorized to access the page
  22. why only a title column exists for nodes in the node table and not a body?
  23. What will happen, if our page callback & core module page callback same? for example  if we have 'contact' as page callback when we enabled the core contact module. Ans:- Existing call pack will be overridden by Newly created page callback.
    Theming :-

  24. Theme name should start with an alphabetic character and contain no spaces or punctuation. Underscores are allowed but not hyphens.
  25. Warning! Modules bearing the same internal name as a theme can prevent a site from functioning. This may cause duplicate function names, which are illegal in PHP. All installed components must have unique names. For locally created themes using a prefix that is likely to be unique is good for theme naming. A site example.com might call its themes ex_themename.
  26. Define  Java scripts in .info :- scripts[] = validate.js (External javascript files can not be include)
  27. Engines in .info file:-  engine = phptemplate. it will discover the theme functions and templates for the behavior of themes.
  28. Regions names should contain alphanumeric characters and underscores.
  29. Assign the contents into regions manually by drupal_set_contents('region name' , 'output content'); 
  30. Making settings available to the administration page :-  In .info file, we can mention which is need to enable by features[] = logo
  31. Create new form filed in theme settings page :- we need to create the theme-settings.php in theme folder. http://drupal.org/node/177868

1 comment: