title: Using a Drupal 6 tutorial for Drupal 7

text:
# Question
Title: Using a Drupal 6 tutorial for Drupal 7
I hate making posts like this because I feel like I am asking people to do all my work for me! However, in times like this, when I am pressed for time, I have to.

I am trying to add an user profile in the topics in the Forum module. I have found a brilliant tutorial, but unfortunately it is for Drupal 6 and some of the functions are not compatible with Drupal 7; I couldn't find the equivalent functions, and I figured some of you may know them.

If you do, I would greatly appreciate it if you could share them with me; even if you don't provide the whole of the functions in tutorial (which would be nice), and just provide me with the Drupal 7 functions to replace the ones in the tutorial; anything would help.

The main functions that do not work are the `profile_load_profile($user)`, and the `get_user_XYZ($user)` functions.

By the way, I am assuming it is because those functions are depreciated in Drupal 7 when it says "Undefined"! I can't see any other reason for it not to work, and I kind of expected some of the tutorials wouldn't work properly on Drupal 6.

# Answer
> 2 votes
Drupal 7 doesn't include the core profile module since users are entities which you can attach fields to. If you have added additional fields to the user you can get them with just user\_load().

FYI: it is not advisable to the $user when calling user\_load() since $user is a global variable which can cause problems.

It doesn't look like that tutorial would ever fully work since get\_user\_comment\_count() is never defined and the get\_user\_rank() parameter call's for a comment count but uses the $user object in the user\_forum\_load() function.

To get the comment count of a user you could just lookup the number of comments from the comment table for a given user and the tutorial's user\_comment\_rank() should still work.

# Answer
> 1 votes
Drupal 6 doesn't define any function whose name starts with "get\_user"; those are functions defined in the code used by the tutorial, or from a module the tutorial is referring to.

The User profile module, in Drupal 7, is only used when updating from a Drupal 6 site; differently the User profile module is not shown in the list of the modules, as it is hidden by default, and users cannot enable it using the user interface. The alternative to using the User profile module is to create fields using the user interface provided by the Field module.

---
Tags: nodes
---


# Question
Title: download a file from a link using DrupalWebTestCase?
I'm building a module that has a file download as part of its functionality. The data in it is dynamically populated from the use of forms.

Is there a method in DrupalWebTestCase that will allow me to download it? Or do I resort to wget?

# Answer
The class `DrupalWebTestCase` has the method DrupalWebTestCase::curlExec(), which accepts an array containing the same values used by curl\_setopt().
> 1 votes

---
Tags: files, testing
---


# Question
Title: hide the webform after submission in webform 3.0
I have a webform (webform 3 module) embedded on my websites homepage. I was looking for a way to hide the webform after it has been submitted.

-\> Tried to check the $\_POST but that does not work -\> Maybe the webform API could help?

Thanks.

# Answer
> 2 votes
Do you want to allow users to submit it just once ?
If so have a look at `node/123/webform/configure` (where 123 is your form node id), there's a "Submission limit" option. If you choose "1" and "ever" then the form will be hidden with the following message: You have already submitted this form. View your previous submissions".

If you want to redirect your user to another page after submission, you can use the redirect option in the settings page.

Does this answer your question ? Can you elaborate it a little more if it doesn't answer it ?

---
Tags: 6, webforms
---


# Question
Title: Alter a form's values on submission but before validate?
I'm trying to set up the user registration form to populate the username field with the email address field. Is there a way to do this without using hook\_validate and having to manually do the form validation?

# Answer
The answer depends on what exactly you want to do.

* If you want to pre-populate a form field, then you can implement hook\_form\_alter() (or `hook_form_FORM_ID_alter()`).
* If you want to avoid users are allowed to set a username for their account, then you should change the form field used for the username in a "hidden" form field, and add a validation handler that set the username to the value you want to use. The reason I would do it in the form validation handler is to avoid that form validation handlers implemented by other modules would throw an error because the field is empty; the error they show would not make any sense to the user, who is not seeing any field for which the error is reported.
* You want to set the username just in the case the user doesn't provide any value. In this case, I would implement `hook_form_alter()` to set the field as not required, and then I would add a form validation handler to set the username in the case the user didn't provide a value for the username.
> 1 votes

# Answer
hook\_form\_alter() (or hook\_form\_FORM\_ID\_alter()) can be used to populate any field before rendering.
> 1 votes

---
Tags: 6, users
---


# Question
Title: Large ecommerce sites that are built on drupal
I'm having trouble trying to convince the team to adopt Drupal commerce/Ubercart.
Would anyone know of some large websites that are built on Drupal?

# Answer
> 2 votes
See Dries' list http://buytaert.net/tag/drupal-sites

# Answer
> 4 votes
Drupal Commerce sites:

Ubercart sites:

High profile sites:

Government sites:

---
Tags: ubercart, commerce
---


title: Display the user avatar in  a user panel

text:
# Question
Title: Display the user avatar in  a user panel
Is there an alternative to make the login box that turns into the default user panel (My Account, Administer etc.) display the user's profile picture above the username?

# Answer
There are actually two separate blocks, *User login* that is displayed only to anonymous users and *Navigation* that only gets displayed once user has logged in. You are interested in modifying the latter one.

Unfortunately, there's no `hook_block_alter()` around that you could use to modify the block from a custom module. However, you can do so from within your theme just before the block gets displayed.

Just pop the following function into YOURTHEME's `template.php` and it should work. Please, note, this adds the user picture to the top of the block content, just *below* the user name.

```
function YOURTHEME_preprocess_block(&$vars) {
  $block =& $vars['block'];
  if ($block->module == 'user' && $block->delta == 1) {
    // Navigation block.
    $block->content = theme('user_picture', $vars['user']) . $block->content;
  }
}

```

If you want it above the username, just replace `$block->content` with `$block->subject`.

Or, even better, just create another block, place it above the *Navigation*, make it only visible specifically to `authenticated user` role, set the *Body title* to `<none>`, and *Block body* to:

```
<?php
global $user;
print theme('user_picture', $user);
?>

```

Make sure to enable the *PHP filter* module first and use *PHP code* filter for the *Block body* input.
> 4 votes

# Answer
You could use Views that would give you a more flexible option, because you can add any fields from the user using the Views UI. You would need to:

1. Create a View that display Users
2. Add a contextual filter for the Uid.
3. Set the configurations of contextual filter's 'When the filter value is NOT in the URL' options to 'Provide default argument - User ID from logged in user'.
4. Add the fields you need, in your case User Picture and Name.
5. Add a block display and display the block wherever you want/
> 3 votes

---
Tags: blocks, users, media
---


# Question
Title: What is the recommend process for migrating a Drupal 6 Ubercart site to Drupal 7 / Drupal Commerce?
I'd like to migrate a client's site from Drupal 6 and Ubercart to Drupal 7 and Drupal Commerce. Is there an easy (i.e.: no manually munging data in the database) migration path? Do I need to go to Drupal 7 + Ubercart as an interim step?

# Answer
> 6 votes
The commerceguys who are behind Drupal Commerce, will surely make this in time. They have a lot of Drupal 6 UC sites, that they on some point would like to get into beta.

Having an upgrade path from Ubercart to Drupal Commerce, is a bit premature for now. Beta was only just recently launched, and some key features are still missing in core, like physical products and shipping.

Upgrading will not be an easy task either, since Commerce is quite different using the new entity API that's available inn Drupal 7. This means that products, orders, costumers, line items are all entities defined by Commerce.

If you want to upgrade a Drupal 6 UC to Commerce today, my recommendations would be to.

1. Update the site to Drupal 7, (but don't install UC for Drupal 7)
2. Define the product types needed by your site.
3. Convert all product nodes by UC into Commerce product entities, and either delete them or change them to have a reference to the product (Custom code) - It depends on how you want to display your products. Usually, you either want to pull in the data to a node, or display the product entity with views.
4. Convert order, line-item data from UC to commerce.
5. Build the site and have fun.

Having just made a Drupal 7 commerce site from scrats and then converted a Drupal 5 -\> Drupal 6 UC site. My take on commerce vs ubercart is that right now, commerce has a much stronger and well built core system, but UC has many more contrib modules with a lot of features. Depending on the UC you are converting, you might have you spend considerable time custom coding what you have in ubercart contrib.

My advise is, to go for commerce drupal 7, but wait a bit until it is more mature and has a better suported upgrade path from Ubercart.

# Answer
> 8 votes
There are new tools and resources for this:

# Answer
> 4 votes
I don't think there is an easy no munging method to get to Drupal Commerce. Over time, someone will hopefully publish some MigrationDestination and MigrationSources that correspond with Commerce products and Ubercart products (orders, customers, etc) respectively for use with the Migrate module.

# Answer
> 1 votes
The documentation isn't complete on the official site and there are many bugs that you may need to consider before making a switch. Not all the critical bugs are fixed for the 7 branch and the list gets longer if you look for issues with ubercart.

---
Tags: ubercart, migrations, commerce
---


# Question
Title: How To Get Views Argument as a Like / Contains Instead of Equals
I have a view that I need to filter using the logic Field\_a Contains url\_argument\_1. Or in SQL Field\_a LIKE '%url\_argument\_1%'. The problem I am having is only filters let me use the "Contains" operator and only Arguments let me access url\_argument\_1. How can I combine them?

Just for clarity url\_argument\_1 is Argument #1 that is passed into the view from the URL. Also, if at all possible I want to avoid writing a custom module. I prefer to do this via the views interface.

# Answer
> 1 votes
Solution would be to filter results by argument value. Unfortunately, this doesn't seem to be doable in Views at the moment. Not via the Views interface, anyway.

However, by altering **exposed** filter form to set current argument value as filter default value, users have managed to get such functionality to work: http://drupal.org/node/360780

I don't know what state it is in, but you may want to have a look at this module, which is supposed to do just that -- enable using argument placeholders (%1, %2) as filter values: http://drupal.org/sandbox/itangalo/1086472 (git only)

---
Tags: 6, views
---


# Question
Title: I want to do something after users voted
I want to do something after users voted. I know I can do it by using `hook_nodeapi('view')` , but I just want to add my action while a vote is being inserted in the database table. How can I do that?

# Answer
You're most probably after VoteAPI integration with Rules: Voting Rules

It enables you to configure actions to occur when a user submits a vote, when a user deletes a vote, and when the results of a vote are calculated. Currently, Voting Rules supports votes on nodes, users, and comments.
> 4 votes

---
Tags: users
---


title: Garland theme and h2 heading

text:
# Question
Title: Garland theme and h2 heading
On D6.2 I'm using Garland. But instead of generating h1 tags for the title it is generating h2 tag. What is the best way to make it generate h1 instead of h2? Should I subtheme it and modify page.tpl.php? Isn't there any settings or module which can do it?

# Answer
> 1 votes
Subtheme is the answer. The theme is the last line in the rendering of the page which is why you generally can't override it. The H2 tags is most likely hardcoded in the page template which is why you can't alter it.

that being said, you could in a module make garland use a page template that your module has created. This require some complex altering of the Drupal theming system, and is not something you want to do, unless you understand the consequences.

---
Tags: theming, 6
---


title: List content of node in another view

text:
# Question
Title: List content of node in another view
I have a view of some custom content type and want to link the name of each object in the view to another view containing its details. At the moment, I have the "link this field to its node" box checked but it doesn't display it in some sort of table, just a list like *Title: value*.

Could you please tell me how I can achieve this?

# Answer
> 2 votes
You can alter the node link to anything you would like with "Rewrite the output of this field", it should link to something like /yourviewpath/$nid, where $nid is the node id and the argument for the view that contains the node details.

---
Tags: views, nodes
---


# Question
Title: Using preprocess node variable in page.tpl.php
I've set up a couple of variables in my `template_preprocess_node()`. How can I access them within a page template? I can access the `$node` variable, but it doesn't seem to have been preprocessed.

How can I force preprocessing?

# Answer
The node variable for page templates is set in template\_preprocess\_page http://api.drupal.org/api/drupal/includes--theme.inc/function/template\_preprocess\_page/6 You should override that function in your theme
> 2 votes

---
Tags: nodes, theming, 7
---


title: How to build a newsletter template

text:
# Question
Title: How to build a newsletter template
I'm creating a content type specifically for email newsletters, which will be sent using phplist (client prefers phplist to using a Drupal newsletter module such as Simplenews).

So I'm planning to use a module like ThemeKey or Content Theme to create a new theme specifically for newsletter content type. Like most newsletter templates, the theme will use tables and lots of inline CSS.

I haven't seen any Drupal base themes for newsletters. Before I build from scratch, is there any advice or suggested theme/module I might have overlooked?

# Answer
I'd write the db queries yourself (don't use views) so that you have full control over the output. Use a custom module to do the queries and write the html. You don't need a whole new theme, because the CSS needs to be inline for email clients to work properly.
> 1 votes

---
Tags: 7, theming
---


# Question
Title: How can a user select a different language to the site default language?
My Drupal 6 site should always display in French for all users *except* me. I need to administer the site in English.

Using the Locale module I have both languages installed and default set to French. In the language negotiation settings ('Configure'), I have selected 'none'. The help text says that *"users may (optionally) select a preferred language on the My Account page"*.

Even though I have selected English in my account settings (under "Language settings"), everything remains in French when I login?

# Answer
It doesn't seem to work like that; see Drupal: changing language settings in user edit not working.

> If you had the Language negotiation set to *None*, because -- like me -- you thought that would allow users to change their language preferences, you were wrong. The problem is this help text on the Languages page is completely misleading:
>
> > None. The default language is used for site presentation, though users may (optionally) select a preferred language on the My Account page. (User language preferences will be used for site e-mails, if available.)
>
> It should read:
>
> > None. The default language is used for site presentation, though users may (optionally) select a preferred language — for site e-mails, if available — on the My Account page.
> 1 votes

# Answer
Have you tried using the Administration Language module?

> This module lets the administrator see all administration pages in her preferred language.
>
> You can use this to display the frontend of the site in one language and still keep most of the backend in English (or another language of your choice).
> 2 votes

---
Tags: 6, i18n-l10n
---


# Question
Title: Sortable, paged table retrieved using EntityFieldQuery
How do you create a tabular, sortable and paged display in a custom module using `EntityFieldQuery`? I've been looking all over for a working example and can't find one. The entity has custom CCK fields, and using db\_select it looks like I have to write joins and I'd rather avoid doing that if `EntityFieldQuery` brings in all the fields.

# Answer
To add conditions for the content of the fields, you use EntityFieldQuery::fieldCondition(), while for enabling the pager you call EntityFieldQuery::pager() passing the number of rows shown in each page.
EntityFieldQuery::fieldOrderBy() could be handy, if you need to order the results by the value of a field.
> 3 votes

# Answer
Working example :

```
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'node', '=')
->propertyCondition('type', 'contenttype', '=')
->propertyCondition("status", 1)
->fieldCondition('field_custom', 'value', $value, '=');
$query->pager(10);
$queryResults = $query->execute();
$results = node_load_multiple(array_keys($queryResults['node']));

```

Results are nodes, You could format it like usual with form's "tableselect" element.
> 0 votes

---
Tags: theming
---


title: Popup on submitting a form

text:
# Question
Title: Popup on submitting a form
Updated:I built a custom form that processes the data and returns `TRUE` or `FALSE`. I want to process the data by AJAX, and show a popup if the form returns `TRUE`. May anyone help me to complete the code? I am using AJAX with drupal for the very first time.

> i made some changes in the form

```
function invitecode_menu() {
$items['invitecode'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('invitecode_nameform'),
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM
);
return $items;
}
function invitecode_nameform() {
$form['invite_code'] = array(
'#title' => t('Invite Code'),
'#type' => 'textfield',
'#ajax' => array(
      'callback' => 'inviteform_nameform_callback',
      'wrapper' => '',
      'method' => 'replace',
      'effect' => 'fade',
      ),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'submit',
);
return $form;
}
function invitecode_nameform_validate($form, &$form_state) {
$code1= $form_state['values']['invite_code'];
  if (!empty($code1)) {
    $code = regcode_use($code1);
    if (!is_object($code)) {
        drupal_add_js(drupal_get_path('module', 'jqevent') .'/incorrect.js');
    }
    if (is_object($code)) {
        $_SESSION['regcode']=$form_state['values']['invite_code'];
        drupal_add_css(drupal_get_path('module', 'jqevent') .'/jqevent.css');
        drupal_add_js(drupal_get_path('module', 'jqevent') .'/jqevent.js');
        $form1=drupal_get_form('user_register_form');
        print "<div id='popupContact'><a class='popupContactClose'>x</a>".drupal_render($form1)."</div>";
    }
}}
function invitecode_nameform_submit($form, &$form_state) {
$_SESSION['regcode']=$form_state['values']['invite_code'];
}

```

if i do not use the print function in validate() it simply give me the popup with no data inside. But using the print statement as i require the form inside the popup it gives me error inside the the popup like

```
> An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging
> information follows. Path: /may18/?q=system/ajax StatusText: OK
> ResponseText: x Username * Spaces are allowed; punctuation is not
> allowed except for periods, hyphens, apostrophes, and underscores.
> E-mail address * A valid e-mail address. All e-mails from the system
> will be sent to this address. The e-mail address is not made public
> and will only be used if you wish to receive a new password or wish to
> receive certain news or notifications by e-mail. Password * Confirm
> password * Provide a password for the new account in both fields.
> Status  Blocked  Active  Roles  authenticated user  administrator
> Notify user of new account  Registration Code Registration Code
> Select the newsletter(s) to which you wish to subscribe. Coutallure
> newsletter  Give us permission to Contact you by email
> [{"command":"settings","settings":{"basePath":"\/may18\/","ajaxPageState":{"theme":"maytheme","theme_token":"WZd5UzEZYK-b_Rh5bxi4rao3d1UNF5KWVloXCPZ9WuI","css":{"sites\/all\/modules\/jqevent\/jqevent.css":1},"js":{"sites\/all\/modules\/jqevent\/jqevent.js":1}},"overlay":{"paths":{"admin":"node\/*\/edit\nnode\/*\/delete\nnode\/*\/revisions\nnode\/*\/revisions\/*\/revert\nnode\/*\/revisions\/*\/delete\nnode\/add\nnode\/add\/*\noverlay\/dismiss-message\nuser\/*\/shortcuts\nnode\/*\/simplenews\nadmin\nadmin\/*\nbatch\ntaxonomy\/term\/*\/edit\nuser\/*\/cancel\nuser\/*\/edit\nuser\/*\/edit\/*\ndevel\/*\nnode\/*\/devel\nnode\/*\/devel\/*\ncomment\/*\/devel\ncomment\/*\/devel\/*\nuser\/*\/devel\nuser\/*\/devel\/*\ntaxonomy\/term\/*\/devel\ntaxonomy\/term\/*\/devel\/*","non_admin":"admin\/structure\/block\/demo\/*\nadmin\/reports\/status\/php"},"ajaxCallback":"overlay-ajax"},"password":{"strengthTitle":"Password
> strength:","hasWeaknesses":"To make your password
> stronger:","tooShort":"Make it at least 6
> characters","addLowerCase":"Add lowercase letters","addUpperCase":"Add
> uppercase letters","addNumbers":"Add numbers","addPunctuation":"Add
> punctuation","sameAsUsername":"Make it different from your
> username","confirmSuccess":"yes","confirmFailure":"no","weak":"Weak","fair":"Fair","good":"Good","strong":"Strong","confirmTitle":"Passwords
> match:","username":"mujtabamir"}},"merge":true},{"command":"insert","method":"prepend","selector":"head","data":"\u003clink
> type=\"text\/css\" rel=\"stylesheet\"
> href=\"http:\/\/localhost\/may18\/sites\/default\/files\/css\/css_-j0N5j7w-7YCgITTN-240MV-bqldIA1OJJebmoiZ80Y.css\"
> media=\"all\"
> \/\u003e\n","settings":null},{"command":"insert","method":"prepend","selector":"head","data":"\u003cscript
> type=\"text\/javascript\"
> src=\"http:\/\/localhost\/may18\/sites\/default\/files\/js\/js_IP9kSDhraOOcZHaQjBKqa_pUy3Jsg_WBiSr0qKQUQ4E.js\"\u003e\u003c\/script\u003e\n","settings":null}]

```

# Answer
The API documentation contains a section titled AJAX Examples.

What I see wrong in your code is the form submission handler that output something using `print`. The purpose of a form submission handler is generally saving the submitted values in the database (e.g. using `variable_set()`), printing a message using drupal\_set\_message(), and redirecting the user to another page, if it is necessary.
It's the AJAX callback that should return the HTML to output in a specific section of the page, or returning the array containing elements that needs to be rendered. ajax\_example\_autocheckboxes\_callback() reports the following text:

> Since #ajax\['callback'\] return can be HTML or a renderable array (or an array of commands), we can just return a piece of the form. See AJAX Advanced Commands for more details on AJAX framework commands.

What returned from the AJAX callback is rendered where the wrapper, which is a CSS ID, is present. For example, in the auto-checkboxes example, the "#wrapper" is used in the following way.

```
  $form['howmany_select'] = array(
    '#title' => t('How many checkboxes do you want?'),
    '#type' => 'select',
    '#options' => array(
      1 => 1,
      2 => 2,
      3 => 3,
      4 => 4,
    ),
    '#default_value' => $num_checkboxes,
    '#ajax' => array(
      'callback' => 'ajax_example_autocheckboxes_callback',
      'wrapper' => 'checkboxes-div',
      //'method' defaults to replaceWith, but valid values also include
      // append, prepend, before and after.
      // 'method' => 'replaceWith',
      // 'effect' defaults to none. Other valid values are 'fade' and 'slide'.
      // See ajax_example_autotextfields for an example of 'fade'.
      'effect' => 'slide',
      // 'speed' defaults to 'slow'. You can also use 'fast'
      // or a number of milliseconds for the animation to last.
      // 'speed' => 'slow',
      // Don't show any throbber...
      'progress' => array('type' => 'none'),
    ),
  );

  $form['checkboxes_fieldset'] = array(
    '#title' => t("Generated Checkboxes"),
    // The prefix/suffix provide the div that we're replacing, named by
    // #ajax['wrapper'] above.
    '#prefix' => '<div id="checkboxes-div">',
    '#suffix' => '</div>',
    '#type' => 'fieldset',
    '#description' => t('This is where we get automatically generated checkboxes'),
  );

```

Using a popup plugin for jQuery is then possible to render as popup the `<div>` tag using that CSS ID.
> 1 votes

# Answer
Use the Simple Dialog module; you can open your form in a popup modal dialog. Other solutions might be using the Chaos tool suite (ctools) module; examples come with the module.
> 1 votes

---
Tags: forms, ajax
---


# Question
Title: Multiple node access rules for same node?
I'm using the Domain Access module to restrict content to specific domains. It uses the node\_access table to do this.

I also want to make a single node hidden behind a login area. The problem is that when I add my node access rules to do this it overwrites all the Domain Access rules which mean that all the nodes appear on the same domain.

Is there a way to allow more than one module to use node access rules?

My node access code looks like this:

```
define('MYSITE_REALM', 'press');
define('MYSITE_GRANT_ID_PUBLIC', 0);
define('MYSITE_GRANT_ID_PRESS', 1);
define('MYSITE_PRESS_SECTION_NID', 554);
define('MYSITE_PRESS_USER', 'press');

/**
 * Implements hook_node_grants().
 */
function mysite_node_grants($account, $op) {
  if ($op == 'view') {
    $grants = array();

    if ($account->name == MYSITE_PRESS_USER) {
      $grants[MYSITE_REALM] = array(
        MYSITE_GRANT_ID_PUBLIC,
        MYSITE_GRANT_ID_PRESS,
      );
    }
        else {

      // everyone else
      $grants[MYSITE_REALM] = array(
        MYSITE_GRANT_ID_PUBLIC,
      );
    }

    return $grants;
  }
}

/**
 * Implements hook_access_records().
 */
function mysite_node_access_records($node) {
  $grants[] = array();

  if ($node->nid == MYSITE_PRESS_SECTION_NID) {
    $grants[] = array(
      'realm' => MYSITE_REALM,
      'gid' => MYSITE_GRANT_ID_PRESS,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
      'priority' => 0,
    );
  }
    else {
    // everything else is public
    $grants[] = array(
        'realm' => MYSITE_REALM,
      'gid' => MYSITE_GRANT_ID_PUBLIC,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
        'priority' => 1,
    );
  }

  return $grants;
}

function mysite_user_login(&$edit, $account) {
  if ($account->name == MYSITE_PRESS_USER) {
    drupal_goto('node/' . MYSITE_PRESS_SECTION_NID);
  }
    else {
    drupal_goto('');
  }
}

```

# Answer
> Is there a way to allow more than one module to use node access rules?

The problem with `hook_node_access_records()` and `hook_node_grants()` is that, independently from the weight of the modules, once a module returns 1 for "grant\_view," "grant\_update," or "grant\_delete" that permission is allowed to the user. If a module returns 1 for one of those operations, and another module returns 0, the access is allowed, independently from the priority given to the records returned from the modules for those records.

In Drupal 7 it is also possible to use hook\_node\_access(), which is able to report if the user has access or not to the node, or if the hook implementation let other implementations decide if the user has access to the node (using the value `NODE_ACCESS_IGNORE`).

In Node access rights it is explained how the node access is checked.

> In determining access rights for a node, node\_access() first checks whether the user has the "bypass node access" permission. Such users have unrestricted access to all nodes. User 1 will always pass this check.
>
> Next, all implementations of `hook_node_access()` will be called. Each implementation may explicitly allow, explicitly deny, or ignore the access request. If at least one module says to deny the request, it will be rejected. If no modules deny the request and at least one says to allow it, the request will be permitted.
>
> If all modules ignore the access request, then the node\_access table is used to determine access. All node access modules are queried using `hook_node_grants()` to assemble a list of "grant IDs" for the user. This list is compared against the table. If any row contains the node ID in question (or 0, which stands for "all nodes"), one of the grant IDs returned, and a value of TRUE for the operation in question, then access is granted. Note that this table is a list of grants; any matching row is sufficient to grant access to the node.
> 3 votes

---
Tags: 7, users, domain-access
---


title: Horizontal form elements

text:
# Question
Title: Horizontal form elements
I have described the form, but every element there is located under the previous one. I need to describe the form where all elements will be placed horizontally but not vertically. This is my form:

```
function contact_register_form($form, &$form_state) {
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('Sign up to be notified when your community launches:'),
  );

  $form['email'] = array(
    '#type' => 'textfield',
    '#title' => t('Email'),
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Add me',
  );

  return $form;
}

```

# Answer
> 17 votes
You can use code similar to the following one, used by the Node module in `node_filter_form()`.

```
  // Build the 'Update options' form.
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#attributes' => array('class' => array('container-inline')),
    '#access' => $admin_access,
  );

  // ...

  $form['options']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Operation'),
    '#title_display' => 'invisible',
    '#options' => $options,
    '#default_value' => 'approve',
  );

```

The key is the line settings the "#attributes" attribute to "container-inline."

That code is for Drupal 7; the equivalent code for Drupal 6 starts with the following code:

```
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );

```

Supposing you are using Drupal 6, then your code should be changed to something similar to the following one:

```
function contact_register_form($form, &$form_state) {
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('Sign up to be notified when your community launches:'),
  );

  $form['email'] = array(
    '#type' => 'textfield',
    '#title' => t('Email'),
    '#prefix' => '<div class="container-inline">',
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Add me',
    '#suffix' => '</div>',
  );

  return $form;
}

```

I didn't put the description inline, as it would not be correctly rendered because it is using a "item" form field. I also find that inlining the description would cause the form to take too much space. (Imagine what would happen if the inlined description would be longer, and placed in a single line.)

The CSS styles that Drupal 7 adds to container-inline elements are the following.

```
/**
 * Inline items.
 */
.container-inline div,
.container-inline label {
  display: inline;
}
/* Fieldset contents always need to be rendered as block. */
.container-inline .fieldset-wrapper {
  display: block;
}

```

They are added from system.base.css.

---
Tags: forms
---


# Question
Title: How to add multiple images to a node using node.save service?
I am using the services module along with the json server module to add a node to my drupal web site from an external application.

One of the cck fields is an image field which can accept multiple values. In my javascript application I'm calling the node.save service with node object like:

`node_obj.field_image = [{ "fid": fid }];`

This successfully adds the image value to the cck field. But how do I add another image value to this field? Calling the service again overrides the old image vale with the new one.

# Answer
```
[{ "fid": 1 }, { "fid": 2 }];

```

have you tried this?
> 4 votes

---
Tags: entities, services
---


title: Advice for categorizing content?

text:
# Question
Title: Advice for categorizing content?
I'm new to Drupal 7 and UberCart and loving it.
I'm working on a site that is automotive based and am having a problem wrapping my head around the catalog. I have 4 different parent catagories, then year/make/model and part category. A product can be anywhere and belong to multiple categories.

Right now I have a vocabulary that contains parent category/make/model/part category and another that contains year.

I need the menu to work like

* Parent Category 1
    + Make 1
        - model 1
            * year
                + sub-cat
        - model 2

        * year
                + sub-cat
    + Make 2
        - model 1
            * year
                + sub-cat
        - model 2
            * year
                + sub-cat

Am I making this too complicated?
The sub-cats would be unique to the Parent Category but make/model/year could belong to any Parent Category and subcat.

Can anybody give me any advice? Thanks in advance.

*edit* I guess I'm asking If I put year make model together in a vocabulary and Parent Category and subcat together in a vocabulary (which I think would work well), how can I incorporate that into UberCart catalog menu?

# Answer
> 1 votes
@Drupality was right...It does require custom coding. I installed Multi Term Views which will allow nodes to be filtered that contain different, multiple taxonomies from different vocabularies.
So you could have a filtered view at `taxonomy/term/27+35` which will show all nodes in term id 27 and 35 or you can have `taxonomy/term/27,35` which will show all nodes that are exclusively in both 27 and 35. After that was set up I just wrote a custom menu and put it in a block in the sidebar.
So I have 3 vocabularies that are Year, Make/Model, and Type. Make/Model is two terms deep. Not the best solution - but if a highly customized menu is needed then apparently this is what must be done.

Thanks @Drupality for your help.

---
Tags: taxonomy-terms, routes, ubercart
---


title: Modifying HTML of menus

text:
# Question
Title: Modifying HTML of menus
In my Drupal 7 template, this one line of code spits out all my menues:

```
<?php print render($page['header']); ?>

```

I want to remove extraneous wrapper tags from my menus; for example, Drupal 7 prints out one of my menus as:

```
<div id="block-menu-menu-top-menu" class="block block-menu">
    <h2>Top menu</h2>
    <div class="content">
        <ul class="menu">
            <li class="first leaf"><a href="/home" title="">Membership</a></li>
            <li class="leaf"><a href="/home" title="">Calendar</a></li>
            <li class="leaf"><a href="/home" title="">Newsletter</a></li>
            <li class="last leaf"><a href="/home" title="">Contact Us</a></li>
        </ul>
    </div>
</div>

```

I want to simplify it to something like:

```
<ul class="menu">
        <li class="first leaf"><a href="/home" title="">Membership</a></li>
        <li class="leaf"><a href="/home" title="">Calendar</a></li>
        <li class="leaf"><a href="/home" title="">Newsletter</a></li>
        <li class="last leaf"><a href="/home" title="">Contact Us</a></li>
</ul>

```

How do I remove unnecessary wrapper tags?

# Answer
> 5 votes
I'm not sure if there are template hints that work exactly with this, but you can place block.tpl.php and region.tpl.php (in modules/block/ and modules/system/ respectively) in the theme directory, and then use conditions to sort through which areas you want to be marked up the default way and regions you don't want to be marked up that much.

---
Tags: blocks, theming, navigation
---


# Question
Title: Trying to get an "About the author" view to work on a multi user blog (contextual filters)
I'm working on a Drupal 7 install sub-theming zen. I have a blog and I want to have an "About the author" view on each blog post. I've created a custom post type (Profile) for this, but I'm not sure how to make my view aware of the user who has created each post to show the Profile depending on the post author. I know this used to be done with the view arguments but that's part of Contextual Filters in Drupal 7, but I still don't know what filter I should have there, or if I should add any fields in the Profiles so that the filters can tell which profile belongs to which author.

Any help will be most welcomed!

# Answer
> 0 votes
You don't need to create separate content types in D7, You are able to attach fields to the user directly (admin/config/people/accounts/fields). If you need more flexibility, use the Profile2 module.

If you just add fields to the user, you can create a new block view of users. Under "Contextual Filters" (which is under Advanced on the right side), add a filter of `User: Uid`, set it to `Provide default value`, with a type of `User ID from URL`, and check the checkbox for `Also look for a node and use the node author`.

Then add the fields normally as you see fit.

---
Tags: views, 7
---


title: Sub-theming Garland

text:
# Question
Title: Sub-theming Garland
I've gone through Creating a sub-theme, but there is something that is not clear to me.

Why do I need to copy style.css and declare it in the info file as, in the above link, it clearly says that if we declare any CSS file all the CSS files are automatically inherited?

Can anybody confirm me the minimum steps to create a Garland sub-theme?

* Create the ".info" file with "stylesheets\[all\]\[\] = style.css"
* Copy the style.css file
* Create the regions in the ".info" file, since none are inherited
* Create an empty template.php
* copy the "color" and "images" directory

# Answer
> 1 votes
The bare minimum is a just a single `YOURTHEME.info` file:

```
name = YOUR THEME
base theme = garland
core = 6.x
stylesheets[all][] = YOURTHEME.css

```

That's it. :-)

--

No need to copy `style.css`. An empty `YOURTHEME.css` works, as long as you've defined it in the .info file. Actually, the file doesn't even have to exist. ;-)

No need to define regions, none are defined in `gardland.info` either.

No need to copy `images` directory. Images are inherited from the base theme.

The `color` directory is optional. You only need it if you are after the color scheme functionality.

No need for an empty `template.php`. You can create one when you need it.

# Answer
> 1 votes
The stylesheets will inherit, unless you have an identically named one, which will override it. You should only add new (and differently named) stylesheets as you need them. You don't have to copy the original style.css, and unless you want to override it, you shouldn't add it to your `.info` file

# Answer
> 0 votes
I think that's it, yes. You need a single stylesheet, but it can be empty if you wish.

---
Tags: 6
---


# Question
Title: URL alias with taxonomy term (multiple vocabularies). How do I choose one?
I'm trying to setup a content type that has a multiple level taxonomy vocabulary assigned. The same content has a CCK taxonomy field for other use, but I don't want to use it on the URL.

The problem is that when I put in the URL alias "\[term\]/\[title-raw\]," it selects the CCK field, not the vocabulary assigned through the Taxonomy module. I tried to change the order of the fields, but nothing changes.

What can I do, apart from putting the other vocabulary through CCK as well?

# Answer
> 1 votes
`[term]` -- Name of top taxonomy term

Top taxonomy term is the term with the lowest weight from the vocabulary with the lowest weight.

Reorder vocabularies at `admin/content/taxonomy`, move the desired one to the top and you should be good. :-)

---
Tags: taxonomy-terms, uri, path-aliases
---


title: Theme for specific requesting computer

text:
# Question
Title: Theme for specific requesting computer
Similarly to changing the theme based on the requesting browser or logged in user, I want to change the theme based on where the request is coming from.

If a request comes from a specific address, domain or computer, how can I force a specific theme? I can't seem to find a module that accomplishes this.

# Answer
> 4 votes
Possible with

# Answer
> 4 votes
You can also create your custom module and use `hook_custom_theme()`

And do your own detection in there.

Eg:

```
function YOURMODULE_custom_theme() {
  if (ip_address() == '192.168.5.212') {
    return 'THEME_NAME';
  }
}

```

---
Tags: theming
---


# Question
Title: View commerce product image and price fields
In Drupal 7 commerce I ran into a problem.
I want to display the latest 3 items placed in the show\_product content type, with attributes from the store. There are several entities in the store, displayed in the same node with the product reference field, all with different attributes and images. Imagine every online clothing shop will face the same problem regarding sizes and colors. So, in Views I need a relation on "Content: field\_prodref - product\_id" to show the attributes from the entities. The view shows all the products from the store. Is there a way to bypass this so the view shows only the show\_product display node with price field and image?

# Answer
I'm pretty sure you'd have worked out the \*the latest 3 items placed in the show\_product content type\* part already:

1. Add filters, Node: Type, Node type: show\_product
2. Add sort criteria, Node: Post date, Sort order: Descending
3. Items to display: 3

For the attributes part, the tricky one, instead of defining a relationship in the existing view, you'd be better off creating a whole new view, which would list the attributes of product passed in as argument.

To make it all work together, you'll attach the latter view to the former one using one of Viewfield (7.x-dev), Views Field View (7.x-dev) and View reference modules.

An example, using Viewfield. To the show\_product node type add a hidden View field called Attrview. Set it to "Always use default value". Set the default value to the attribute listing view. The argument is "%nid". Exclude its display from node teaser, full view etc.

In the first view, then, along with Price and Image, also add Attrview as a field. Done!
> 3 votes

---
Tags: 7, views, commerce
---


# Question
Title: Setting a new users profile fields based on a form
Users on my site all have a "home region" field. This profile field is saved for each user and used to customise various site features, so that the user gets shown local content.

These regions aren't states or cities - they're more like electorate / local council boundaries (I'm not really sure what the US analogy would be). Most users are going to be uncertain about which region they actually want to save to their user profile.

I have a form which allows users to either (A) explicitly select their region from a select dropdown or (B) enter their postcode, submit the form, and get back their region. This form works fine.

I want users to be able to pick a region at registration time using this form, and have that region saved to their profile. Ideally I'd like to integrate the "select region" form with the user\_register form, so that they can submit the form, get told "you are part of X region" and then click "register" and create a new user account with that region.

What I'm doing is using hook\_user() to insert my form elements, perform my extra validation and then try to save the region data to the user on submit.

## EDIT: the below is roughly how I solved this

```
function mymodule_user($op, &$edit, &$account, $category = NULL) {
  /* add "select your region" functionality to the user edit form */
  $category = 'Regional information';
  switch ($op) {
    case 'register':
    case 'form':
        /* "register": The user account registration form is about to be displayed. The module should present the form elements it wishes to inject into the form. */
        /* "form": The user account edit form is about to be displayed. The module should present the form elements it wishes to inject into the form. */
        $form = array();
        $form['Regional information']['region'] = _region_select('', _region_select_options());
        $form['Regional information']['postcode'] = _postcode();
        return $form;
        break;
    case 'validate':
        /* "validate": The user account is about to be modified. The module should validate its custom additions to the user object, registering errors as necessary. */
        $region = $account['region'];
        $postcode = $account['postcode'];
        // form_set_error() if I need to
        break;
    case 'insert':
    case 'update':
        /* submit happens *before* the user account is saved - we want insert or update
           "insert": The user account is being added.
           "update": The user account is being changed.
           The module should save its custom additions to the user object into the database and set the saved fields to NULL in $edit. */
        $region_code = $edit['region'];
        $postcode = $edit['postcode'];
        if (!$region_code && $postcode) { // pull the region from the postcode
            ...
        }
        if ($region_code) {
            $region_term = taxonomy_get_term($region_code);
            $region_name = $region_term->name;
            /* the profile module wants the name of the region, not the id */
            $profile_edit = array( 'profile_region' => $region_name );
            profile_save_profile($profile_edit, $account, $category);
        }
        break;
  }
}

```

# Answer
Do you think you could just make the select dropdown and postcode input box parts of the `user_form`? Looks like you've got the functionality working already, so it would be a matter of a simple module implementing the following hook:

1. `hook_user(register)` to alter the registration form and add your custom fields. You'll want to use a profile or profile\_taxonomy functionality to insert the form element
2. `hook_user(validate)` to validate the user input (incorrect postcode etc.)
3. `hook_user(submit)` to convert the postcode to region and to save that information in the user profile
> 2 votes

---
Tags: 6, forms, users, webforms
---


# Question
Title: How to do a newsletter / mailing list with Drupal 7
I would like to make a mailing to a Drupal (7.4) community, sending an email to every user or every user with a specific role.

I would like to send this mails from my admin interface and I want to send mails with HTML.

What is the best way to do it ?

# Answer
> 3 votes
Use Simplenews and Mime Mail and/or HTML Mail to achieve this.

# Answer
> 3 votes
Mailchimp could be a solution.
E-mails and tracking are done by an external e-mail marketing service, where html mails can be made or you can input an url to send as mail.
For now, this is the only available module with detailed tracking available for D7.

---
Tags: emails
---


# Question
Title: How to create an iCal feed of non-Nodes?
It looks like the Calendar/Dates modules don't add Views Display types directly. Instead you're apparently supposed to copy one of the default views that come with Calendar to access the additional displays. However, the default views are Node views and I want to create a view of non-nodes. For example, say I want to create an iCal feed display type listing the dates users created their accounts on the site. Is there a way to do that using the Calendar/Date modules?

---

I made several attempts to use the iCal functionality included with the Calendar module, but in the end I gave up on that idea. Instead, found an issue associated with the Views Bonus Pack, with code for adding iCal support to that module.

I made some modifications to allow me to use arbitrary Views fields in an iCal feed. I'm interested in hearing feedback on the idea, if anyone here gets a chance to try it out.

# Answer
> 2 votes
You can do this.

1. Make calendar module create an extra default view:

```
variable_set('calendar_default_view_options', array(
  array('name' => 'calendar'),
  array('name' => 'calendar_custom')
));

```

After clearing cache you should now have two calendar default views which are exactly the same.
2. Override the custom calendar view.

```
hook_views_default_view_alter(&$views) {
  if (isset($views['calendar_custom']) {
    $views['calendar_custom']->base_table = 'users';
  }
}

```

You can change the base table of the view, which is what Views will use to determine what you can query from.

Note this is example code and untested, but should work.

---
Tags: views, 6, feeds
---


# Question
Title: How to set up Drupal Commerce to sell users the ability to create/post custom nodes (ex. classified ads)?
I am currently working on a classifieds D7 site, and I would like to sell users the ability to create/post a classified ad. With D6 + Ubercart this can be done using the UC Node Checkout module (http://drupal.org/project/uc\_node\_checkout), and following the instructions provided on the Drupal Easy website (http://drupaleasy.com/blogs/ultimike/2009/03/event-registration-ubercart).

Is there any way implement the same functionality with D7 + Drupal Commerce?

Thank you so much

# Answer
You can do this with Rules pretty easily.

1. Create a role with the desired permission.
2. Create a product to sell.
3. Create a rule for the checkout complete event.

Condition is that the product you created is in the order. (I would probably create my own condition as I'm better with code than with the Rules interface, but you should be able to set this up in the Rules interface.) Action is to give user that owns the order the selected role.
4. There is no step 4, you're done.
> 3 votes

---
Tags: commerce
---


title: Themes folder path changes

text:
# Question
Title: Themes folder path changes
I am developing a site, in which my client has only access to sites/default/files path(their company allows only this path as public) today i got a new requirement that theme files such as css and js needs to be editable by admin , so they want theme files in sites/default/files/themes/site-theme. Is this achievable ? if so please give me any ideas on this .

# Answer
> 1 votes
One possible solution would be to alter the `$theme_path` global during `hook_init()`, although that would mean that *all* your theme files should be in another directory. I'm not sure if that's what you're going for.

If you just want to change some paths (ie for the stylesheets), alter the paths during `hook_preprocess_page()`, look up `$vars['styles']` and change the paths there.

---
Tags: javascript, theming
---


# Question
Title: Link field to path (automatically pulling Node Id)
I have a view "Objects" containing type Object and having fields name and size. I have another view with more features of the Objects called "Details". I set the path of the "Details" view to details/%.

What I want to do is link the name field of the Object in the first View to its details in the latter. In "output this field as a link", what path should I put for it to automatically get that field's Node ID and plug it into the URL so that it goes to its corresponding set of details? Is that not possible? Do I have to link each name manually to its details?

# Answer
Make sure to have the Token module installed.

Then, to be able to use the `[nid]` token, you'll have to add a *Node ID* field and move it *before* the *Node name* one to be output as link. The nid field you can *Exclude from display*.

In the node name field then, set custom path to `details/[nid]`.
> 4 votes

---
Tags: nodes, views, users
---


# Question
Title: What's the difference between these multi-site setups in Drupal 6?
I am migrating several Drupal 6 sites to a new host. I recall the installer automatically set up my multi-site tables with just a few settings in the installer. I couldn't find these settings while I am making this migration and discovered description of multi-site configuration.

My original multi-site is of this type: Example one (this page explains a multi-site using $db\_prefix property in a site's settings.php file).

During this file migration I found this type: Example two (this page explains manually crating a database table \[database\_name\]\_shared\_tables).

---

As I said, my four sites were setup as with version one above. As I work to restore these sites from the mysql dump files, I'm wondering which process will be faster? My sites work like this,

```
+ default.domain (main drupal app)
|- sub1.domain (separate data)
|- sub2.domain (separate data)
|- sub3.domain (separate data)

```

Some of the information about multi-sites is outdated. This page suggests there are tables which can not be shared. Yet my settings.php file did not have a detailed list of shared tables, and instead had a simple prefix value, and leads me to believe the first example resolves what to share for you.

# Answer
> 1 votes
I once wanted to do multisites but it became so difficult to share data without sharing ALL of the data that I stopped. I wanted to share forum content, but not page content which is impossible. It is all nodes or on nodes.

The biggest problem with doing the $db\_prefix method is everything is done in your settings.php file. I shared the variables table which shared every module setting. This method then included overriding all every variable you care about. For me if was a different google analytics code. Since this is stored in the db and I was sharing the variables table, the analytics ID was shared.

The most important table to keep up-to-date is the sequences table (auto-number table for databases that do not auto number easily) that stores the next user id to be used. If you share users, you have to have that table in lock step with the rest. It is easily edited to change the users\_uid value to be the next user id in the system.

So my answer will be another question. What do you want to be shared. Users? Roles? Taxonomy? Nodes? The more you share, the more tables have to be shared and the more overhead it is.

As a side note, the documentation is very outdated. I only recommend doing this on a dev and not production copy of your database and make sure you have a backup of a working settings.php and a full backup of the drupal database. This will help to roll back and keep your site running in the event something goes wrong.

In the settings.php I have the same $db\_url as all of the sites. The exception is the below items.

```
$conf = array(
  'site_name' => 'My Site Name',
  'theme_default' => 'my-=sub-theme',
  'site_slogan' => 'My site slogan',
  'site_frontpage' => 'my_site_view',
  'smtp_fromname' => 'SMTP Settings From',
  'site_footer' => 'Site Footer',
  'googleanalytics_account' => 'UA-112233-1',
);

```

Any variable inside the variables table can be set in $conf. This helps my having a different theme on my sub domain site as well as a different frontpage view. I setup a taxonomy that puts the content into the view and then out to the frontpage. I took the example frontpage view included in views and cloned it and edited it to my needs. This was a quick and dirty solution to share the nodes but keep the frontpage content separate and track each site with its own google analytics. It works but I know there are shortcomings. The major one being that content can still be searched for on both sites that does not technically belong there.

# Answer
> 0 votes
I would have closed this question, but there might be some other bone head who misses both examples use the $db\_prefix parameter in settings.php

(\>\_\<)

---
Tags: 6, migrations, multi-sites
---


# Question
Title: Why does the core search module not index node titles?
The search results only show terms in the body if that. Take the example of a product site. There is a product called Funkywidget with a description that has Funckywidget written twice in it. However, the core search module does not show any results for Funkywidget. It has a record in the search\_index table but doesn't show when typed into the search form.

What is the best way to enable people to find a Funkywidget?

# Answer
> 2 votes
> There is a product called Funkywidget

If the *title* of the node is "Funkywidget" it's searchable by that term. If you want to incorporate search terms that aren't in the node's fields, you should look at more complex search solutions like Apache Solr.

See here: http://api.drupal.org/api/drupal/modules--node--node.module/function/\_node\_index\_node/6 The title is added to the search string that's going in the db.

`$text = '<h1>' . check_plain($node->title) . '</h1>' . $node->body;`

---
Tags: 7, search
---


# Question
Title: Customize the display of error messages from the webform module
I am embedding the webform in drupal 6 in my home page but the error messages are shown on the webform page, is there a way to customize it so that 'on unsuccessful submission it still shows error messages on my websites home page instead of the webforms page'?

Thanks.

# Answer
I ended up using regular expression to overwrite the form action= in the $form. This seems to be one of the only way out to stop it from redirecting to the webform node when there is an error on submission. Thanks for the views and the responses.
> 0 votes

# Answer
Message are not disabled on home page. Please check for `$messages` if it is properly rendered in page template file. If you are using a separate template for home page then check it specially.
> 0 votes

---
Tags: webforms
---


# Question
Title: Drag ad drop images to make a customised gallery
So I have a content type "Albums" which has a field "image". This allows a user to upload several pictures into this album.

What I have done next is made a view that displays all the different albums. So you see a thumbnail for each album.

Once you click on an album you are taken to the contents of that album. The content is basically a list of image fields with some other stuff like date published etc...

What I want to do now is being able to pick a picture from this album and drag it to like some sort of panel at the bottom and drop it there, then navigate around the website dragging and dropping different pictures from different albums.

Once you have finished with the selection there should be a button called "create" or something similar which will maybe call a script through some trigger which will zip the pictures and download them to your pc.

I have no idea how to do this. Help!

Thanks!

I'm using Drupal 6.

# Answer
> 1 votes
This is actually a nice idea but probably not so easy to implement.

jQuery UI could help you with the drag and drop features. http://jqueryui.com/demos/droppable/ Drupalgardens does some galerie configuration through drag n drop - so there you may be able to get some inspirations on this. Especially since you can export the site and then look how exacly they do it. http://drupalgardens.com

---
Tags: views, rules, media
---


title: Best mobile theme for iOS devices?

text:
# Question
Title: Best mobile theme for iOS devices?
Can anyone please tell me the best mobile theme I could use for iOS devices? I tried the iUI theme but it doesn't display the table with the info properly :)

# Answer
jQuery Mobile or Omega themes
> 1 votes

---
Tags: theming
---


title: Good use of content profile

text:
# Question
Title: Good use of content profile
I am using Drupal 6 and I have installed the Content Profile module.
First I made 3 extra fields, "gender," "seeking gender," and "dob." Now I want to create a multistep that users needs to fill in with other details.

I was wondering how I can do this using content profile module. I have read that this is a very good module in order to customizing user profiles.

# Answer
One of the only ways I have been successful at making required multistep forms before having access to the website was using CTools to construct the form workflow, and submitting the data on submit callbacks into Drupal with node\_save().

See Intro to Drupal 6 Multistep Form Domination Using Chaos Tools.
> 1 votes

---
Tags: users
---


title: Set different page and window titles

text:
# Question
Title: Set different page and window titles
What I'm trying to do seems simple, and I'm sure it is, I just don't know what theme files need to be modified and how to modify them.

I want to make the user profile page display the user's first and last name (custom fields assigned to the User profile) as the title, rather than their username (which is default).

What I'm assuming can be done is intercept the title variable somewhere and change it to what I want.

How can I do this?

Cheers.

# Answer
> 2 votes
In Drupal 7, the template file that sets the title shown in the browser page is html.tpl.php, while the template that sets the page title is page.tpl.php.

Both the templates don't receive a variable containing the user object to which the page is referring, as those templates are used for every page. If you want to change the titles only for user pages, then you need to get the user object using menu\_get\_object('user'). The function returns `FALSE` if the currently shown page is not a user profile page; that is what happens when the viewed page is, e.g., example.com/node/1.

# Answer
> 1 votes
Not sure if you would be interested in using a module to do this but you can check out the Page Title module.

> This module gives you granular control over the page title. You can specify patterns for how the title should be structured and, on content creation pages, specify the page title separately to the content's title.

---
Tags: 7, theming, users
---


title: Personal Contact Forms

text:
# Question
Title: Personal Contact Forms
What is the best way to get a 'Contact User' form on nodes like an ebay-ish 'Contact Seller' simple form?

I tried Contact / Contact Forms module, but I do not want a Sitewide Contact form to be accessible (don't want to use it) and I want Mollom/Captcha integration and sending limits for anonymous users.

I thought maybe I could do Webform, but I can't see a way to make the recipient dynamic (node author, for example).

# Answer
Take a look at the Privatemsg module
> 1 votes

---
Tags: 7, forms, emails
---


# Question
Title: Get just the first item from a multiple valued field using field_view_field()
I'm using `field_view_field()` to get the render array for a image field that has multiple values. I then use `drupal_render()` on that resulting array to print out the markup.

I only want the first image to be returned in the markup for that field. Is there a way to either manipulate the rendered array to remove the other fields or a setting when call `field_view_field()` to say only return first row?

# Answer
Have you considered using field\_view\_value? It is the recommended way to retrieve a single value from a multi-value field.
> 1 votes

---
Tags: 7, theming, entities
---


# Question
Title: Sort nodes based on the amount of tags that match a specific node tags
Is there anyway to sort the nodes on a views display using the amount of matching tags of a specif node? I would like to have a views display that shows me all the nodes that most match with a given node.

For example: I have one node with three terms associated with it and I'll pass this node to a views as an argument. The views should display first the nodes that have this same three terms, after that it should display the nodes which match with two of the three terms, after that the nodes that match one of the three terms and after that the nodes that doesn't match any of the three terms.

I couldn't find something that could solve this problem for me. If there isn't any implemented solution I'd like to know if it's feasible to implement this on Drupal 7.

# Answer
> 4 votes
Check out Similar by Terms module. This Drupal module attempts to provide context for content items by displaying a block with links to other similar content. Similarity is based on the taxonomy terms assigned to content. Blocks are available based on similarity within each of the defined vocabularies for a site as well as a block for similarity within all vocabularies. There are two methods of sorting. 1) **Based on the most number of matching terms**. 2) Based on lest used terms.

Or you could use the Relevant Content module. This module provides two ways of referencing relevant content. Both of these methods provide configuration to filter for specific content types and vocabularies, limit the maximum size of the result and provide some header text. The result on both cases are a list of nodes which the module considers most relevant based on the categorization of the current page. This is achieved by finding other nodes which are of one of the allowed types and have the **most number of terms in common**.

# Answer
> -1 votes
I don't know if have a specific module to use, but I have two options, you can use query\_alter to change the arguments, but I guess that you will need to execute the views other times to get the other results. Another option is execute a specific query to get a list of nids ordered by the sum of matching terms.

---
Tags: 7, views, taxonomy-terms
---


# Question
Title: Access restriction modules block nodes, but not teasers?
Please forgive if this is bad form - this is my first post here, and I realise it's very similar to this existing question, although slightly different.

I'd like my site to have a bunch of public info, some members-only info, and some info only for super-users. All of the content-access modules I've tried seem to work when viewing the actual node, but in the taxonomy pages the teasers for these pages are still visible (thus leaking information). In short, you can see which pages you're not allowed to read in full, and that's a problem.

How can I make sure that users only see content --in any way-- that they are permitted to see?

I've implemented my access model by making three distinct roles (well, anonymous, authenticated, and "super user"), and three distinct content types for each user role and then assigning access based on content type, although for a very few nodes I do need to override this with node-level access control (for making a super-user page available in view-only mode to regular members). I'm not interested in per-user access control as such, per-role (with per-node override) is sufficient.

My site runs Drupal v7.2 (but I'm upgrading to 7.4 as I post this), and I've tried the modules named Node Privacy By Role and Content Access. Both of these work very nicely, except for the issue mentioned above.

# Answer
Uh, okay this is a little embarrassing ... I had my Drupal site update itself and its modules, and lo: it suddenly worked as intended. Whee.
> 2 votes

---
Tags: users
---


# Question
Title: What happened to the arguments part of views 3?
Am I just blind?

(I'm trying to pass the current page's nid into a block where I'm theming a view and want to filter the view by the nid.)

# Answer
Arguments are now called Contextual Filters.
> 6 votes

# Answer
They have been renamed "Contextual filters," and they have been moved in the third column that is collapsed by default.

In Drupal 6 (Views 6.x-3.x-dev) the URL arguments are still called "Arguments."
> 7 votes

---
Tags: views
---


# Question
Title: How do I add a file upload field to user profile?
I need to add a file upload field to user profile, and show it on profile page (not during registration). How can I do this?

# Answer
You should implement hook\_user(), and add code when the user edit form is being shown, and `$op` is equal to "form"; this is different from the form shown to the users when they are registering, which is handled when `$op` is equal to "register."

The hook documentation reports the following description for the "form" operation:

> The user account edit form is about to be displayed. The module should present the form elements it wishes to inject into the form.

To complete the information, on Drupal 7 the only way to add fields to the user edit form is to implement hook\_form\_alter(), or hook\_form\_FORM\_ID\_alter(); both the hooks are also used in Drupal 6, and they are the only way to remove form fields from the user edit form, while `hook_user()` allows to just add form fields.
> 1 votes

# Answer
Use Content Profile.

By default Content Profile puts the additional fields in a tab on the profile page. If you want them to be all in one page use Account Profile
> 3 votes

---
Tags: users
---


# Question
Title: How do you deal with multiple locations?
I'm sure this applies to offices with multiple locations, but I am trying to create a site for a charity that runs summer camps. I was wondering how would you suggest I present the different locations?

I looked at gmaps and open layers (they may do what I want but I couldn't figure out how so easily, I don't want to have to enter coordinates because locations are changing often and I want to make it easy for new staff to add/remove locations). Ideally it would be good to either have a map with markers that users can click on to see details of the location or to list the locations and once they click on it it shows it in a map.

So I guess there's two questions: 1) What tool can help me present this data in drupal 7?; and: 2) What tool can be used to manage the data?

# Answer
> 7 votes
I've been using GMap + Location to accomplish this. The site I've been working on involves Apartment Communities spread out all over the place. I created a content type for apt\_community which accepts location data (I only allowed an exact address but you can let the user pick a location on a map). Then I have a view that puts all the points on a map which I attach to a page.

Check this DrupalTherapy screencast on GMap + Location (http://www.drupaltherapy.com/gmap) and this other screencast Drupal Aficionado did on using GMap and Views (http://blip.tv/drupal-aficionado/gmap-location-and-views-1773822).

---
Tags: google-maps
---


title: View for Organic Group CCK field

text:
# Question
Title: View for Organic Group CCK field
I'm trying to create a View that displays a CCK Imagefield from an Organic Group node.

I have a content type called 'Subsite' that I'm using as the Organic Groups creation node. I've added a CCK Imagefield called "Banner" to this content type, so that each group has a banner image.

I'm creating 'Page' nodes and assigning them to Organic Groups.

Let's say I assign a page called "Page 1" to the OG "Group 1." How can I configure a View to display the banner on "Page 1"?

# Answer
In your view, you only need to bring up the node's parent group and display its banner field:

**Add relationships:** Organic groups: Group node (post)
**Add fields:** Content: Group banner, Relationship: Group node (post)
> 1 votes

---
Tags: 6, entities, organic-groups
---


# Question
Title: Comments only showing subject, no comment
Using Drupal 7 with a custom made theme, the comments are only showing Subjects, and ignoring the comment body.

In my comment.tpl.php file I have:

```
<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<?php print $picture ?>

<?php if ($new): ?>
<span class="new"><?php print $new ?></span>
<?php endif; ?>

<?php print render($title_prefix); ?>
<h3<?php print $title_attributes; ?>><?php print $title ?></h3>
<?php print render($title_suffix); ?>

<div class="submitted">
<?php //print $permalink; ?>
<?php print $submitted; ?>
</div>

<div class="content"<?php print $content_attributes; ?>>
<?php
  // We hide the comments and links now so that we can render them later.
  hide($content['links']);
  print render($content);

?>
<?php if ($signature): ?>
<div class="user-signature clearfix">
  <?php print $signature ?>
</div>
<?php endif; ?>

```

Any ideas on how to get the comment to show?

# Answer
> 1 votes
I found the solution and it was pretty obviously now that I found it. In content type --\> Edit --\> Comment Display --\> The Comment field was hidden! DUH!! :)

# Answer
> 0 votes
What you are using is not different from what used from the Bartik theme for its comment template file.

```
<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>

<!-- Omissis -->

<?php if ($new): ?>
  <span class="new"><?php print $new; ?></span>
<?php endif; ?>

<?php print render($title_prefix); ?>
<h3<?php print $title_attributes; ?>><?php print $title; ?></h3>
<?php print render($title_suffix); ?>

<div class="content"<?php print $content_attributes; ?>>
  <?php
    // We hide the comments and links now so that we can render them later.
    hide($content['links']);
    print render($content);
  ?>
  <?php if ($signature): ?>
  <div class="user-signature clearfix">
    <?php print $signature; ?>
  </div>
  <?php endif; ?>
</div> <!-- /.content —>

```

I would check if the applied CSS styles are not making the comment body invisible, or if there is a module that, because a bug or not, is not removing the body from comments. The last point is easy to check: If you change the theme, and the comments still show only the title, then it's not a problem with the theme being used.

---
Tags: 7, comments
---


# Question
Title: Build taxonomy categories with views, only children
I am trying to build a menu with taxonomy terms and views.

Lets say that I have a tree of taxonomy terms

1. Parent-1
    * child-1.1
        + grandchild-1.1.1
            - greatgrandchild-1.1.1.1
            - greatgrandchild-1.1.1.2
        + grandchild 1.1.2
    * child-1.2
        + grandchild 1.2.1
            - greatgrandchild-1.2.1.1
            - greatgrandchild-1.2.1.2
        + grandchild 1.2.2

I am having problems viewing only the children of the taxonomy menu. I want to exclude the current level, and only see the children, not the grandchildren of an item. So for instance.

When I am viewing child-1.1, I only want to see grandchild-1.1.1 and grandchild-1.1.2, not any of the great grand children. I don't want to see child-1.2 or the parents.

Thank you very much for your help!

# Answer
> 2 votes
Can you set up your Taxonomy view to accept the argument *Parent term* and pass it the current term? I don't know how complex your view is, but I got it to work in this basic example:

**View type:** Term
**Add arguments:** Taxonomy: Parent term
**Action to take if argument is not present:** Hide view / Page not found (404)
**Validator:** Taxonomy term
**Argument type:** Term ID
**Add fields:** Taxonomy: Term Term

That will display only the current term's children, i.e. those that have the current term as a parent.

---
Tags: 7, taxonomy-terms, views
---


# Question
Title: Why can't I change values in my cookies?
I'm storing my users city in a cookie.

I want that cookie to expire by browser session, so I don't want to store this information in $\_SESSION, because I want $\_SESSION to persist for the default 23ish days.

So I'd like to stick with Drupal storing all of its stuff in $\_SESSION as normal, but also set a cookie with a custom lifetime. When the user selects a city I set a cookie in my forms `_form_submit()` hook:

```
$c = 'Washington'; // ...or whatever
$_COOKIE['city']['cityname'] = $c;
setcookie('city[cityname]', $_COOKIE['city']['cityname'], 0);

```

If I print this out with `print_r($_COOKIE['city'])` I get:

```
Array ( [cityname] => Washington [state] => 65 )

```

Yay, it works!

Then the user selects a new city and the same code runs again (I know it's running because I've tried inserting a `die;` in there):

```
$c = 'New York';
$_COOKIE['city']['cityname'] = $c;
setcookie('city[cityname]', $_COOKIE['city']['cityname'], 0);

```

I print the $COOKIE value out again and get:

```
Array ( [cityname] => Washington [state] => 65 )

```

So the value hasn't changed and I'm left with the previous city. Why aren't my cookies values changing? Is there a way I can fix this, or a recommended workaround available?

# Answer
> 2 votes
OK, found the issue I think. The first cookie is set from the homepage. The second was set from a different page.

I looked in the Chrome "cookies" dialog and found out that I had multiple cookies all set with different paths.

`setcookie()` has a "`$path`" argument:

> The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.

So in my `setcookie()` I now do:

```
setcookie('region[state]', $state, 0, '/');

```

...and the path gets saved to "/" every time, and I don't end up with duplicate cookies causing confusion.

---
Tags: 6, cookies
---


title: $_SESSION empty

text:
# Question
Title: $_SESSION empty
I'm printing error messages (e.g. from the login form) in my page with `<?php print $messages; ?>`. Nothing is showing up.

I think my problem is that the $\_SESSION variable (which should contain these error messages) is empty.

I tried explicitly setting a session var in my page with `$_SESSION['test'] = 'wtf';`, which definitely inserted something into my drupal\_sessions table:

```
mysql> SELECT * FROM drupal_sessions;
+-----+----------------------------+-------------+------------+-------+------------------+
| uid | sid                        | hostname    | timestamp  | cache | session          |
+-----+----------------------------+-------------+------------+-------+------------------+
|   0 | 6oq6700jo1guhe89bue0kj8jl6 | 10.16.0.132 | 1311836508 |     0 | test|s:3:"wtf";  |
+-----+----------------------------+-------------+------------+-------+------------------+

```

Then I added a `hook_init()` which did nothing except `print_r($_SESSION); die;`. This printed out `Array ( )`, i.e. an empty $\_SESSION array.

So either Drupal isn't reading into the $\_SESSION variable properly, or something somewhere in my site (maybe my code) is resetting the $\_SESSION variable. I really need to track this down — where should I start looking? Is there an obvious way to try and debug this?

## login.inc

```
<div id="login">
    <?php print $messages; ?>
    <?php if ($user->uid) { ?>
        <p>You are already logged in as <span id="username"><?php print $user->name; ?></span>.</p>
        <p>Would you like to <a href="/logout/">log out</a>?</p>
    <?php } else {
        print drupal_get_form('user_login_block');
        $connector_block = (object) module_invoke('connector', 'block', 'view', 0);
        $connector_block->module = 'connector';
        $connector_block->delta = 'one_click_block';
        print theme('block', $connector_block);
        print fbconnect_render_button();
    } ?>
</div>

```

## init hook

```
function mr_misc_hooks_init() {
    print_r($_SESSION);
    die;
}

```

# Answer
The database was missing user 0. I followed the instructions at devbee.com to restore that user. I'm not sure why we were missing that user, but I hope it doesn't happen again.
> 3 votes

---
Tags: 6, sessions
---


# Question
Title: How do I reproduce this SQL with Drupal 7's query builder?
```
SELECT * FROM mytable
WHERE ('myfield1' = 'someval1' AND 'myfield2' = 'someval1')
   OR ('myfield1' = 'someval2' AND 'myfield2' = 'someval2')
   OR ('myfield1' = 'someval3' AND 'myfield2' = 'someval3')

```

I'm trying to do this with a foreach() loop:

```
foreach($mywords as $w)
{
  $myquery
    ->condition('myfield1', $w)
    ->condition('myfield2', $w);
}

```

Each iteration of the loop, however, should add the next set of conditions.

# Answer
> 0 votes
You need to do something like this:

```
$query = db_select('mytable', t)->fields('t');
$condition = db_or();
foreach($mywords as $w {
  $condition->condition(db_and()->condition('myfield1', $w)->condition('myfield2', $w));
}
$result = $query->condition($condition)->execute();

```

This is not tested but should work.

For reference, see `db_or` and `db_and`

# Answer
> 0 votes
The conditions you add in that way are added using and "AND" operator; see the code of the constructor of the `SelectQuery()` class, and SelectQuery::condition

```
  public function __construct($table, $alias = NULL, DatabaseConnection $connection, $options = array()) {
    $options['return'] = Database::RETURN_STATEMENT;
    parent::__construct($connection, $options);
    $this->where = new DatabaseCondition('AND');
    $this->having = new DatabaseCondition('AND');
    $this->addJoin(NULL, $table, $alias);
  }

  public function condition($field, $value = NULL, $operator = NULL) {
    $this->where->condition($field, $value, $operator);
    return $this;
  }

```

This means you need to call `myquery->condition()` only once, or the resulting query will use "AND" between the conditions. `SelectQuery::condition()` accepts also an instance of DatabaseCondition, such as one returned from db\_or() and db\_and(); both the functions are helpers build on the constructor of `DatabaseCondition`.

```
function db_and() {
  return new DatabaseCondition('AND');
}

function db_or() {
  return new DatabaseCondition('OR');
}

```

The code should then build a `DatabaseCondition` object, and pass it to `myquery->condition()`.

---
Tags: 7, database
---


# Question
Title: Gmap Error "Javascript is required to view this map" when embedding the node in another node
In my drupal 6 site, I use finder embedded in a node, to search for another node.
When user select a result the node is loaded in the same page.
The final structure is

* parent node
    + finder embedded
    + parent node description
        - resulting node

Everything works fine, except that the Map loaded in the resulting node is not displayed.
I get this error "Javascript is required to view this map".
Obviously I've checked what's wrong, and I've seen that the required JS are missing (gmap.js, marker.js, etc..).

How can I force GMap to load js if they are missing?
Why do you think this is happening?

**UPDATE**

The problem is related to Ajax. If I take the same scenario and hit Enter instead of Find, the request is made without using Ajax and the map is shown correctly.
Using the Find button (Ajax request) the problem persist.

Any solution?

# Answer
> 1 votes
`GUnload` is part of the Gmap API. Are you loading the Gmap js files served by Google?

The error would happen if the JS file from Google is:

* Missing.
* Has not been parsed when the code giving the error is executed.

*To give a more thorough answer more details are needed.*

**Update**

The Gmap module is a bridge to the Gmap JS API that Google has created. The actual Gmap JS API is not included in the module itself but is served by google. It's included using the following line:

```
drupal_set_html_head('<script src="'.
  check_url(url('http://maps.google.com/maps', array('query' => $query))).
  '" type="text/javascript"></script>'
);

```

The error you are getting, it is caused by the lack of the above JS file, or because it's loaded after the gmap module JS code is run.

# Answer
> 1 votes
I think you should force gmap to include JS in your parent page (or, to test, every page). Insert this in your hook\_init() or in your template.php:

```
_gmap_doheader();

```

The reason is that, if you include JS by AJAX, it may be not ready when Gmap uses it.

Edit: I looked at the code again, and changed the code.

---
Tags: location, google-maps, nodes
---


# Question
Title: How do I add client-side form validation to a Drupal form?
How do I add client-side form validation to a Drupal form? For example, in the comment module. If the vistor don't enter the email address, I want to popup a window that says: "please enter the email address".

I hope someone can give me an example of how I do this.

# Answer
You can either try the Clientside Validation module ( I haven't ) or you can handle it via jQuery required plugin for specific form elements that you require by adding validation rules in your custom js file and loading it with your custom theme - http://docs.jquery.com/Plugins/Validation/Methods/required there is no perceivable Drupal form API quirks that you need to handle as its all on the client side.
> 4 votes

# Answer
I'm biased since i created http://drupal.org/project/clientside\_validation, but it is using http://bassistance.de/jquery-plugins/jquery-plugin-validation/ to do all validations, the benefit of the module is that you don't have to write any code
> 5 votes

# Answer
Use a preprocess function to load http://bassistance.de/jquery-plugins/jquery-plugin-validation/ and a script that has specific settings for your node form.
> 1 votes

---
Tags: 7, forms
---


title: Validation on modal dialog forms

text:
# Question
Title: Validation on modal dialog forms
I opened my form in a jQuery modal dialog using the Simple Dialog module. I am unable to do any sort of validations on it.
Is it a limitation of the module? Would it validate if I use any other method of creating a modal dialog form, such as using a CTools modal dialog, or using the Drupal overlay?

# Answer
I used the Chaos tool suite module, and it does that!
> 2 votes

---
Tags: forms
---


title: How can I customize the first sidebar?

text:
# Question
Title: How can I customize the first sidebar?
I am trying to customize the Bartik theme.
How can I customize left sidebar? I want to add some more links, and remove the search fields.

# Answer
You can disable the search block in "Structure -\> Blocks" in the admin panel. On the same page you can create a new block and add some links to it. Then add the block to the side bar.
> 4 votes

---
Tags: theming
---


# Question
Title: Is there any module that can show whoever edits a node?
Is there any module that can show whoever edits a node, just like how happens on Stack Exchange sites, where the user who edited a post is shown together the author of that post?

# Answer
This article should be able to help you: Adding 'Last edited by name some time ago' information

I'm not sure how you want it to look exactly, but with a preprocess function and a simple template edit, you can add an editors information. You can style this however you like and add/remove information, but to show the editor's name and the edit date/time do the following:

Add to template.php (or add the code to the preprocess\_node function if already exists):

```
function neuco_preprocess_node(&$variables) {
  $node = $variables['node'];
  $editor = user_load($variables['revision_uid']);
  $variables['edited'] = 'Edited by ' . theme('username', $editor) . ' on ' . format_date($node->changed, 'medium');
}

```

In your tpl file (node.tpl.php, node-YOURTYPE.tpl.php, etc):

```
<?php print $edited; ?>

```

Functions used: `template_preprocess_node()`, `user_load()`, `format_date()`, `theme_username()`
> 2 votes

# Answer
You might be looking for the Diff module, or any revision module.

Here is a quote about it (from the module's project page):

> ... adds a tab for sufficiently permissioned users. The tab shows all revisions like standard Drupal but it also allows pretty viewing of all added/changed/deleted words between revisions.
> 1 votes

---
Tags: nodes
---


title: Search API requirements

text:
# Question
Title: Search API requirements
I'm trying to get the Search API module to work on my Drupal 7 installation, but I get the following error when I go to Home » Administration » Configuration » Search and metadata » Search API » Default node index:

> The server this index currently lies on doesn't support facets. To use facets you will have to move this index to a server supporting this feature.

What steps should I follow, in order to make my server compatible with the Search API module?

# Answer
You can't use facets on MySQL (for the moment), from the project page:

> ### Search facets
>
> This module provides the ability to create facets on any search executed anywhere in Drupal, be it a search page, a view or any other source. The feature isn't available for all servers, though, since it would be too complex to implement for some service classes. Right now **only the Solr servers** support this, facet support for the database-based searches might be done in the future.

This means that you can't use facets, but you can still use Search API to search your content.
> 4 votes

---
Tags: search
---


title: what to include?

text:
# Question
Title: what to include?
I am writing my own PHP program on root or inside a module which is suppose to return the registration form. The content of the abc.php program is:

```
<?php
  $form1=drupal_get_form('user_register_form');
  $output1 = drupal_render($form1);
  echo $output1;
?>

```

this is called by a jQuery function actually and the result is to be inserted in a popup DIV. But it gives me the the error:

> undefind function drupal\_get\_form.

What do I need to include in the file so this error disappears?

thanks in advance

# Answer
> 2 votes
The answer depends on where you put the PHP file. Generally speaking, in Drupal you don't create a file that bootstrap Drupal, but you normally create a module or a theme, which is invoked by Drupal after it has been bootstrapped, or when the boot is still not completed (that is the case of the `hook_boot()` implementations).

* Inside the directory of a module: As you have a module, all you have to do is be sure the file is included when the module is running. That is something Drupal automatically do, if the hook\_menu() implementation is similar to the following one (it is the actual implementation made from the Book module). When, the users access "admin/content/book/settings," Drupal loads the book.admin.inc contained in the directory containing the book.module file.

```
function book_menu() {
  $items['admin/content/book'] = array(
    'title' => 'Books',
    'description' => "Manage your site's book outlines.",
    'page callback' => 'book_admin_overview',
    'access arguments' => array('administer book outlines'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'book.admin.inc',
  );
  $items['admin/content/book/list'] = array(
    'title' => 'List',
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  $items['admin/content/book/settings'] = array(
    'title' => 'Settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('book_admin_settings'),
    'access arguments' => array('administer site configuration'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 8,
    'file' => 'book.admin.inc',
  );

  // …
}

```

```
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
echo drupal_render(drupal_get_form('user_register_form'));

```

There are few cases where creating a file similar to cron.php or update.php is really necessary, such as when you create a soap.php file similar to xmlrpc.php, but for SOAP requests. For cases like yours, you just need to create a module, and implement the necessary hooks.

# Answer
> 2 votes
You should not write code in stand alone php files and call them (Unless you know what you are doing and do it for performance reason, to avoid Drupal bootstrap on a pure external web service call could be one such example).

What you should do instead is to write a module. Use `hook_menu` to define the path that you want to listen for, and create a callback function that will handle incoming requests. Doing it like this will allow you to actually use the Drupal APIs.

You can lookup the hooks and functions you need to use at the Drupal API reference site

# Answer
> 0 votes
To get started check out http://drupal.org/developing/modules which walks you through developing modules in Drupal or check out http://drupal.org/project/examples that shows you how to use the Drupal API.

---
Tags: forms
---


# Question
Title: Render a drupal form retrieved by drupal_get_form
In Drupal 7, I have a preprocess function retrieving a form like so:

```
$contact = drupal_get_form('privatemsg_new');

```

$contact is then a fully populated form array with the right fields and elements. After that, I tried drupal\_render and render, but neither one show a themed output in the node. What do I have to do to display the form?

# Answer
The correct answer is to use `drupal_render`, which is used for render arrays like the form is. I tested this with a different form, and got the desired result so what you're doing should be right. Most likely you have a different error some where in your code causing this.

```
$html = drupal_render(drupal_get_form('form_id', $args)));

```
> 5 votes

---
Tags: 7, forms
---


# Question
Title: Adding the current node title as the value of the comment form title?
**I want a value to be automatically added to the title text-field in the comment form ; this value would be indeed the current node title.**

I've started working on a `hook_form_alter()` (added in a custom module already installed and enabled) like this one :

```
   function ta_module_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == 'comment-form') {
        $form['comment']['title']['#value'] = 'Blablabla';
    }
   }

```

But as you might guess it's not working... I've got several issues:

* Is the `$form_id` the right one ?
* I didn't manage to successfully use `print_r($form)` (or it returned nothing) so I guessed the path to the title value. Might be incorrect too...
* And finally, I really don't know how to get the current node title variable, so as to attribute it the title value!

Thanks for reading, I hope I've been understandable ! ;)

# Answer
You're right, you most likely have the `$form_id` wrong. To check this you can use `drupal_set_message($form_id);` and refresh the page to see all form ids on the current page.

Once you have the form id correct, *then* you can use `print_r($form);`

For example, I got this working on the comment form on my node type "Announcement":

```
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'comment_node_announcement_form') {
    $form['subject']['#default_value'] = $form['#node']->title;
    //print_r($form);
  }
  //drupal_set_message($form_id); // Use to get $form_id
}

```
> 2 votes

---
Tags: 7, forms, hooks, comments
---


# Question
Title: Dropdown Menu with 20+ items gets cut off by a views content rotor
I'm trying to spruce up a Drupal 6 site, but I'm running into some issues with a views slideshow (specifically, rotorbanner) and having a menu with ~20 items.

When the menu expands, I can see all the links, but whenever I mouseover on a link that's within the "slider" block, the list disappears.

My thought was to fix this by just making the menu two column, but I'm running some difficulties with that and maybe fixing this will be easier.

I'd prefer not having 20 menu items, but that is the way my org does things, alas : )

For an example, go this dev site and hover over the "networks" section on the menu

Thanks!

# Answer
This is an awfully localized question, but I got this to work fine in Chrome and Firefox by adding:

```
position: relative;
z-index: 1;

```

to the slideshow block (`<div id="block-views-speakerslider-block_1">`) or any of its containers (`<div id="wrapper">`, `<div id="content">`, etc)
> 1 votes

---
Tags: views, 6, routes
---


title: "Demonstrate Block Regions" not showing

text:
# Question
Title: "Demonstrate Block Regions" not showing
I did a minimal install, with a desire to get rid of some of the stuff my site-to-be won't need.

The problem I have... is I can't seem to get Demonstrate Block Regions working. It shows up on a "Standard" install... but not the "Minimal" install on 7.

Top one is Standard install. Bottom one is Minimal.

What module or setting am I missing?

# Answer
> 8 votes
You are missing the System help block.

That is what is displaying the current help tips:

SS http://tardis1.tinygrab.com/grabs/99f4a5fef70efc8f19ddb137c664c7cf22b0599ff5.jpg

When you activate the block the help tips will be displayed whenever possible.

---
Tags: blocks, theming
---


title: hook_menu_alter() doesn't work

text:
# Question
Title: hook_menu_alter() doesn't work
I have implemented `hook_menu_alter()` in a module I have created. I have printed something inside that function call but nothing shows up, alhough the `hook_init()` implementation from the same module is executed.

somebody has any idea regarding this issue?

```
function mymodule_init(){
  print "here";
}

function mymodule_menu_alter(&$items) {
  print "I am here";
  return $items;
}

```

# Answer
`hook_menu` and `hook_menu_alter` are only called when rebuilding the menu table, not on each table load. So you won't see your print statements.

As a side note, I would use `drupal_set_message()` rather than print when debugging.
> 0 votes

---
Tags: 6, routes
---


title: Pass a node reference to a module form

text:
# Question
Title: Pass a node reference to a module form
I've created a bid module that allows the users to bid on an auction through a node reference. I'm using `hook_form_alter()` to create the form on the 'create bid' page, and I would like to perform some SQL queries dealing with the referenced node.

How do I load the node reference?

# Answer
> 1 votes
To load a node, use

```
node_load($nid);

```

This requires that the node is saved and that you have it's nid.

*To give a better answer more details are needed*

---
Tags: nodes, database
---