EzDevInfo.com

drupal interview questions

Top drupal frequently asked interview questions

CSS to hide INPUT BUTTON value text

I am currently styling an <input type='button'/> element with the following CSS:

background: transparent url(someimage);
color: transparent;

I want the button to show as an image, but I don't want the value text to display on top of it. This works fine for Firefox as expected. However, on Internet Explorer 6 and Internet Explorer 7 I can still see the text.

I have tried all sorts of tricks to hide the text, but without success. Is there a solution to make Internet Explorer behave?

(I am constrained to use type=button because this is a Drupal form and its form API doesn't support image-type.)


Source: (StackOverflow)

Working with version control on a Drupal/CMS project

I was wondering how teams that develop sites using Drupal (or any other CMS) integrate version control, subversion, git or similar, into their workflow. You'd obviously want your custom code and theme files under version control but when you use a CMS such as Drupal a lot of the work consists of configuring modules and settings all of which is stored in the database.

So when you are a team of developers, how do you collaborate on a project like this? Dumping the database into a file and putting that file under version control might work I guess, but when the site is live the client is constantly adding content which makes syncing a bit problematic.

I'd love to know how others are doing this.


Source: (StackOverflow)

Advertisements

What are some of Drupal's shortcomings? [closed]

Drupal is very much a "Do Everything" CMS. There are modules that allow you to add almost any functionality, which is great. However, it feels like a lot of the features (v5 and v6) seem scattered around and unintuitive for the user. As a developer, I'm left with the feeling of having patched a site together using bubble gum and string.

For example, to add text to the default search box (that disappears when clicked), you have to either add some jQuery code OR override the theme. I've also found the menu system more complicated than it should be.

Am I the only one with this opinion? What things (if any) would you change about Drupal's core?


Source: (StackOverflow)

Adding text (just text!) to a form in Drupal 7 [closed]

OK, I finally figured out how to add (or edit) form controls through the form API in Drupal.

But now, I would like to add text to a form. Not a <textarea>, and not a <textfield>; both of which can be edited by the user. I would like to add <p>static text</p>, written by me, to be read by the user.

How would one do that?


Source: (StackOverflow)

Attaching image files to nodes programmatically in Drupal 7

Is it possible to add an image to a node programmatically?


Source: (StackOverflow)

Favorite Drupal tips or best practices? [closed]

Just wondering what tips or tricks you guys might have to share. As always with posts like this, please only one tip per post so they can be voted on independently.

I'll start: however you do your theming, you can use the mothership theme as a base theme for your theme to inherit from so that your markup will be a lot cleaner and less verbose.


Source: (StackOverflow)

displaying a Drupal view without a page template around it

I would like to display a Drupal view without the page template that normally surrounds it - I want just the plain HTML content of the view's nodes.

This view would be included in another, non-Drupal site.

I expect to have to do this with a number of views, so a solution that lets me set these up rapidly and easily would be the best - I'd prefer not to have to create a .tpl.php file every time I need to include a view somewhere.


Source: (StackOverflow)

How to find version of Drupal installed

How can I know which version of Drupal is installed in my server?


Source: (StackOverflow)

Adding a class to "body"

How can I modify or pre-process the <body> tag to add the class body? I don't want to create a whole html.tpl.php just to add a class.


Source: (StackOverflow)

Does Drupal comply with the MVC paradigm?

Drupal is frequently referred as a Content Management Framework, does it comply with the MVC paradigm? If it does, how Drupal implements MVC?

Thanks.


Source: (StackOverflow)

How to quickly theme a view?

I've defined a view with the CCK and View 2 modules. I would like to quickly define a template specific to this view. Any tutorial or information on this ? What are the files I need to modify ?


Here are my findings: (Edited)

In fact there are two ways to theme a view : the "field" way and the "node" way. In "edit View", you can choose "Row style: Node", or "Row style: Fields".

  • with the "Node" way, you can create a node-contentname.tpl.php wich will be called for each node in the view. You'll have access to your cck field values with $field_name[0]['value']. (edit2) You can use node-view-viewname.tpl.php wich will be only called for each node displayed from this view.
  • with the "Field" way, you add a views-view-field--viewname--field-name-value.tpl.php for each field you want to theme individually.

Thanks to previous responses, I've used the following tools :

  • In the 'Basic Settings' block, the 'Theme: Information' to see all the different templates you can modify.
  • The Devel module's "Theme developer" to quickly find the field variable names.
  • View 2 documentation, especially the "Using Theme" page.

Source: (StackOverflow)

Creating list of similar nodes in Drupal 7/Views 3

Copy from drupal.stackexchange.com hoping to get more answers here:

I face a rather common problem of displaying a list of nodes similar to current one. Similar node is defined as one having at least one taxonomy term that current node has. There are few solutions available as modules, however the modules I've found (specifically Similar By Terms) are in beta stage (as in "not working properly") for Drupal 7.

I've also found a couple of solutions based on Views and contextual filters (such as http://scito.ch/content/show-related-nodes-block-based-taxonomy-terms-views-3-and-drupal-7) or relations. I quite like this way as it saves me installing extra modules and with Views being actively developed and supported I'd prefer to use them rather than any custom solution. The problem I can't get around is how to sort "similar nodes" by the number of terms they share. For example, if I have "IPhone 4S" Node with Terms "Gadget", "Apple", and "Phone", I want similar nodes in the following order:

  1. IPhone 3 (Apple, Gadget, Phone)
  2. IPad (Apple, Gadget, Tablet)
  3. Mac (Apple, Computer)
  4. Bramley (Apple, Fruit, Tree)

How can I sort nodes in this view by the number of terms they share?

This question is about building a view, please do not suggest module or custom php-based solutions. Thank you.


Source: (StackOverflow)

How to output (to a log) a multi-level array in a format that is human-readable?

I'm working on a drupal site and when debugging, I am always having to read through long, nested arrays. As a result, a large portion of my life is spent using the arrow, return, and tab keys, to split up 1000+ character strings into a nested, readable format.

For drupal devs, I can't use devel's dsm(), as I'm working with multi-step #ahah/#ajax forms, and I can only output the arrays to the error log, not to the screen.

Visual example:

Evil:

array ( 'form_wrapper' => array ( '#tree' => true, '#type' => 'fieldset', '#prefix' => '', '#suffix' => '', '#value' => '', 'name' => array ( '#type' => 'textfield', '#title' => NULL, '#size' => 60, '#maxlength' => 60, '#required' => false, '#description' => NULL, '#attributes' => array ( 'placeholder' => 'Email', ), '#post' => array ( 'form_wrapper' => array ( 'name' => '', 'pass' => '', ),
...

Good:

array ( 
'form_wrapper' => array ( 
    '#tree' => true, 
    '#type' => 'fieldset', 
    '#prefix' => '<div>', 
    '#suffix' => '</div>', 
    '#value' => '', 
    'name' => array ( 
        '#type' => 'textfield', 
        '#title' => NULL, 
        '#size' => 60, 
        '#maxlength' => 60, 
        '#required' => false, 
        '#description' => NULL, 
        '#attributes' => array ( 
            'placeholder' => 'Email', 
        ), 

Edit: Sorry, by "not output to screen", I meant via drupal's system messages where it's possible to output arrays in a clickable, nested format (using devel.module).


Source: (StackOverflow)

How are people handling content management system production staging?

I've been dipping my toe into web development technologies for fun (ya, i should get out more), and am a little shocked at the lack of clear support for production staging (i.e. development, testing, performance, and production environments). Actually support isn't the word; Content Management Systems seem to actively work against efforts to allow for clean staging.

Currently I am using Drupal. I have had a very hard time finding how the community solves this problem. Most of the posts I've seen recommend reproducing the steps done in development on the production system (reading this actually shortened my life a small bit). I also hear of pushing production data back to the developers so they can add incremental features. This can't be the way to go, what if the client doesn't want you pulling their data back to your development environment?

So finally my question:

How are you managing real world production staging issues for a CMS?

I come from a background where pushing to production feels like sending people to the moon, so I may need to relax a little bit. However I am still interested answers that involve source control, allow for production rollback, and testing.


Source: (StackOverflow)

Using JQuery in Drupal 7

I'm writing my own Drupal 7 module, and like to use JQuery in it.

$('#field').toggle();

But I'm getting this error:

TypeError: Property '$' of object [object DOMWindow] is not a function

It seems that JQuery is not loaded. Otherwise $ should be defined.

Though I actually include it in the header:

<script type="text/javascript" src="http://rockfinder.de/misc/jquery.js?v=1.4.4"></script>

Do I have to do anything else to activate JQuery in Drupal? Is $ being overwritten by Drupal?

That's the website: http://rockfinder.orgapage.de


Source: (StackOverflow)