# Question
Title: Creating facets for custom contents added by CCK in apache Solr module
I was unable to create Facet for a CCK field, in the sense that for a specific CCK content type i was unable to group.

This could be summarised as my problem statement

Ex. CCK Field - Article Author

Actual Result : No Group (No of Search Records) Expected:

* Author 1 (2)
* Author 2 (5)

etc....

This is my primary concern, I need to create facet for the custom content types.

Please let me know if any of you have previous experiences with implementing Apache Solr for Drupal. Also let me know your kind suggestions and feedback.

My drupal version is 6.22.

Note: Based on my googling experiment i set the CCK field type in question as text and not string but still didn't help me much.

# Answer
> 1 votes
I was finally able to get this done with good assistance from one of the module's maintainer.. This is the issue list query comprising further details and some sample code. Hope this servers of some help to anyone using solr search.

Cheers!!

---
Tags: 6, search
---


title: How to show RSS icon for a views feed?

text:
# Question
Title: How to show RSS icon for a views feed?
I created a feed for one of my views. I was under the impression that Drupal would automatically display an RSS icon on a view that has a feed? I see that page.tpl.php prints an icon:

However, I'm not seeing the icon. What am I missing?

# Answer
You need to attach your `Feed` display to one of your `Page` displays (within the same view).

To do this, in `Feed settings` click on `Attach to: None` and tick one of previously created `Page` displays (or create one first if you haven't already done so). Only then the RSS icon will be displayed on the page your feed is attached to.

Here's a screen shot for anyone who (like me) can't see the wood for the trees.
> 10 votes

---
Tags: 7, feeds
---


# Question
Title: How to retrieve "profile_" only filelds?
Now I load user profile fields of a `$uid` by:

```
$thisuser = user_load(array('uid' => $uid));
profile_load_profile($thisuser);
drupal_json($thisuser);

```

Is there a quick way to filter only fields with leading `profile_` in `$thisuser` and so `drupal_json` displays only profile values?

# Answer
> 1 votes
The condition should be `preg_match("/^profile_/", $profile)`. Have look at preg\_match.

---
Tags: users
---


title: custom login form

text:
# Question
Title: custom login form
I want to create a custom login but I don't know where to start,

See the image for more details:

Is there anyway to create a custom HTML and add it the drupal login logic? maybe with a REST or API?

# Answer
> 3 votes
Here is a very good tutorial on Customising the login form.

# Answer
> 2 votes
I got what you need but please mention which Drupal version you are using; you can have a look at this module if you need: It is one of the best module for customizing the login of a Drupal system in the Drupal way.

---
Tags: forms, media, users
---


# Question
Title: Import site from HTML pages (currently static files in directories, not in a CMS)
I've taken over a small website (link here, in case it helps) which is currently composed of largely static HTML files (with a few PHP includes thrown in to generate menus and footers, etc). I want to migrate it into Drupal, as I'm fairly familiar with this and it'll make the site more manageable. My question is: what's the best way to do this?

I've found plenty of modules to migrate sites from CMSes like WordPress, but none to import static files organised in directories. Some research turned up the Migrate and Feeds modules, but I'd like some guidance on whether to use something else, or whether to use these, and if so how. Should I write a perl script to pull out the content and titles and current paths or pages into a CSV of some format? Presumably others have done this, so it'd be interesting to see best practice, or examples...

Many thanks

# Answer
> 1 votes
I'm surprised that you didn't find Import HTML yet. Personally, I haven't used it since the Drupal 5 days, but just give it a try and see if it does what you need.

---
Tags: migrations, importing-exporting
---


# Question
Title: Modifying superfish menus to gives extra block of data
I am using superfish menus and it works fine and i want to add extra column in superfish menu which will display some stand alone data. how do i alter superfish menu to do this. I have shown in image what i need to do.

# Answer
I am not sure you can achieve this with Superfish without a major hack to the module. Try using OM Maximenu which can create menus with all other module blocks you want as attachments, modules like views, slideshow, menu, user, nice menus, quicktabs, and custom blocks with tables, lists, images, videos, etc.
> 1 votes

---
Tags: 7, navigation
---


# Question
Title: How to disable automatically generated comments in node, but enable programmatically created comments?
I decided to programatically print comments un Views using PHP footer. The problem is that they now appears twice (my code + default). When I disable comments in content type settings, both disappear. How can I disable the default comments and keep my comments printed by php code? I tried to edit node.tpl file. but there is no section responsible for showing comments there (I use Garland).I do this because I am using a complicated views structure and I would like the comments to be displayed below the node, but not at the end of the whole view. Any advice appreciated.

# Answer
Configure comments to be show in separate page, and you'll be able to show them with your view. Also, you've to hide the comment link if you do it.
> 1 votes

---
Tags: views, 6, comments
---


# Question
Title: How can I list all the terms of a given vocabulary using Views?
I just need to list all the terms of the "Colors" vocabulary using the Drupal 7 version of Views. I thought it was simple to do it, but I can't find a way to get it.

I can't use contextual filters.

# Answer
> 3 votes
You need to build the view from a taxonomy base as shown in this screenshot (I'm showing Tags; you would need to show Colors):

# Answer
> 0 votes
Funny. I answered a similar question with a similar answer (and image) on Stackoverflow a while back, so had a sense of *deja vu* when seeing this question and response.

Of course you can also add a block or page display in the first step (see image I provided for the earlier question of this nature -- again using "tag" instead of "color")

If you aren't already pretty used to Views, it can help to experiment and learn about the different "display format" options.

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


title: Hiding block title when customizing

text:
# Question
Title: Hiding block title when customizing
I would like to hide the block title when customizing a block, but I didn't find any solution on the internet, Can you please help me?

```
function custom_theme(&$existing, $type, $theme, $path) {

  $hooks['user_login_block'] = array(
    'template' => 'templates/user_login',
    'render element' => 'form',
    // other theme registration code...
  );
  return $hooks;
}

```

# Answer
You can do it easily directly in the configuration page of block by adding `<none>` in the title field setting.
> 8 votes

# Answer
You can also hide it by setting the CSS "display" property to "none."
> 1 votes

---
Tags: 7, theming, blocks, hooks
---


# Question
Title: Does node_save create all fields associated with a custom content type automatically?
I have a custom content type and want to create new nodes in code. The content type contains fields, some will be set with values and others left empty. Is it necessary to define all the fields using `$node->field_custom_name[$node->language][0]['value'] = 'field value';` or just the ones with values to complete the node definition?

# Answer
> 2 votes
You can happily omit the empty ones, there's no problem. When consulting the newly created node, `node_load()` will retrieve all the attached field and build the correct object.

---
Tags: 7, nodes
---


# Question
Title: Effecient modules which will give me users location and country information
I am using drupal 7. I searched and found lot many modules to give users location and country information. So just wanted to know which is the efficient module which i should use.

# Answer
Take a look at Smart IP.

> Smart IP identify visitor's geographical location (longitude/latitude), country, region, city and postal code based on the IP address of the user. These information will be stored at session variable (`$_SESSION`) with array key 'smart\_ip' and Drupal `$user->data` object with array key 'geoip\_location' of the user but optionally it can be disabled (by role) at Smart IP admin page.
> 2 votes

# Answer
I'd recommend IP-based Determination of a Visitor's Country module.
> 1 votes

---
Tags: 7
---


title: How to add tabs to a form?

text:
# Question
Title: How to add tabs to a form?
On a node add/edit form I have "upload file" and "link to url" form fields. I would like to create tabs for "upload file" and "link to url" for each field.

I would like ajax style tabs that don't require a reload of the page. Is there a solution for that in Drupal or do I need some css magic?

# Answer
> 2 votes
Use the Field Group Module. It comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers.

**Field Group:**

> Fieldgroup will, as the name implies, group fields together. All fieldable entities will have the possibility to add groups to wrap their fields together. Fieldgroup comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers.
>
> The field group project is a follow-up on the field group module in CCK. The release will only exist for Drupal 7 release and higher, so since the existence of the Fields API in core. By moving field group to a separate module, this may open some new perspectives.

---
Tags: 7, forms, routes
---


# Question
Title: Translate the frontend part of the site only
I am working at a project that needs a biilingual translation (content + interface). I've installed the following modules:

```
Locale + Content translation (core modules)
Internationalization Module (i18n)
Variable Module (required by Internationalization) – it deals with meta tags
Admin Menu

```

I can't find a way to:

To provide interface translation for front-end only. Admin should be in English

**Note: I assume this can be done by deactivating the language block on admin side) but how can this be done without duplicating the theme (the same theme for admin but with the block language disable).**

How can this tasks could be accomplished?

# Answer
> 2 votes
The Administration Language module can do this:

> 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).
>
> You can use the standard Languages page to choose the language of the admin pages.

# Answer
> 0 votes
Is it a problem if your contributors (the ones who access the back-office) see the front-end in English ?

If not, just set their default language as English. If they want to browse the front-end in the original language, just disconnect or use a "private browsing" option.

---
Tags: i18n-l10n
---


title: Comment form not showing

text:
# Question
Title: Comment form not showing
I got a panel and added a comment form for this certain node type but the comment form does not show up.

* I have enabled commenting for this content type and appropriate permissions (can post comment) for any authenticated user.
* I tried disabling the panel for node templates.

In both case the comment form still does not show up. What could be wrong?

# Answer
If you have changed the content type to allow for commenting, it does not back-propagate to existing nodes. So, check to see the individual comment settings on each of nodes that it does not appear on to make sure they are indeed enabled.
> 14 votes

---
Tags: 7, comments
---


title: Drupal 7 views, filter by owner

text:
# Question
Title: Drupal 7 views, filter by owner
I need to show the list of the content created by the currently logged-in user. How do I do this with the Views module?

# Answer
> 13 votes
1. Create View on Content, and click "save and edit".
2. Add necessary fields. Title, body, post date, etc.
3. Expand the "Advanced" pane.
4. Add new Contextual filter.
5. Check "Content: Author uid"
6. When the filter value is NOT in the URL -\> Provide default value -\> User ID from logged in user (if you are putting this View in profile pages, better choose "User ID from URL")
7. Apply and save.
8. :)

**Update**:

**Here is a short list for Views 2:**

1. Create a View on node as primary table.
2. Add necessary fields as you want.
3. Click Add new argument(Little plus sign under arguments pane). Check "`User: UID`" and click add.
4. When the argument is not given, choose to use a default argument, and set it to logged in user.

**Update 2:**

If you want to restrict access to own content, see https://drupal.stackexchange.com/a/41899/1899

# Answer
> 3 votes
You can also achieve this by the following in your view:

Add Relationship "Content: Author" and check require relationship, then add a filter for "User: Current" and chose Is the logged in user.

This is probably a better option if you only want to display posts created by logged in user, as it is url independent.

---
Tags: views
---


# Question
Title: How do I use the Cufón module to change the title of a view?
I bought a new theme and I am not getting much support from the place I bought it from. My theme has nice fancy titles in blocks, which are implemented using the Cufón module to change the text. I was wondering if it was possible to do the same with the title of my views.

I have tried overriding the views-view-table-tpl and added `<h2 class="title cufon">` around the title, but it didn't have any effect.

How can I achieve this?

# Answer
> 2 votes
Edit the page.tpl.php template, and add the cufon class to the page title (`<h1>`). Alternatively add a h1.title rule to the Cufón module.

If you dont't use the Cufón module, add this to your template.php.

```
drupal_add_js('Cufon.replace('h1.title');', 'inline');

```

---
Tags: views, theming
---


# Question
Title: get user profile picture at registration
I am using Drupal 7.

I follow this link to enable profile picture of user.

Now i want to get profile picture from user at the time of registration.

How can i get this?

Any help will be appreciated.

# Answer
> 2 votes
There is a development version of the Register with Picture module.

---
Tags: 7, users
---


title: No fields to select

text:
# Question
Title: No fields to select
In View 3, the contextual filter page is missing some fields; only content, content revision, content translation, file usage, global, search, and user show up. Is this an installation issue?

# Answer
> 1 votes
Some Tutorials for Drupal 7 show how to use Contextual Filters using Fields, but fields are called Content in the current versions of Drupal7 / Views 3.

---
Tags: 7, entities, views
---


title: How to show drupal menu in drop down?

text:
# Question
Title: How to show drupal menu in drop down?
I am trying this code

```
   echo "<select>" .$main_nav = menu_tree('secondary-links');

            print"<option>"     .    $main_nav   . " </option></select>";<br>

```

but it display all menu at ones

# Answer
> 1 votes
It looks like you're building a so-called "jump menu", is that correct?

It's not considered good practice to code a menu into a template like you're doing in your example. Try to build the functionality of your site with modules (existing ones, or custom) and use the theme (template.php, CSS files, template files) for appearance only.

If you need a jump menu, have a look at the Jump module. It provides a block for every top-level menu and every vocabulary, so it could get you exactly what you need without writing one line of code.

---
Tags: 6, theming, routes, navigation
---


# Question
Title: taxonomy-term at the automatic creation of url alias of a content path
In Drupal 7, how i can use the taxonomy-term at the automatic creation of url alias of a content path?

# Answer
> 2 votes
Install Pathauto and Token. Pathauto will let you create automatic aliases, and Token will supply the content's taxonomy term as a substitutable value.

# Answer
> 0 votes
By using Pathauto(7.x-1.0) & Token(7.x-1.0-beta7) you can not achieve it at this moment I guess. As I also faced the same problem. In my case, I have the following URL patterns in D6 site, D6 --\> \[vocab-raw\]/\[term-raw\]/\[title-raw\] Now, I suppose you have a fresh D7 installation not an upgrade. So If you have a fresh D7 installation do the following, Create a field in the Content Type as "Term reference" name it "Category" or so. If you are using a upgraded D7 site from D6 site, it will be automatically done.

Now there is two way to do it. 1. Use the Dev version of the Token Module so you will be able to use taxonomy/vocabulary token variables. As the docs suggests,
http://drupal.org/node/741914#comment-4006696
http://drupal.org/node/741914#comment-3714746
But I have used it and haven't got the Success. 2. So, the next one that worked for me is using the Entity Module. Install and enable the Module and then do the following, Go to URL Aliases administration page -\> Patterns. Expand replacement patterns for Content paths -\> expand Nodes -\> you'll see category at the bottom, expand it. OK, now you're ready to use taxonomy terms tokens. I am attaching an image for reference.

---
Tags: path-aliases
---


# Question
Title: How to add Span before my <a tag only for main menu 1st level items
I need to add a span tag before mt

if i add like

```
function mytheme_link($variables) {
  return '<span><a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</a></span>';
}

```

it will add for all the menus

and if i use

```
function mytheme_menu_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }

  $link['localized_options']['html'] = TRUE; //let l function know that our link title includes html
  return '<span>'.l($link['title'], $link['href'], $link['localized_options']).'</span>';
}

```

it does not add at all.

# Answer
you have forgotten the '#' before localized\_options, title & href.

```
function mytheme_menu_link($link) {
  if (empty($link['#localized_options'])) {
    $link['#localized_options'] = array();
  }

  $link['#localized_options']['html'] = TRUE; //let l function know that our link title includes html
  return '<span>'.l($link['#title'], $link['#href'], $link['#localized_options']).'</span>';
}

```

for main menue only use `theme_menu_link__main_menu($var)`
> 3 votes

---
Tags: 7
---


title: Errormessage with reference module

text:
# Question
Title: Errormessage with reference module
When I want to add a link between two content types I got the following error:

> Notice: Undefined index: args in \_node\_reference\_view\_settings\_validate() (line 161 of /var/www/vhosts/nielsjansen.be/httpdocs/drupal/sites/all/modules/references/node\_reference/node\_reference.module).

Settings were saved but with this error. Is this a problem?

# Answer
> 2 votes
You should report this in the module's issue queue.

Notice type errors are most of the time harmless and caused by sloppy programming or some edge case the developer didn't think of.

---
Tags: nodes
---


# Question
Title: Why would I want to use Universally Unique IDentifier (UUID) in Drupal?
I see that a lot of people are using Universally Unique IDentifier (UUID). What is it? And, why do I want to use it with Drupal?

# Answer
If you want to create an UUID for you content you should use the modules. UUIDs can be used for content staging and such.

The problem is that Drupal uses serial ids for the content (nodes), so if we have the same site installed different places, the id for the same content most likely will be different. (fx in one environment the node id might be 137, while it on another might be 153)
This makes it very hard to track changes on the same content in different environments. The idea with UUIDs is to create a id that is the same on all environments.

So you could have content writers work on a stage site, have it reviewed, and the put the changes out on the production server, without messing everything up in the process.
> 14 votes

---
Tags: entities
---


title: The Login block has vanished

text:
# Question
Title: The Login block has vanished
I haven't changed it in */admin/structure/blocks* and it is still there.

All that I can think that I installed a few modules to try them out and then disabled them and maybe that caused it.

In any case, my users can't log in and I am in big trouble.

How to go about debugging the problem? Thanks.

---

Update: I am not logged in (I see "Log in or register to post comments"). Even when I load /user/logout the login block is not there (not in the HTML)

The "recent log messages" shows nothing out of the way.

# Answer
The modules you were experimenting with and then disabled, did you go through the uninstall process? Also, flush you caches.

I hope that helps.
> 1 votes

---
Tags: 7, debugging
---


# Question
Title: How to append fields to published node in drupal?
A node once published should not be edited, but extra fields can be added to that node. How can i do it? For example , lets say i have a content type called 'employee'. Once i create this content i cannot edit that node but can only add more information to that node. this extra information must be stored in the node's column. Is it possible ? or is there any other way?

# Answer
guess its possible with a combination of hook\_form\_alter and hook\_nodeapi

Do check out these methods... hope it helps...
> 1 votes

# Answer
Ah, just hit me - I think I know what you could have in mind - kind of "locking" some fields, so that their values cannot be edited once they are saved, still though users could provide values for other fields, is that it?

If that's the case, have you looked at Field Permissions and Workflow Fields modules?
> 0 votes

---
Tags: entities, nodes
---


title: Combining different content types

text:
# Question
Title: Combining different content types
I do not have much experience with Drupal but I have a question. I have a content type Hotels with general information about the hotel but also with a field country and country information. I was thinking to make a content type Country with fields like country information (country Name (England), country description (England is an island), map (googlemaps). So when I have to add 10 hotels in the same country I do not have to write the same country information again and again. I want to combine the content type HOTEL and COUNTRY but I really don't know how to do it?

# Answer
Set up two content types, "Hotel" and "Country" and use the Entity References module to define a relationship between the two. Then configure it to display a "Rendered entity" formatter, that renders the references entity using a configurable view mode
> 2 votes

# Answer
For addresses you could use the location or addressfield modules. That will help you don't the road when you integrate with other modules, like gmaps.

The references module is a another good option.
> 1 votes

---
Tags: nodes
---


# Question
Title: Using Drupal 5 Gmap + location. What's the Drupal 7 equivalent?
I have an existing Drupal 5 site that I want to port over to Drupal 7. In my existing site, I have custom CCK types for, for example, a business type such as restaurants. I have the Location and GMap modules enabled. When entering a new restaurant, I type in the address of the restaurant and it is geocoded and the node type displays a map.

Now in Drupal 7 I'm trying to figure out how to do the same thing. I know CCK got partly rolled into Drupal 7. Which modules should I use for entering in the address info? I looked at the Location and GMap modules but they're both currently in dev only and I don't want to run development modules on my production site. So what's the drupal 7 way to handle address info, geocode it, and display a google map?

# Answer
> 2 votes
I found this blog post which looks promising: Placing Users on a Map in Drupal 7 - with Openlayers, Addressfield and Geocoding

It says to use a combination of: Addressfield Geofield Geocode Openlayers

Except geocode doesn't seem to have an official 7 release

**UPDATE**

I successfully got this working, using this blog post as a foundation. The article is talking about adding map data to user profiles. In my case, I wanted to add map data to content nodes so I didn't need the Profile stuff. I used the following modules (and their dependencies):

Yes, some of these are dev modules which is not ideal, but it seemed unavoidable to get the functionality I wanted.

In the article he talks about using his own fork of the Geocode module, but I found using the Geocoder (note the "er" ending) module (as suggested by the geofield module) instead worked fine.

**Overview**

In a nutshell this solution uses Address field to hold the address data and geofield to hold the coordinate data and OpenLayers to display the map. The geocoder module is the glue between the address data and the empty geofield, taking the address data and populating the geofield. The OpenLayers module uses the geofield coordinates to display the map.

**Steps**

I created a "Map" in OpenLayers which is basically like a preset of how you want the map to look and behave (e.g, map type, zoom level, etc). This takes some tweaking to get things setup the way you want them.

Then I added a content type xyz. In that content type I clicked "Manage Fields" and added an address field (Postal address). Then I added a Geofield, and in the widget drop down I chose "Geocode from another field". In the settings for the field I was able to choose the Address field I created earlier as the source.

Then in the "Manage Display" section of my xyz content type, for my geofield I chose "OpenLayers" from the Format drop down list. And in the configuration of that field I chose the OpenLayers map type I had created earlier.

One thing I'm not crazy about is with the OpenLayers module; I can't seem to get the normal Google Maps pan and zoom controls and instead get some somewhat funky looking pan/zoom controls.

**UPDATE**

Apparently you can customize the pan and zoom controls using any images you like via css. This blog post discusses it at the end: Take Control of Your Maps

# Answer
> 1 votes
I've used the Geolocation module successfully. It provides a widget for entry of the location and a formatter for display as a map.

---
Tags: 7, location, google-maps, entities
---


# Question
Title: How to display inbox messages and sent messages order by date - private message module
In private message module inbox and sent messages should be display by time wise.

Right now,

**It is displaying where the unread messages list first and then the read messages list second.**

But based on my requirement

**All the messages should be displayed in date order weather it is read or unread**

How can I do this?

# Answer
Have a look at the following issue: http://drupal.org/node/850932
> 1 votes

---
Tags: privatemsg
---


# Question
Title: Newbie Question: Modify forms before render
I'm trying to style all the text inputs with and text areas from the forms.

They are complex images so I probably will have to build a div wrapper in order to do this. There is anyway to replace all the

```
<input>...</input>

```

to something like

```
<div><input>...</input></div>

```

before rendering the content in a theme?

# Answer
I really wouldn't use jquery to wrap form elements renderend by Drupal. What if the user has javascript disabled ?

Drupal provides several core api functions for theming forms, one of those is http://api.drupal.org/api/drupal/includes--form.inc/function/theme\_form\_element/7

place the function in the template.php file of your custom theme (change the function name from 'theme\_form\_element' to 'mytheme\_form\_element'

change the contents of the function to your liking, especially look at places where there's html markup involved
> 3 votes

# Answer
If you really want to wrap every input of every form of your site, you can do this very easily client-side with jQuery `.wrap()`.

If you want to do this for some of your forms, you can use `hook_form_alter()` and the `#prefix` and `#suffix` properties.

```
$form['your_element']['#prefix'] = '<div class="new-class">';
$form['your_element']['#suffix'] = '</div>';

```

You can also try to traverse all elements of your `$form`, look out for the different elements you want wrap using `#type` property. This could be a little more complicated as all elements can be included inside groups and be deeper in the form's array, but nothing a good recursive function wouldn't be able to resolve.
> 1 votes

---
Tags: forms, media
---


# Question
Title: Content type field with term reference or users
I have "People" content type that has some fields; one of those is "field1," which is a term reference, and uses an autocomplete widget.

How can I display only "Users" registered with particular roles in the term reference with the autocomplete?

I need to display it on http://example.com/sitename/admin/config/people/accounts/fields.

I am displaying any view or content here; this is where administrator users add the fields to the user accounts and in the "field1". How can I display or list only \["username" with respective to "roles"\] or \["username"\]?

# Answer
If you install References and Views, you should be able to use a view to determine which content/terms/etc. are shown. These settings appear on the field settings page for the Term Reference.
> 1 votes

---
Tags: 7, nodes, ajax
---


# Question
Title: Search API Solr integration with fivestar (or similar) rating system (fascet and sort)
I'm attempting to sort nodes by ratings using the Search API faceted search with Solr integration. I've already set up fivestar ratings (about 9 per node, its a large multi-axis rating system.) but i'm unable to index these ratings!

Can someone help me understand how to change this so I can use a facet search for ratings?

Otherwise, are there any recommendations on other modules (aside from fivestar) which would allow the votes to be indexed?

Thank you!

Justin

# Answer
You can best create a new Entity property in a `hook_entity_property_info_alter()`, and add a custom field "rating" with a custom getter callback. Like so:

```
...
      $properties = &$info['flatrow']['properties'];
      $properties['my_indexable_rating_axis_1'] = array(
        'type' => 'integer',
        'label' => t('Rating axis 1'),
        'query callback' => 'entity_metadata_table_query',
        'getter callback' => 'rating_axis_one_get_properties',
      );
      return $properties;
...

```

Use it to extend the node entity. The getter callback is where you retrieve the value to be indexed,

```
function rating_axis_one_get_properties($entity, array $options, $name, $entity_type) {
  $value = $node->field_fivestar['average_rating']; // I made this up, check how to do it

  return $value;
}

```

Then index the field with Search API.
> 3 votes

---
Tags: rating, search
---


# Question
Title: Is it possible to use Drupal with CouchDB?
I'm very big fan of CouchDB. I want to try Drupal, but it doesn't have built-in CouchDB support, and i guess it is not easy to add one, because Drupal's DB layer was designed for SQL-based databases. I found only one attempt to add CouchDB support but it is experimental. Is there any successful cases of using Drupal with CouchDB? Or i should ultimately give up on this issue?

There is also MongoDB support, but i just wanted to know all variants.

# Answer
There are a few things to keep in mind.

Even though Drupal support multiple databases (mainly MySQL, PostgreSQL, and now anything supported by PDO), this is only true of the core files. There are contributed modules that use database specific syntax and/or functions. In addition, there are some functions that show subtle differences when run on different database servers (for example, see Does db\_affected\_rows() works well with PostgreSQL?).

The modules for non-SQL databases are primarily for offloading some core tables from the primary database. You still need an SQL database when using these.

Personally, I don't mess around with any of these other databases. I may start experimenting with MongoDB, but I can't really use it with client's projects as its support on commodity hosting is limited. Setting it up for them would eat into their budgets, and clients would rather have me do Drupal work than IT work.
> 1 votes

---
Tags: 7, database
---


# Question
Title: Problem trying to create a views with tabs. Link of tab doesn't point to the path I set
I am trying to create a views with tabs: so that a page that has several tabs, the View has a primary page that shows all Article nodes, a tab for all Event nodes, and a tab for Blog nodes. Something should works like this:

* "Content" button in menu links to /content,
* "Articles" tab links to /content/articles,
* "Blog" tab links to /content/blog,
* "Event" tab links to /content/event.

---

However, with my work, this is what I got:

**all the 3 tabs link to /content**, instead of /content/articles, /content/blog, /content/event.

==========

Below is configuration of my view:

1.
2.
3.
4.
5.
6.
7.
8.
9.

So basically, the tabs shows up, but the links of tabs are all pointed to /content, rather than their individual link.

What have I done wrong? Please advise. Thanks in advanced!

# Answer
> 4 votes
I've not had the pleasure of Views 3, but I think I can see what's wrong. I believe you want to have three displays:

1. Articles, which has a default menu tab (and you want Views to provide the parent menu item)
2. Blog, which has a menu tab (but not default)
3. Events, which has a menu tab (but not default)

(Currently the displays are set up as default tabs, which is why they point to the parent item - just like the path for the *View* tab on a node view doesn't point to `node/x/view` but points simply to `node/x`.)

# Answer
> 0 votes
I think I see your mistake. Similar to the above post, you need more views. Just one though. Right after the instructions for creating the Content view, the book has a line " + Add new view". In my book (hard copy version) it's at the very top of page 79. I think you missed that step. You might clone the view you have and delete the appropriate displays to save time, or just create a new one from scratch.

Also you might try the book's site. www.dgd7.org

Sometimes the authors themselves respond to questions there.

---
Tags: views, routes
---


# Question
Title: How does DrupalGardens.com setup a new website?
How does drupalgardens.com creates a new website?

1. It creates a separate directory for Drupal, containing all core files(modules, themes, includes, ...)

OR

1. It shares the themes, modules and core files, and just creates a sub-site in drupalgardens.com

The second one is more reasonable, But When I read the source HTML I saw the following line:

`<link type="text/css" rel="stylesheet" href="http://[mysitename].drupalgardens.com/modules/acquia/gardens_client/gardens_alert.css?lva62a" media="all" />`

That, in my opinion, says that my website is outside of drupalgardens and has a separate directory instead of being a sub-site in drupalgardens.com

# Answer
Yes, Drupal Gardens sites are multisites. Modules inside either /modules or /sites/all/modules are shared by all sites in a multisite installation. If we installed an entire instance of Drupal for each individual Gardens site it would be a serious waste of disk space.
> 3 votes

---
Tags: multi-sites
---


# Question
Title: Where is the code that filter web and email addresses into links?
Under full html, drupal states: "Web page addresses and e-mail addresses turn into links automatically."

I'm curious to know where this behaviour is coded and how I would hook into it if I need to modify it slightly

# Answer
> 4 votes
This answer is for Drupal 7

You can see where the default filters are defined in /modules/filter/filter.module line 1147. There we see that \_filter\_url() (line 1358) is the function used to transform text into links.

You shouldn't modify this code directly. Instead you can implement hook\_filter\_info\_alter() to change the process callback for url filter to your own function (you can copy `_filter_url()` and make the few changes you need)

```
function YOURMODULE_filter_info_alter(&$info) {
  $info['filter_url']['process callback'] = 'YOURMODULE_filter_url';
}

```

Keep in mind that these changes will be reflected everywhere the URL Filter is used. If you need something not so "all inclusive", you can implement a new filter that you can apply to a seperate input format.

---
Tags: input-formats
---


# Question
Title: Show list of node titles from a certain taxonomy term
```
<?php
    $result = db_query("SELECT {node}.title, {node}.nid FROM {node} INNER JOIN {term_node} ON {node}.nid = {term_node}.nid WHERE {term_node}.tid = %d ORDER by {node}.title ASC LIMIT %d, %d", 5, 0, 30);
    while ($node = db_fetch_object($result)) {
        $nodes[] = l($node->title, 'node/'.$node->nid);
    }
    foreach($nodes as $list) {
        print $list.'<br />';
    }
?>

```

I want to print node titles from a certain taxonomy term inside a node. it doesn't prints anything, and print\_r($nodes) shows nothing. What's wrong with my code?

# Answer
You have to enclose table names in curly braces `{}` everywhere they appear, not just in the `FROM` and `JOIN` clauses. So the correct query would be

```
SELECT {node}.title, {node}.nid
FROM {node}
INNER JOIN {term_node} ON {node}.nid = {term_node}.nid
WHERE {term_node}.tid = %d
ORDER by {node}.title ASC

```

You can also use table aliases instead.

If you use table prefixes, your query should have resulted in an error. Turn on PHP's error reporting if you did not see any error message.

If you do not use table prefixes, then the reason is, that the database query simply returns an empty result set (i.e. no node is tagged with the taxonomy term that has `5` as `tid`).

Also note the following:

* In the line

```
$nodes = l($node->title, 'node/'.$node->nid);

```

you overwrite the previous result and thus the previous result is lost. But if a result would actually exist, at least the *last* result should be printed. Nevertheless, use

```
$nodes[] = l($node->title, 'node/'.$node->nid);

```

to be able to use *all* results.
* You pass three arguments to the query (`5`, `0`, `30`), but the query only has one parameter (`term_node.tid = %d`). Are you sure that `5` is the `tid` you are interested in? The other arguments are ignored.
* If you create a new revision of a node that has the requested term and then remove the term from the new revision, the node will still appear in the result set. Join on the `vid` of the node instead of on the `nid` to prevent this.
> 1 votes

---
Tags: database
---


title: Moderating non stop comments

text:
# Question
Title: Moderating non stop comments
I'm sick of moderating comments in my sites. Currently in Admin I'd see all comment titles with view/edit link on each. What I want a table in which I can see each comment full text(which I can edit) along with delete/approval buttons so that I can moderate all of them at once in single screen.

Is there any module which can give me this view.

# Answer
> 3 votes
Yes - Views. :)

Just create yourself a comment-based view and configure it the way you want. I guess you won't be able to have an in-place editing here, but everything else should be easy achievable.

---
Tags: 6, comments
---


# Question
Title: How to alter the "Request new password" form validation
I have adapted the login procedure with hook\_form\_FORM\_ID\_alter so that another database is also checked for credentials. Now I need to change the forgot password validation as well. It seems the FORM\_ID of this form is user\_pass, however, the hooks I define for that do not trigger. I also tried with hook\_form\_alter to see what form was triggered, but that hook also never fires (while it does for login for example).

Is the "Request new password" some kind of special form? Is it possible to change the validation handler of this form?

I'm using Drupal 7.

# Answer
Nothing special about this form, you can alter it just like any other:

```
function MYMODULE_form_user_pass_alter(&$form, &$form_state) {
  $form['#validate'][] = 'MYMODULE_user_pass_validate';
}

function MYMODULE_user_pass_validate(&$form, &$form_state) {
  // Your code here
}

```

Works perfectly fine.
> 13 votes

---
Tags: 7, forms, users
---


# Question
Title: How to Add\Edit ECK entitys from front-end?
I'm using the ECK module for defining custom entities. Also there are users that have permissions to add and edit entities from specific bundle. I'm trying to create a front-end menu for these users with 'Add entity' and 'Edit entity' items.

My question: how to provide an option to Add/edit custom entities to the front-end users?

# Answer
> 1 votes
ECK create CRUD permissions for all entity type/bundles that has been created with it, so all you need to do is to give the users the permissions needed.

Since the path is located in admin/ you might need to create a link for users to use to create some of your custom entities.

---
Tags: 7, users, entities
---


# Question
Title: loading templates of region within page.tpl regardless of blocks being present
I came to this query while trying to create my own theme. Say i have my region named footertop, which is placed above the footer. Its going to contain only some html content and some site logos which are static atleast for now.

I don't have any blocks to assign to this region but still want it to appear and had created a template file named **block-footertop.tpl**. But to my understanding (from drupal docs) this region only appears if any block is assigned to footer top region and is meant to be that way. My page.tpl.php doesn't have any conditions placed for this region, merely

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

```

I'd like to know if there's any way to 'include' the template within page.tpl.php like its done with smarty. Most of the search i'd done showed me results containing \*hook\_theme()\* and seemed different than what I'm trying to achieve.

Why I'm trying to this is to save a big bunch of html markup from being in my page.tpl.php and sheer curiosity to understand drupal theming better.

Any suggestions/solutions to this novice drupal enthusiast would be greatly appreciated.

Thanks in advance!!

# Answer
> 2 votes
First of all I think you should be sure you know the difference between regions and template variables. Second, there are different approaches to your question:

**A) Custom region + block**

You could indeed define a new region. This can be done in one of the two ways:

* in your theme's `.info` file (best way) like this `regions[regionname] = Region name`
* in the `template.php` file (haven't tried or felt the need to use this one)

After you defined your new region you can add blocks and content to it. You could just skip defining a new region and just add your block to the footer region or the region appropriate to your needs.

In your case your `myTheme.info` file would look something like this:

```
; $Id$
; @file: myTheme.info

regions[footertop] = Footer Top

```
* output the region variable (`$footertop`)

```
/**
* @file page.tpl.php
* $footertop contains all the HTML content for that region
* and the blocks belonging to that region
*/
print $footertop;

```
* `.info` file is cached in the database, so you need to clear the cache
* add a new block: `www.example.com/admin/build/block/add`
* add the block to the `footertop` region: `www.example.com/admin/build/block/list/myTheme`

When should you use this approach: when you have static content or/and just some snippets of text/html you want to add to your site. Remember to choose an appropriate input filter, otherwise some/all of your content might get filtered out.

Source: http://drupal.org/node/171224

**B) Template variable**

We want to define a new general variable available for all templates. Something like `$content` or `$is_front`. How do we do this: good old friend `hook_theme` :)

Create a new template file `footertop.tpl.php` and in it add the static data you want to add

```
/**
* Implementation of hook_theme()
* @file template.php - in your active theme
*/
function myTheme_theme(&$existing, $type, $theme, $path) {

  /*
  * If you are sub-theming another theme, like Zen,
  * you might need to do something like this
  * $hooks = zen_theme($existing, $type, $theme, $path);
  */

  $hooks['footertop'] = array(
    'template' => 'footertop',
    // 'arguments' => array(), // We could specify some arguments, useful when the content is not static
    // 'path' => $path . 'to/file' // This is also usefull if your template is in a subfolder
  );

  return $hooks;
}

/**
* Now we make our variable available to other templates
* file template.php - in your active theme
*/
function myTheme_preprocess_page (&$vars, $hook) {
  $vars['footertop'] = theme('footertop');
}

```

Now to add the variable in a template just do this:

```
/**
* @file e.g. page.tpl.php
*/

/* Some other code */

<?php print $footertop; ?>

/* Other code */

```

Source:

Now if you want to be a ***pro*** with ***drupal*** theming or ***development*** you should get yourself a book on this matter. It helped me a lot when I was struggling to understand how Drupal theming works :) You'll defined find the right one for you.

---
Tags: 6, theming
---


# Question
Title: What D7 settings need changed to take advantage of bigger cloud server
I've just upgraded my Rackspace cloud server to 2GB in hopes of speeding up my site. What steps should I now take to enable my Drupal site to utilize this extra memory?

Php mem is to 512MB at present. This is as far as I have gone in changed things (could I go higher, should I?)These are the types of questions I have..

# Answer
> 2 votes
Varnish, Memcache, & APC come to mind. PHP either has enough memory or it doesn't; giving it 512MB wont speed it up.

# Answer
> 2 votes
You need to profile your system. Any other changes, including resizing your instance are totally guesses. I have some suggestions for profiling in my answer to How to increase the performance of my website in Drupal 7. @marcvangend's answer also has suggestions on Drupal specific settings.

---
Tags: performance, database
---


# Question
Title: How to create a custom content-type with template for an "empty" page
I want to display a Unity webplayer in a modal/overlay. I figured out a way to show a drupal page with the webplayer in the overlay, so I'm almost there. But that page then displays everything, including menus etc. The Context module allows me to strip most of it, but not everything. So it seems having an empty page to start with will be easiest.

What would be the best way to create a Drupal page that only shows the content and is otherwise empty? I have already created a custom content-type for the webplayer, so maybe there is a way to associate that with a custom template file that only prints the content? I'm also writing a module for this, so the solution can require changes that need to be implemented in code.

I'm not very familiar with theming, so I'm also interested what template file needs to be created or changed (page.tpl.php, node.tpl.php or something else altogether).

# Answer
> 0 votes
By code, if you want a page that display's only content, here's how I would do it.

```
function module_menu() {
$items['overlay/location']=array(
 'title' => 'Title of page',
 'page callback' => 'module_callback',
 );

return $items;
}

function module_callback() {
 echo 'show what ever!';
 //no return!
}

```

Take a look at hook\_menu()

---
Tags: 7, theming
---


# Question
Title: Is it possible to bypass the admin approval step based on a particular condition?
Potential scenario:

Allow users with a particular email address or token to skip the admin approval step and have their account approved ie: it sends the password/login link out immediately and they don't receive the *awaiting approval* email.

All other users with other email addresses need to be approved by an admin.

One potential solution I've thought of is to act on hook\_user\_insert to unblock and send the password email the user hook\_mail\_alter to disable the initial *awaiting approval* email.

I just feel this option is a bit hacky and I'm wondering if there is a better way of doing things.

# Answer
Take a look at User Restrictions module for **Drupal 7** and Access Rules for **Drupal 6**.

**UPDATE**

For registering users based on unique code check out regcode module
> 2 votes

---
Tags: users
---


# Question
Title: How to Control Core Performance Cache Expire Time Of Day
Wondering if there is a way to control the time of day that core performance caching will expire and run cache clear all via cron.

I'd like to change my minimum lifetime setting as low as possible and use Expire or Cache Actions and/or Views Content Cache to get away from bulk cache clears on my site... which are causing WAY too much excess mySQL load. But I want this master cache clear to happen in the middle of the night, just after the daily backup.

# Answer
> 1 votes
Partial answer, but I typically handle exact scheduling and cron-but-not-cron tasks by using a custom script and calling it with wget in a crontab. You can use cron.php for guidance on how to bootstrap, and then write your own function to clear what you want, then put it in crontab to run when you want. Just remember to lock down the script in .htaccess or apache config.

---
Tags: performance, caching
---


title: How to update my drupal launched sites

text:
# Question
Title: How to update my drupal launched sites
I want to ask about how to update Drupal 7 sites. My site is divided into 2 phases, after launching and adding data in the first phase, I now want to update the second phase. I have a lot of new content type, Views and panels. I added a new language and blocks, a lot of things. I can export panel and view but what about the content type, language and any permission or configuration that saved into database.

# Answer
Use the Features module to export *content types* and *permission*. You can go to *admin/structure/features/create* and the select the features you want to export.
> 2 votes

# Answer
The Features module is your friend in deployment. However, there are some other things that are not supported by Features, and which require you to create an install script.
> 2 votes

---
Tags: 7, importing-exporting
---


title: Gmap/location design question

text:
# Question
Title: Gmap/location design question
Which modules and function should I use to store address of house and also display Google Map of it? I also want to use postal code, province, city each in views etc independently.

I understand I should use GMAP + location.

But not sure if I need to use Location CCK or Node Locations.

What is the best way to accept address and also show Google map in the node?

# Answer
I don't know the relative merits of Node locations vs Location CCK for this scenario, but the CCK option's worked for me. **Edit:** With GMap enabled, you can select a Google Map as the field's formatter by going to *Content management* -\> *Content types* -\> *Edit \[content type\]* -\> *Display fields*. If GMap's enabled, you should see an option *Map only*. CCK will handle storing the data. See my comment on this Q for how to get the table details. **Edit2:** Actually, if memory serves, Location doesn't store the CCK data as you might first expect. location.module stores locations in its own table, and the CCK field just stores an ID into that table.
> 2 votes

# Answer
I've had good luck with Location CCK. Node Location is a holdover from before CCK (and now Fields in Drupal 7) was a mature system, I can't see any reason to use that on a new application. Use Location CCK, and GMAP to show multiple nodes on a single map with views.
> 0 votes

---
Tags: 6, location, google-maps
---


title: Path for a Views 3 page

text:
# Question
Title: Path for a Views 3 page
Is it possible to set a Views 3 path for a page to *%/%* **instead of**, for example, *factsheets/%/%* ?

The preview works, but the actual view doesn't. I'm thinking it shouldn't, but can't find anything to confirm one way or another.

# Answer
> 1 votes
I do not believe that a path such as %/% in views will work. Have you tried it?

The path factsheet/%/% is not intercepting other content, it is the path to the view page. That means that views responds to any page with a factsheets followed by other path segments. The reason for defining the view pages with % is to create a wildcard variable to be used in contextual filters (3rd column of the main view form). These filters supplement the basic filters defined in the first column. Having two % filters means that you can use two contextual filters. The top contextual filter takes the first % and the second takes the next % in the path.

The Views preview works because you are only testing the contextual filters. The path is not being run through Drupal to determine content.

---
Tags: views
---


title: Are there filters in drupal?

text:
# Question
Title: Are there filters in drupal?
I'm a wordpress user and I was wondering if Drupal has the ability to let coders modify the output, or return value of a function trough filters.

(in WP you can do this with add\_action / add\_filter)

# Answer
Yes, there are a few methods.

One uses what Drupal considers filters. I a not sure what the best starting point for these is, but the API reference for hook\_filter\_info should be a decent read.

Another is via preprocess and process functions. Again, I am not sure what the best online starting point for these is, but take a look at the API reference and search for "process" and "preprocess".

The concept of Drupal 7 render trees along with field templates / template functions can also be thought of as a way to process content for display.

My copy is at work, but I think both filters and preprocess/process hooks are discussed in Drupal 7 Module Development. I can't remember if render trees and field templates are in that book or their theming book.
> 4 votes

# Answer
While Drupal coding is very powerful, It is also possible to do a great deal within Drupal without writing any code. The Views Module is basic a UI for the mySQL database providing general and contextual filtering capabilities by filling out the forms. If your interested in learning more about views, watch the video series "Taming the Beast" at nodeone.se.
> 1 votes

---
Tags: theming
---


# Question
Title: Is it possible to apply FAPI #states to profile2 fields on the user registration form?
I have a profile embedded into the user registration form and am trying to add a conditional to one of the fields in order to show/hide related fields.

The fields are all part of the same fieldgroup in the following layout:

```
username
email

profile (fieldset)
 - About you (fieldset)
  - fields

submit button

```

I think the issue is how to actually target the fields and apply `#states` to them. Any ideas? I tried digging through Devel Themer, but couldn't get anywhere with it.

# Answer
If you want to alter a form, you need to create a custom module and implement hook\_form\_alter (or hook\_form\_FORM\_ID\_alter) in it. In your hook\_form\_alter implementation you will have the $form array available. Look up the element you're interested in and add a #states property to it.

The above is just theory; I have not tried it specifically with the profile2 form and a #states property, but I assume that it would work.
> 0 votes

---
Tags: forms, users
---


# Question
Title: How do I get the user's email in the user profile template?
I am trying to customize the user-profile.tpl.php file.

I can access the all custom fields using `$user_profile['field_fieldname']`, and I can even access the user picture using `$user_profile['user_picture']`, but I don't know how to get the user email.

# Answer
> 2 votes
I solved this by following way.

```
$account = menu_get_object('user');
$mail = $account->mail;

```

# Answer
> 1 votes
The email field is part of the $user variable. For the currently logged in user, you can get to it via:

```
global $user;
$user_email=$user->mail;

```

and a quick:

```
drupal_set_message('<pre>' . print_r($user,true) . '</pre>');

```

will show you all sorts of information that is available.

If you need it for a different user, you need to grab the `$node->uid` from the node you are looking at and then do a `user_load($node->uid)` to get to the info...

# Answer
> 0 votes
You do know that Users are fieldable now, so you can add whatever CCK fields you want, like phone number, links, e-mail, etc. Each it's own field type. There's no need to get messy in your template files to customize the user profiles.

---
Tags: 7, users
---


title: Create User Dashboard as startpage

text:
# Question
Title: Create User Dashboard as startpage
hope that you can help me.

Version: Drupal 6/7

i need information about a user dashboard.

we want to create a intranet solution with bug/ticket reporting/scrum functionality and need for a overview a User/Team overview (newest issues/newest tasks etc.). but i don't found any help/information about a user/team dashboard.

1.) can i set a dashboard as startpage?

Greets Frank

# Answer
> 2 votes
You could use Homebox and redirect the user to their individual dashboard on login (possibly using LoginToboggan or Rules). I've used it before and it's pretty neat.

Following that, you just create views to display your tickets/issues/tasks etc and display them in the homebox.

---
Tags: views, organic-groups
---


title: Panels page won't load

text:
# Question
Title: Panels page won't load
I have created a panels page using Panels and for some reason it takes an age to load. It seemed to have started when I added another panels page as a child of this one, and added a navigation block to the left column.

Is there any way to debug this? I've tried using Firebug to check the Net tab, but it just loads and loads. This is running on my localhost so it must be a code loop somewhere, but I've no idea how to find it.

I've checked the reports.

Drupal 7.8
Panels 7.x-3.0-alpha3
Chaos tools 7.x-1.0-rc1

---

I found this in my log, any ideas?

```
Type    theme
Date    Monday, September 19, 2011 - 12:33
User    admin
Location    http://localhost/project01/admin/structure/pages/nojs/operation/page-about_us/handlers/page_about_us_panel_context_3/content
Referrer    http://localhost/project01/admin/structure/pages/nojs/operation/page-about_us/handlers/page_about_us_panel_context_3/content
Message Theme key "panels_edit_display_form" not found.
Severity    warning
Hostname    127.0.0.1
Operations

```

# Answer
Yes, this is an issue with the module. Fortunately there is a patch.
> 0 votes

---
Tags: 7, panels
---


# Question
Title: Redirect anonymous user to login in custom module
In a custom module, I'd like to redirect anonymous users to the login page. After a successful login the user should get to the page he intended to see.

I tried the following code. This gives me the login form, but the user is never sent to the destination page. Instead the standard user page gets displayed.

```
if (!$user->uid) {
    $dest = drupal_get_destination();
    drupal_goto('user/login', $dest['destination']);
}

```

Any ideas how to fix that?

# Answer
> 2 votes
Have you tried `drupal_goto('user/login', array("query" => array("destination" => $dest['destination'])))`?

---
Tags: 7, redirection, users
---


title: No PHP validation criteria in Views

text:
# Question
Title: No PHP validation criteria in Views
In order to specify a PHP validation criteria for a View - do I need some additional module? In previous installation of Drupal I had this position in select box. Now there is everyone of them apart from PHP code. Where did it go?

# Answer
> 5 votes
Check if the PHP Filter module (Core, optional) is enabled.

---
Tags: views
---


title: Specific lay-out for every content-type

text:
# Question
Title: Specific lay-out for every content-type
Is it possible to change the layout for a content type through CSS? How do I do it?

# Answer
Based on the comment of the OP (Niels) I changed my answer:

Each content type page will have a different class (node-type-*CONTENTTYPE*) associated to the BODY element of your HTML.

So you can add to your CSS file:

```
body.node-type-mycontenttype1 img { border-color: red; }
body.node-type-mycontenttype2 img { border-color: yellow; }

```

---

Original answer:

Wich version of Drupal do you use?

For Drupal 7:

You can use a different template for each node of different content type by creating a template:

/site/all/themes/*YOUR THEME*/templates/node--*CONTENTYPE*.tpl.php

You can read on Template Suggestions to know which template you can create.

For the CSS, I suggest you to put everything in your main CSS file and not use a different CSS for each content type.
> 2 votes

# Answer
Also for different page layout (not only node layout) for different node types you have to add template suggestions to your theme, then you can style in with CSS.

**For Drupal 6** add this code to **template.php**

```
<?php
function themeName_preprocess_page(&$vars, $hook) {
  if (isset($vars['node'])) {
   $vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
  }
}
?>

```

Then make different files for any content type you have and layout them as you wish

* page-blog.tpl.php *for blog content type*
* page-news.tpl.php *for news content type* ... etc.

**Similar for Drupal 7**

```
<?php
function themeName_preprocess_page(&$vars, $hook) {
  if (isset($vars['node'])) {
   $vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type);
  }
}
?>

```

Then make different files for any content type you have:

* page--blog.tpl.php *for blog content type*
* page--news.tpl.php *for news content type* ... etc.
> 0 votes

---
Tags: nodes, theming
---


# Question
Title: Migrating a huge live drupal 6 site to drupal 7 Server
I am having a drupal 6 based news site with almost 600 thousand nodes. We are currently building a new site on drupal7.

1. What are the ways to migrate the content from old to new?
2. What are the best practices?
3. What are the know issues?
4. Can data be migrated in chunks?

I did alot of reading online, didn't find anything to give me confidence. Hopefully there will be people here who have hands on experience in this.

# Answer
> 1 votes
This topic is already well covered in the Drupal documentation.

---
Tags: migrations
---


# Question
Title: Migrate from WordPress (with buddypress plugin)
I have a Wordpress 3.2.1 site with many users, and BuddyPress plugin installed. I want to move all the users and profile fields, the BuddyPress comments, and the blog content into a fresh Drupal 7 website.

What is the easiest, or best way to do this?

# Answer
> 5 votes
I did a Wordpress import this summer into a Drupal 6 system. While I ended up doing a manual import for a variety of reasons, a decent amount of my code was based on Wordpress Import.

This module has been suplamented by Wordpress Migrate which uses the Migrate framework. Since you mentioned Drupal 7, this approach would be worth exploring.

Both of these use the WXR format, so you are likely to lose less data than with other methods, and you can generate the backup file right from the WP admin interface.

Personally, I would take a backup of your site (like with Backup and Migrate), and try out Wordpress Migrate before trying to use Feeds.

Keep in mind that Wordpress RSS and WXR files may not always be valid XML, so you may run into parsing issues. I have had problems because of WP plugins that add embed code or `<script>` blocks directly into the post/page, and then WP doesn't wrap everything properly in a CDATA section.

It is also worth noting that you may end up losing any markup that would be the result of short-tags in the post/page body, and just import the sort-tag.

# Answer
> 0 votes
I think you should have a look at the Feeds module, which I have used to migrate from a Silverstripe installation to Drupal.

# Answer
> 0 votes
Just a caveat. I haven't actually had any experience doing this. I'm just googling and researching. Looks like you should check out the Migrate module.

My first instincts of using the feeds module may be misguided.

Installing the Wordpress Migrate module along side with the Migrate module seems to be your best bet as proscribed here: http://drupal.org/node/43178

---
Tags: 7, migrations
---


# Question
Title: Where does location cck module save the data?
I've gone through the code in modules/all/location/contrib/location\_cck but am unable to figure out where this CCK field is storing the address data.

I guest that it's install file should have table fields to store geographic data like city, lat long etc. But it isn't there.

**Edit**: Ultimately I want to access all those location fields separately(beyond Views) when writing modules etc. For example I want to read postal code attached to a particular node for some analysis. That's why I'd like to extract location info about nodes.

# Answer
> 3 votes
As mentioned, the data's stored in the location table, which is handled by the location API and indexed by location ID (lid). The CCK field stores an lid. If you have access to the node object with the field, then you can access the address fields directly from the node object. If you don't have the node object and want to avoid the cost of loading lots of nodes, you can get the CCK DB details using `content_fields($field_name, $content_type_name)` and `content_database_info($field)`. Then you can use `location_load_location($lid)` to get the location. I've just taken a quick look at the source for `location_load_location()` and note that it might do JIT geocoding (so it might actually write as well as read!). I imagine you won't have any issues with doing a join directly on the location table, but I always prefer to use the API where possible.

There's also the command `location_load_locations($id, $key)` which looks like it can give you all locations associated with a particular `nid` or `vid`, but I don't think that's what you're after.

# Answer
> 1 votes
Most CCK field modules let the CCK take care of creating tables and fields and saving data. This is done by implementing hook\_field\_settings().

---
Tags: location
---


# Question
Title: Page not found when trying to access custom module
I've followed this post and made a custom module but when I try to access it from url domain.com/module/method I get 404?

Am I missing something?

Path (URL) to call custom module function

# Answer
> 0 votes
So much could be going wrong from a finger fudge standpoint here, so just make sure you have something very similar to this going on:

For example, in quick.info:

```
name = quick module
core = 6.x
description = quick module
package = quick package

```

In quick.module:

```
<?php

function quick_menu() {

  $items = array();
  $items['quick/hello'] = array( // change to the url you want
    'title' => 'Quick Hello',
    'type' => MENU_CALLBACK,
    'page callback' => 'quick_hello',
    'access arguments' => array('access content'),
  );

  return $items;
}

function quick_hello() {

  $content='Hello. Thank you for surfing over to ' . $_GET['q'];
  return $content;
}

```

Obviously make sure your module is enabled and not so obviously that all caches are cleared, but past that, the most important piece of the above is the 'quick/hello' when it comes to page found/not found :)

---
Tags: 7
---


title: basic page within a basic page

text:
# Question
Title: basic page within a basic page
Is there any way to create a basic page within a basic page? For example, when you create new content, you have the option of making a top menu. Within that basic page you have just created, can you also make another basic page with a top menu within that basic page?

Sorry if this is confusing.

# Answer
Well, I guess that you are asking about creating hierarchical menu structure, so that menu item pointing to your "another basic page" is a child of menu item for first "basic page"?

Then yes, there is a way, and pretty easy to it, when creating a second "basic page" and providing a menu link for it (in `Menu settings` section), make sure that you select your first "basic page" in `Parent item` dropdown.
> 1 votes

---
Tags: routes, 7
---


# Question
Title: EntityMetaDataWrapper exception when calling commerce_cart_product_add()
In brief, I'm trying to create and order and add a line-item as part of a form submission callback. Here's the sauce:

```
if (!commerce_cart_order_session_exists())
{
    $order = commerce_cart_order_new();
    $order->log = t("Created by $product_type checkout page.");
    commerce_cart_order_session_save($order->order_id);
} else
{
    $order = commerce_order_load($form_state['order']->order_id);
}
$wrapper = entity_metadata_wrapper('commerce_order', $order);
$sku = get_sku($product_type, $adj_age);
commerce_cart_product_add($uid = 0, $sku = 2, $quantity = 1, $display_uri = NULL, $combine = FALSE);

```

I'm getting the following error:

```
EntityMetadataWrapperException: Missing data values. in EntityMetadataWrapper->value() (line 83 of /srv/www/mtairy.toomodernmedia.com/public_html/sites/all/modules/entity/includes/entity.wrapper.inc).

```

In some very similar case I was getting the same error message, but in the commerce\_cart\_product\_add function definition where the metadatawrapper was being called.

If I comment out the commerce\_cart\_product\_add() line I can instantiate an order object. Not sure what I'm doing wrong here.

# Answer
You are using `commerce_cart_product_add` wrong.

You can pretty much replace your entire code with:

```
$product_id = ...; // You need to product id, from somewhere, you can get it from the SKU
commerce_cart_product_add_by_id($product_id);

```
> 2 votes

---
Tags: 7, commerce
---


# Question
Title: Adding a line item to an order from a module
I'm trying to create a gift wrapping module for Drupal commerce. I have created the checkout pane that has a select box for the user to choose if they want their order gift wrapped (and a field to select the giftwrap price on the configuration form). I've also created a giftwrap line item type. In the pane's base\_checkout\_form\_submit() function I would like to create a giftwrap line item that is added to the order alongside the products. This is what I've got so far:

```
/**
 * Implements base_checkout_form_submit()
 */
function commerce_giftwrap_pane_checkout_form_submit($form, &$form_state, $checkout_pane, $order) {

  $default_currency_code = commerce_default_currency();
  if ($balance = commerce_payment_order_balance($order)) {
    $default_currency_code = $balance['currency_code'];
  }

  // Create the new line item.
  $line_item = commerce_line_item_new('giftwrap', $order->order_id);

  $line_item->line_item_label = 'Gift Wrapping';
  $line_item->quantity = 1;
  $line_item->commerce_unit_price['amount'] = variable_get('commerce_giftwrap_price', '2.00');
  $line_item->commerce_unit_price['currency_code'] = $default_currency_code;

  commerce_line_item_save($line_item);
}

```

I haven't wrapped it in an if statement yet, I wanted to get it working first. This code is creating a line item in the database however it isn't adding the line item to shopping cart contents view on the checkout review page. I've altered the shopping cart view to include product line items and my newly created giftwrap line items.

Any help on this would be greatly appreciated.

# Answer
You need to add the line item to the order itself. You can do this pretty easily with the entity wrapper:

```
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;
$order_wrapper->save();

```
> 6 votes

---
Tags: 7, commerce
---


# Question
Title: Forms : How to add elements on the client without a (ajax) round trip to the server
I have been playing with AJAX examples.

What I'd like to do is have elements added to the form without requiring a round trip to the server. I guess Drupal requires this to rebuild the form with the new elements. Is it possible to do this without calling back Drupal?

# Answer
Short of building your form with a huge amount of fields, hiding them, and then showing them dependent on the user's action, no you can't.
> 1 votes

---
Tags: forms, ajax, javascript
---


title: Views-based page access?

text:
# Question
Title: Views-based page access?
I need to restrict a View-generated page to authorized users only. (D7.9, Views 3)

I generally want to hide the Drupal's built-in user login block, but have the login form appear when a guest tries to access that page. I have been messing around with Fancy Login (which is supposed to appear whenever there is a need to authenticate), and also with roles and permissions, esp. with "Views: Bypass views access control". Somehow I cannot get the desired result - the page is either fully accessible, or an Access denied page comes up.

Anyone been through a similar challenge?

Artur

# Answer
Just configure your "Default 403 (access denied) page" to "user/login". It's under "configuration / system / site information"
> 2 votes

# Answer
I would tackle it with Panels.

Make a panel page. Place your view on it, and set the visibility of the content to be for authenticated user. Place the login form on it, and then set the visibility for this to be for anonymous users only.

You may also need Login Toboggan or Login Destination to redirect users back to the same page after they log in.
> 0 votes

---
Tags: views, ajax, users
---


# Question
Title: Users complain they can't "click on anything" on my Pressflow site
The users of my site complain they cannot click on anything on my site, which runs Pressflow.

If that makes any difference, I am using some Nginx Caching, and the server config from the Barracuda Aegir project.
I can't seem to figure this out, or reproduce it in another site.

# Answer
I fixed the issue (which was general): I was using a Microsoft CSS filter to scale the background image. It somehow made the whole page render incorrectly. I removed filter, and the problem was solved. I can live without a nice background on IE, for now.
> 2 votes

---
Tags: 6
---


# Question
Title: Create a page to edit all fields from a custom content type
I have a custom content type that has a custom field called "stock."

I would like to have a single page that shows me all "stock" values in a list, and allows me to change the value. Is this possible?

# Answer
Create a view filtered on your content type and include a "NODE: EDIT LINK" in the FIELDS along with all the rest. You can then click on that to edit the node. Anything fancier requires digging into views tpls and custom node edit code.
> 1 votes

# Answer
Create a view with the content type and the field you wish to edit, then use Editablefields module to let you edit them inline.
> 1 votes

---
Tags: 7, views, entities
---


# Question
Title: How to make block title words themable in D6
I need to have my block title for Newsletter Signup block appear like this:

Sign up for mail

Note: Sign up = red colored font for mail = blue colored font

Please help, I know how to override a block.tpl.php file, but I am not sure what my code would be to separate the word groups and add a div or span.

# Answer
Quick and dirty in your block.tpl.php:

```
<?php
  if ($block->subject=='Sign up for mail') {
    $block->subject='<span class="red">Sign up</span> <span class="blue">for mail</span>';
  }
?>

```

And in your .css file:

```
.blue {
   color: blue;
}

.red {
    color: red;
}

```
> 0 votes

---
Tags: blocks, theming
---


# Question
Title: URL Aliases not recognizing Node Reference Tokens?
I'm having trouble getting my URL Aliases to cooperate with certain Tokens... specifically Tokens generated by the CCK Node Reference module. Here is the URL structure that I'm trying to establish:

```
/department/course/lecture

```

Each section refers to a referenced node... so a lecture refers to a course which refers to a department. Make sense? My URL Alias structure, with Tokens in place, looks like this:

```
[field_course_department-title-raw]/[field_course_number-raw]/[field_lecture_display_number-raw]

```

When the URL Alias gets generated, it becomes:

```
/%5Bfield_course_department-title-raw%5D/%5Bfield_course_number-raw%5D/lecture-2

```

So the only Token that is working is the lecture (the last one). The first two tokens aren't even recognized by Drupal and, as you can see, are encoding the brackets from the Tokens into HTML entity codes. Those two are also the CCK Node Reference fields. Worth mentioning, the two offending Tokens were present and available in the Replacement Patterns section on the URL Alias settings page... so it would seem that Drupal should be able to recognize them, right?

What's going on here?! Help! Any ideas or suggestions would be greatly appreciated! Thanks in advance.

# Answer
> 1 votes
The issue I\_THINK is that tokens are only generated on content in the current node, eg, it has no inherent intelligence to walk up the hierarchy of node references to find all your other info stored in other nodes.

So, it would appear you have a node ref to the course already in your lecture, so just make sure you have the correct \[TOKEN\] there (TOKEN-title-raw instead of TOKEN-number-raw perhaps?) but to get up level to the department, you probably have to put a field in your lecture node and populate it behind the scenes with the department node reference (via hook\_nodeapi() and $op presave by node\_load()ing the nid of the course and getting it from there)

# Answer
> 0 votes
You would use nodeapi() something like this:

```
YOURMODULE_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {

  if ($node->type=='lecture' && $op == 'presave') {
    // grab the nid of the course and load it...
    $course=node_load($node->field_course[0]['nid']);
    // set the nid of the course's department in a field in the lecture...
    $node->field_department[0]['nid']=$course->field_department[0]['nid'];
  }

}

```

Of course, you'll have to have added the department field to your lecture node type, plus set all the field\_XXXX to your exact system's as well.

To do this without your users seeing it, you can use the Node Form Columns module to hide the field if its not required (http://drupal.org/project/nodeformcols) or don't let them edit the field with permissions which should hide it or if none of that works, just display:none it with css :)

Disclaimer: I just typed all this in from memory so there may be typos but the gist is here I hope :)

---
Tags: entities, nodes, tokens, path-aliases
---


# Question
Title: Drush make project versions when there is only dev available?
Using Drupal 7.x. If I specify a drupal module project in my make file with no version, for example:

```
projects[] = geocoder

```

and the project currently only has a dev version available (e.g. geocoder module as of November 29, 2011):

will make grab the dev version? Or do I have to explicitly specify the dev version?

# Answer
Probably should have just tried this before asking, but I tried it now. My make file has:

```
projects[] = geocoder

```

And running make gives me the following output.

```
Project information for drupal retrieved.                                 [ok]
Project information for geocoder retrieved.                               [ok]
drupal downloaded from                                                    [ok]
http://ftp.drupal.org/files/projects/drupal-7.9.tar.gz.
geocoder downloaded from                                                  [ok]
http://ftp.drupal.org/files/projects/geocoder-7.x-1.x-dev.tar.gz.

```

So seems like yes it will grab the dev version if necessary.
> 2 votes

# Answer
If the project has both a *stable* release and a *dev* version available, you can force usage of the *dev* version using something like

```
projects[geocoder][version] = 1.x-dev

```

You can also directly pull the project from its Git repository with

```
projects[geocoder][download][type] = git
projects[geocoder][download][url] = "http://git.drupal.org/project/geocoder.git"
projects[geocoder][download][branch] = 7.x-1.x

```
> 3 votes

---
Tags: drush
---


# Question
Title: How to create a module wide variable that refreshes every page load?
What is the best way to create a variable that is accessed by the different views of my module (block, page etc), but that is destroyed at every new page request?

I've been using `variable_set` to store information that is used throughout my module, but this seems to persist across page requests. Is there a hook I can implement to call `variable_del` for every outgoing page, or is there a better way of storing variables in my module that do not persist across page loads?

# Answer
The `variable_set()` and `variable_get()` functions are made to set/get a persistent variable. So they should not be used to persist data within a single page request. The `drupal_static()` function is made for this task and is well documented. Off course, you could also go with a static variable without bothering about `drupal_static()`. But `drupal_static()` will make your code more maintainable and future proof.

```
/**
 * Set or get the shared foo variable.
 *
 * @param $new_value
 *  (optional) If set, the new value to assign to the foo variable.
 *
 * @return
 *  The value of the foo variable. If $new_value is set this would be
 *  the previous value.
 */
function MODULE_foo($new_value = NULL) {
  $value = drupal_static(__FUNCTION__, NULL);
  $previous_value = $value;
  if ($new_value !== NULL) {
    $value = $new_value;
  }
  return $previous_value;
}

```
> 9 votes

# Answer
Not only does variable\_set persist across pages, it nukes the cache every time it is called. It should only really be used for settings, and similar read-mostly uses.

If you read my answer to Where do I declare a global variable?, I outline a few methods that should work. I typically use the method,

```
function foo_get_the_service ()
{
  static $service;

  if (! isset($service)) {
    $service = foo_init_the_service();
  }

  return $service;
}

```

which works well for me when I really do need a global.
> 4 votes

---
Tags: 7
---


# Question
Title: Is it possible to use jQuery's modal dialog instead of the browser-standard alert when using ajax_command_alert()?
I'd like to have a simple feedback form that is submitted via AJAX, using Drupal 7. Upon receipt of the form, I want a simple jQuery modal dialog to appear that will say something along the lines of "Thank you for your submission, etc.". The browser standard alert does accomplish this, but my client feels that this looks unprofessional, hence the desire for the more nicely styled jQuery dialog.

Using `ajax_command_alert()` causes the browser to use a simple `alert()` function. Is there any way to force usage of the jQuery modal dialog? For reference, my code is below:

```
function feedback_form($form, &$form_state) {

    $form['first_name'] = array(
        '#type' => 'textfield',
        '#title' => 'First Name',
    );

    $form['last_name'] = array(
        '#type' => 'textfield',
        '#title' => 'Last Name'
    );

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

    $form['comments'] = array(
        '#type' => 'textarea',
        '#title' => 'Comments'
    );

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit Feedback',
        '#ajax' => array(
            'callback' => 'feedback_form_submit'
        )
    );

    return $form;
}

function feedback_form_submit($form, &$form_state) {
    $commands = array();
    $commands[] = ajax_command_alert("Form received");
    return array('#type' => 'ajax', '#commands' => $commands);
}

```

EDIT: I see that the alert function is defined in misc/ajax.js, under Drupal.ajax.prototype.commands. If I were to alter the JS file's implementation of alert, this would work - but that would be considered hacking core, I believe. How else could I alter this function?

# Answer
I solved this problem in two ways - first, I added my own JS file which adds a modal option to Drupal's AJAX commands with the following JS code:

```
jQuery(function() {

    // Add modal dialog option to Drupal AJAX
    Drupal.ajax.prototype.commands.modal = function(ajax, response, status) {
        // Code to create a modal dialog goes here
    }

});

```

Then, in my AJAX callback on the server, I used the following code:

```
function feedback_form_submit($form, &$form_state) {
    return array(
        '#type' => 'ajax',
        '#commands' => array(
            array(
                'command' => 'modal',
                'text' => "Form submission successful!"
            )
        )
    );
}

```
> 2 votes

# Answer
```
function feedback_form($form, &$form_state) {
  ...
  $form['#attached']['library'][] = array('system', 'ui.dialog');
  ...
}

function feedback_form_submit($form, &$form_state) {
  $commands[] = ajax_command_append('body', '<div id="dialog" class="element-hidden">Form received</div>');
  $commands[] = ajax_command_invoke('#dialog', 'dialog');
  return array('#type' => 'ajax', '#commands' => $commands);
}

```
> 0 votes

---
Tags: forms, ajax, javascript
---


title: Organic Groups strict membership access

text:
# Question
Title: Organic Groups strict membership access
I have set up multiple organic groups on my site that can only be joined with admin approval.

My issue now is that members can post content in groups of which they are not members. I really don't want this.

Does anyone know of a module or technique to stop unauthorized members from posting content in a group but only in groups they are members of and hence authorized to do so?

# Answer
You need to enable `Organic groups access control` module. This will let you set your groups to public/private.

There is a tutorial series on Organic Groups which explains everything you need to know about the configuration at http://modulesunraveled.com/organic-groups
> 1 votes

---
Tags: organic-groups, users, nodes
---


title: Accessing properties of attached file

text:
# Question
Title: Accessing properties of attached file
I have a custom content type which allows one file to be attached to it. In the teaser of the node I want to fine-print the date of the file's (rather than node's) last modification and its size. How can I access those properties in a suggestion template file or in the field-based View that generates the list of teasers?

I am using Drupal 7, and version 7.x-3 of the Views module.

# Answer
> 0 votes
Partial answer, but in the views settings page, you add a relationship to the field that holds the file. Then, when you add a field, you should see an option for **File: Size** in the list. Other fields for file into appear, but mtime isn't one of them.

A hackish way to get mtime is to use stat in your view template, but I would do that as a last resort if you can't find a module to add this as a view field.

---
Tags: views, theming, files
---


# Question
Title: Problem with creating own module Block with an SQL query
I’m trying to create a custom module that implements a block to display something I haven’t been able to do with the Views 2 module.
I’ve tried to look at some guides and tutorials, but I haven’t got any result yet.

I can print out the first SELECT attribute in the first row. The first row make sense since I don’t loop through it but still I’m confused on how to do the rest.

```
function sn_most_contributed_block($op='list', $delta=0) {
  if ($op == "list") {
    // Generate listing of blocks from this module, for the admin/block page
    $block = array();
    $block[0]["info"] = t('Most Contribution this week (custom module');
    return $block;
  }
  elseif ($op == 'view') {
    $mce = db_result(
      db_query("SELECT node.uid, COUNT(nid), users.picture AS users_picture, users.uid AS users_uid, users.name AS users_name, users.mail AS users_mail FROM node node INNER JOIN users users ON node.uid = users.uid WHERE (node.type IN ('leads',  'qa',  'qa_comments',  'til_salg',  'tips_tricks')) AND node.created >= UNIX_TIMESTAMP( CURDATE( ) - INTERVAL 1 WEEK ) AND node.created <= UNIX_TIMESTAMP( CURDATE( ) + INTERVAL 1 DAY ) GROUP BY uid ORDER BY COUNT(nid) DESC LIMIT 0 , 5")
    );

    $block_content .= "Most contributed members are: " . $mce';
    $block_content .= "<div class='author picture profile_image'>In here should be the user image</div>";
    $block_content .= "<div id='username'>In here should be the username</div>";

    if ($block_content == '') {
      $block['subject'] = 'contribution test';
      $block['content'] = 'yay';
      return $block;
    }
    else {
      // set up the block
      $block = array();
      $block['subject'] = 'Most contribution this week';
      $block['content'] = $block_content;
      return $block;
    }
  }
}

I’ve tested my query in the database environment for my Drupal site and it works and print everything it should out correctly.

For looping the query, I tried this code with no result.

while ($contriUser = db_fetch_object($mce)) {
  $contriUser [] = $contriUser->uid;
}

I have also tried the following code.

while ($contriUser = db_fetch_object($mce)) {
  var_dump($contriUser);
}

```

Any help on how to solve this or if someone has an alternative solution to get the most contributing members last seven days it would be much appreciated.

# Answer
For most contributing members you may want to look at the user points modules, they give you a lot of very nice features.

A couple of quick pointers with your code as you are asking.

Your query should use parameters and be formatted according to drupal coding standards, this helps for security and portability. The coder module can help you with this.

To get the results you will probably want something like db\_fetch\_array in a loop

```
 $result_set = db_query("SELECT ...");
 while ($result = db_fetch_array($result_set)) {
   $block_content .= ...;
 }

```

I hope this helps a little.
> 2 votes

# Answer
I made some changes to the interesting part. Check out this untested code:

```
$block_content = "";
$result_set = db_query("SELECT node.uid,
  COUNT(nid),
  users.picture AS users_picture,
  users.uid AS users_uid,
  users.name AS users_name,
  users.mail AS users_mail
  FROM {node}
  INNER JOIN {users} ON node.uid = users.uid
  WHERE (node.type IN ('leads',  'qa',  'qa_comments',  'til_salg',  'tips_tricks'))
  AND node.created >= UNIX_TIMESTAMP( CURDATE( ) - INTERVAL 1 WEEK )
  AND node.created <= UNIX_TIMESTAMP( CURDATE( ) + INTERVAL 1 DAY )
  GROUP BY uid
  ORDER BY COUNT( nid ) DESC
  LIMIT 0 , 5"
);

$block_content .= t("Most contributed members are: ");
while ($result = db_fetch_array($result_set)) {
  $block_content .= '<div class="author picture profile_image"><img src="'.$result['users_picture'].'"/></div>';
  $block_content .= '<div id="username">'.$result['users_name'].'</div>';
}

```
> 1 votes

# Answer
If you have views 3, dereine has kindly posted an import for this http://drupal.org/node/1186598#comment-4593972
> 0 votes

---
Tags: 7, blocks, database, userpoints
---


# Question
Title: How do I pass an object from javascript to PHP?
I set up a hook\_menu like this:

```
$items['fleet/construct'] = array(
  'page callback' => 'construct_fleet',
  'type' => MENU_CALLBACK,
  'access arguments' => array('access content'),
);

```

Then I set up a js file with this:

```
$.post({
  url: '/fleet/construct/',
  data: {new_ships: [1,2,3,4], destroyed_ships: [5,6,7,8]},
  success: finalizeFleetResponse
});

```

How do I access the data from inside my menu callback function?

# Answer
> 1 votes
You are using a POST, it is the same way you, use

```
$new_ships = $_POST['new_ships'];
$destroyed_ships = $_POST['destroyed_ships'];

```

Read more on php POST.

# Answer
> 1 votes
AFAIK, Drupal doesn't provides an API to access POST variables. Probably because what's provided by PHP itself is enough. To retrieve the data, you can use `filter_input()`:

```
$new_ships = filter_input(INPUT_POST, 'new_ships', FILTER_VALIDATE_INT, FILTER_REQUIRE_ARRAY);
$destroyed_ships = filter_input(INPUT_POST, 'destroyed_ships', FILTER_VALIDATE_INT, FILTER_REQUIRE_ARRAY);

```

---
Tags: 7, ajax
---


title: RSS feeds in the front page

text:
# Question
Title: RSS feeds in the front page
How I can set which rss feeds are put at my frontpage like that

Feeds are produced by Views.

Right no feed link exists in frontpage. What would be also the right syntax for HTML5?

# Answer
The default frontpage view provides what you need as long you `print $feed_icons;` in your page.tpl.php
> 1 votes

# Answer
If you are using node.module (i.e. the /node url) for your front page, that will have a feed automatically. In fact, you can turn this off if you replace the home page listing using Views. See here: http://drupal.org/node/413620#comment-2142182

Feeds will be provided by Views under certain circumstances. Firstly, you have to create a special RSS display for each feed you want to expose. Do this by creating a new view, then adding a display of type RSS and configuring that to expose the information you require. Secondly, for the RSS view to appear on the page you're concerned with, you need to configure the views path correctly. You can configure this to be the front page, if I recall correctly. You can also attach the feed display directly to a page or block display in that same part of the interface.
> 0 votes

# Answer
Enable the default view called "frontpage" in View page and in that view, you will see "Feed" display and edit it according to your requirement.
> 0 votes

---
Tags: views, feeds
---


# Question
Title: Can't get module to show up in admin/sitebuild/modules
Normally all you need to do is create a modulename.info file with name = modulename description = This module sends a text message every hour. core = 6.x

Then an empty modulename.module

put both files under sites/all/modules/modulename and presto, the module should be showing up in the list under admin/sitebuilding/modules. I did this a couple of times checking that the core version would be correspond to the drupal version at hand, and of course doubleverifying that I working in the correct site folder. Nothing's showing.

What am I missing.

# Answer
The answer is make sure you use the right program to make files for your drupal module. Or at least have your code editor configured so it creates valid files for your module.

Your custom module could be saying it's not compatible with your core drupal version due to invalid module files so that could be a bit misleading.
> 0 votes

# Answer
> Then an empty modulename.module

The module should contain atleast

```
<?php

```

in order to show up.
> 0 votes

---
Tags: 6
---


title: How ajax framework in D7 forms work?

text:
# Question
Title: How ajax framework in D7 forms work?
I am trying to understand and get the example working that was discussed here http://api.drupal.org/api/drupal/includes--ajax.inc/group/ajax

I understand the form building function.

```
function ajax_example_simplest($form, &$form_state) {
    $form = array();
    $form['changethis'] = array(
    '#type' => 'select',
    '#options' => array(
      'one' => 'one',
      'two' => 'two',
      'three' => 'three',
    ),
    '#ajax' => array(
      'callback' => 'ajax_example_simplest_callback',
      'wrapper' => 'replace_textfield_div',
    ),
    );

    // This entire form element will be replaced with an updated value.
    $form['replace_textfield'] = array(
    '#type' => 'textfield',
    '#title' => t("The default value will be changed"),
    '#description' => t("Say something about why you chose") . "'" .
    (!empty($form_state['values']['changethis'])
    ? $form_state['values']['changethis'] : t("Not changed yet")) . "'",
    '#prefix' => '<div id="replace_textfield_div">',
    '#suffix' => '</div>',
    );
    return $form;
}

```

What I don't understand is what is happening in ajax callback function.

```
function ajax_example_simplest_callback($form, $form_state) {
    // The form has already been submitted and updated. We can return the replaced
    // item as it is.
    return $form['replace_textfield'];
}

```

The same form field is returned. I thought we can change the value or something for the form item $form\['replace\_textfield'\] through ajax callback function. Can some one pls help me to explain this part?

# Answer
> 2 votes
All ajax logic placed in construct form function (ajax\_example\_simplest), ajax callback just return part of form (replace\_textfield) or ajax commands. Its Drupal architecture. This form can be validate and altering.

# Answer
> 1 votes
Please spend some time with the AJAX Example in the Examples project. This is also available on api.drupal.org, but it's best just to get the code and experiment with it. It tries to explain exactly what's going on and best practices with it. Also, http://randyfay.com/ajax.

---
Tags: 7, forms, ajax
---


# Question
Title: Solution for the URL Alias and question marks issue with Webform
I am developing a site in Drupal 7. I am using webform for creating a "contact us" form. After submitting the from successfully, the page is redirected to a confirmation page where the url is http://www.somesite.com/node/11/done?sid=3. I want this particular url as http://www.somesite.com/thankyou.

I tried to set the url alias for **node/11/done?sid=%** as **thankyou**. But unfortunately it doesn't work for me.

Any suggestions about a solution for this?

# Answer
By default, webform will redirect you to an internal URL with the submission parameter `sid`. The only way to prevent this parameter to being displayed is to redirect the user to an external URL.

What you can do is set up a bit.ly short URL that targets your *thankyou* page, therefore webform will think it's an external URL, won't add the submission parameter and the user will land on your http://www.somesite.com/thankyou page.
> 1 votes

---
Tags: 7, uri
---