title: Unlimitted entries in Watchdog table

text:
# Question
Title: Unlimitted entries in Watchdog table
I need to set watchdog log entries to unlimitted. Now it clears every time when cron is called.

```
admin/settings/logging/dblog

```

now maximum is 100000, is there any better way to do this.

# Answer
Just change the setting to "ALL" that should work. Please see the screen below !

Cron will run only if minimum limit is set in the select box see the below code in dblog module.

```
function dblog_cron() {
  // Cleanup the watchdog table.
  $row_limit = variable_get('dblog_row_limit', 1000);

  // For row limit n, get the wid of the nth row in descending wid order.
  // Counting the most recent n rows avoids issues with wid number sequences,
  // e.g. auto_increment value > 1 or rows deleted directly from the table.
  if ($row_limit > 0) {
    $min_row = db_select('watchdog', 'w')
      ->fields('w', array('wid'))
      ->orderBy('wid', 'DESC')
      ->range($row_limit - 1, 1)
      ->execute()->fetchField();

    // Delete all table entries older than the nth row, if nth row was found.
    if ($min_row) {
      db_delete('watchdog')
        ->condition('wid', $min_row, '<')
        ->execute();
    }
  }
}

```

If we select value as "ALL" which is 0, Cron won't delete any entries !

For Drupal 6,

You can use Elysia Cron module, to turn off the dblog\_cron feature.

Elysia Cron Module tells,

> Turn off (disable) a cron task/feature you don't need.
> 6 votes

# Answer
Never flushing your Watchdog log via CRON or at least manually clearing the log every so often will eventually cause you problems. If you are on a dedicated or virtual Linux host consider using Syslog instead of Watchdog for your Drupal logging (available in both Drupal 6 and 7.)

This will allow you to keep an unlimited and permanent log of your Drupal events. The setup guide also shows you how to use logrotate so log files don't get out of hand.

This will likely have a huge impact on performance as well. This is due to being able to prevent the excessive DB writes that Watchdog initiates.

Excerpt from Drupal.org regarding the Syslog module

> **Install & configure the Syslog module**
>
> Go to the Modules page, /admin/build/modules, and install the Syslog module. Then go to the Syslog settings page, /admin/settings/logging/syslog (D6) or the Logging and errors configuratiion page, admin/config/development/logging (D7), and select which Syslog level to attach to the log messages. Choose one that is not in use by Syslog
>
> **Configure Syslog to Log to a Separate File**
>
> Edit `/etc/syslog.conf` and add:
>
> ```
> local0.* /var/log/drupal.log
>
> ```
>
> (if local0 is the level that you configured Syslog to use in Step 1)
>
> Then, restart Syslog:
>
> ```
> service syslog restart
>
> ```
>
> Note that this is optional. If you do not do this, your messages will most likely be in `/var/log/messages`.
>
> **Disable the Database Logging (formerly, Watchdog) Module**
>
> Check that you are seeing messages in the syslog by using
>
> ```
> tail /var/log/drupal.log
>
> ```
>
> You can also browse the file by using less.
>
> If it is working, you may now go to the modules page and disable Dblog.

For complete entry, visit Syslog: OS-integrated logging
> 5 votes

---
Tags: log-messages
---


title: month of the date in Italian

text:
# Question
Title: month of the date in Italian
Use the module date-7.x-2.6, to insert a date dd / mm / yyyy in my content type. My problem is that when I view it, would that be translated into Italian for example "22 Settembre 1009" and now appears so: "22 Sep 1009". Thanks!

# Answer
On the "Manage Display" page for your content type (under admin/structure/types), you can adjust the format to use to display the date.

To adjust the formats, you can configure the date and time settings (admin/config/regional/date-time).
> 0 votes

---
Tags: 7
---


# Question
Title: List of nodes limited by last node created from each user
I am using Drupal 7, and I want to create a views which lists all the nodes that match the following criteria:

* Only the nodes whose content type is A, B, C
* The latest nodes of those content types created by all the users, one node for each user

How do I create it?

# Answer
> 5 votes
Views 3 has the perfect new relationship type for this "Obtains a single representative node for each user, according to a chosen sort criterion."

To do this, begin with a new view which is a list of Users in fields format. By default you will see a list of usernames.

Then add a relationship 'User: Representative node (search for 'represent' when adding the relationship. You can choose the sort criteria as perhaps 'updated date' order by descending.

You can now add extra fields using the related data - such as 'Content: title' and 'Content: Updated date' using the relationship 'representative node' for each new field.

# Answer
> 1 votes
another approach is by creating two views:

1-a view that return a the latest post for the content types(A,B,C) for a specific user by accepting the uid as an argument.

2-the second view return a list of the users.

the trick here is to use the module Views Field View, and add "view field" to the second view then insert the first view with uid as an argument in it.

i hope that help.

# Answer
> 0 votes
This can be easily done using Views3.

1. First create a `users view`. You can do this by selecting 'Show Users' on the page `admin/structure/views/add`
2. Add a new relation-ship of type `User: Representative node` As the description reads it *Obtains a single representative node for each user, according to a chosen sort criterion.*
3. In the Relationship settings page select `Representative sort criteria` as `Content : Post Date` and check `Requires this relationship`, If you want to list only users with some content.
4. Goto Filters add a new filter `Content: Type`. Select the content types A,B and C
5. Goto fields and add any fields you want from the Representative node.

---
Tags: 7, views, users
---


title: Comma Separated List in VBO

text:
# Question
Title: Comma Separated List in VBO
I am trying to select a bunch of users with a bulk operation so I can delete them and unpublish their comments. I have a comma separated list of about 250 users. However, when I use the filter command in views, it only lets me enter about 10 names before the form runs out of space.

Is there something I am missing here? How do I create a filter that will take a much longer list of names? and/or just pass in a CSV file?

# Answer
Use contextual links against filters. This is an example view, you can import and check it through admin/structure/views/import: http://paste2.org/p/2282691

Then you need to change , to + (by design, it should work with comma, I haven't idea, why wasn't work for me..) in your source.

I've tested it more than 30 argument passed to view.

Limitations:

* If username contains some 'exotic' char, like @, the view won't have result.
* The webserver has url limit (by default 6-700 char as I remember), when the url reach it, you'll get apache error.

But both of them happen, if you use normal filter too.
> 0 votes

# Answer
The textbow must have a size so you wont be able to make more than what your are doing now. But if your in views you can see the DBquery generate and use it on PMA to delete a greater number of users with theirs comments.

Be carefull, it's to do if you know what you are doing. I suggest to look at the query of view because Drupal create a table for each CCK field so it's hell to figure the inner joins. If you have a doubt, make a save of your database before.
> 0 votes

---
Tags: views
---


# Question
Title: How to make a thumbnail slideshow when hover over album cover?
Hi im thinking of making a gallery of photos.

On the front page Id like to display thumbnails of album covers for each collection.

What I want to achieve is when I hover over an image (Album cover) that image will turn into a slideshow/ transition of images that are included in that album.

Whats the easiest and best approach to accomplish this?

# Answer
Here are my suggestions. You will need to load both preview and slideshow, and hide slideshow with css/jQuery. Then with jQuery show whole slideshow on hover.

Or, you could use jQuery load() or other jQuery ajax methods to load slideshow dinamically on-hover, If the page has lots of content.

In any case, you will need to include some custom jQuery scripts in your page.tpl.php (checking if $is\_front is true, to include some javascript via drupal\_add\_js for example). This is type of approach i use.

For slideshows, you can use jQuery scripts (i use http://css-tricks.com/anythingslider-jquery-plugin/ and http://bxslider.com/ ).

If you are fond to php programming you can use content types and EntityFieldQuery to load elements in that slideshows.

If not, you could try and search for existing drupal modules to show slideshows like http://drupal.org/project/nivo\_slider
> 1 votes

---
Tags: 7, views
---


title: How to install OpenLayers in drupal?

text:
# Question
Title: How to install OpenLayers in drupal?
I have been trying this for a while without success. After installing the OpenLayers module in drupal 7.14 and trying to configure it i get the following error:

Cannot establish a connection to the server:

I have tried all permutations including downloading the openlayers library in the local machine, giving it a local path in a number of different ways.

The second error that is seen suggests that i am installing an incorrect version of the openlayers library when in fact i have been installing the recommended version i.e. version 2.11.

It has been a frustrating experience getting Openlayers, Geoserver , PostGIS and Drupal 7 working together on Windows 7. The number of combinations are many and there are many issues that are difficult to solve if you are not a webmaster.

# Answer
> 1 votes
There is a patch for the '?q' URL problem which occurs using openlayers-7.x-2.0-beta1, apply the openlayers-fix-marker-lang-path-1404912-3.patch (http://drupal.org/node/1404912) it should fix this for you.

---
Tags: 7, installation, javascript
---


# Question
Title: Select and trigger popup on marker via javascript
Is it possible using javascript to trigger a select on an openlayers marker?
I have access to the name and coordinates of the marker, at the moment I am using setcenter to adjust the map to show the marker but I can not find an api call for selecting markers? Hopefully I'm just missing something simple!

Cheers,
Paul

**update**

So the use case is:

* Auto complete search that shows place names
* select a place name
* map scrolls to the correct lat/long

Now I need to trigger the marker popup that is in the centre of the screen.

Note: I have popups working via mouse clicks.

# Answer
> 1 votes
you can select whether you want a Popup to appear on a MouseOver event or on a MouseClick event, go to Admin - Structures - Openlayers - Maps, edit the map you are using and you can change these on the 'Behaviors' tab. Hope this helps.

---
Tags: javascript
---


# Question
Title: How i can use the feed module for uploading the images in the image field of the content type?
How can I use the feed module for uploading images into the image field of a content type, using a .csv file and storing the images inside a directory on server?

# Answer
Just put the url of the image in your csv and the feeds module will import the image.
> 0 votes

---
Tags: 7, feeds
---


# Question
Title: Filter the products by selecting the checkbox
I am developing an e commerce website. I want to display the product catalog on the left sidebar as check-boxes. When the user will select the products, the page should get loaded with those products. I am new to drupal. I know that I will have to use Taxonomy. Please let me know what else i have to use to achieve this? And how all these are linked?

Thanks in advance!

# Answer
If what you are looking is filtering and not just displaying the products according to their taxonomy terms, then maybe you are looking for the facet api module with apachesolr
> 0 votes

---
Tags: commerce
---


title: Rules E-mailing

text:
# Question
Title: Rules E-mailing
I am sending an email using rules after a content is created and I am trying to figure out how to have the email sent from the user that that made the content.

# Answer
In the Send Email action, there should be an option for "from". Click on "switch to data selection", then enter content:author:mail(or something along the lines of that).
> 1 votes

# Answer
Use the Rules event "After saving a new user account." (Note that: "Before saving a user account" is too early. No UID exists.)

Select the action "Send mail."

In the "From" value for the "Send mail" action, use the replacement variable \[account:mail\].

You will need the Tokens module I believe to accomplish this using this method.

---

As a side note, emails triggered from your server using the from address of your users will likely be marked as spam as they are (usually) not originating from a permitted source.
> 0 votes

---
Tags: nodes, rules
---


# Question
Title: Disable creation of a page for a content type and just use teasers?
So on my website I have Content Type: Level 3 - Article Page. This page has two node reference fields where you can set Call to Actions, these display teaser versions of other articles, downloads etc and are shown below the body text of the page. See this screenshot:

I now want to also allow users to set Call To Actions on the Level 3 pages for specific Giving/Donations.

So I've created a new Content Type: Giving CTAs. Here a user can add text, a thumbnail, title, default donation amount etc.

The issue is that I only ever want to use these Giving CTAs as teasers rendered as in the screenshot. They will forward to a giving checkout page carrying the donation amount value. I don't really want full pages to be rendered for each one. So is there a way to cancel the rendering of pages or disable it for this content type? Maybe it's actually disabling the creation of a URL and default node/id URL? I'm not sure :S

# Answer
As far as I'm aware, every Drupal node created has a "page" created for it, no matter what. You can disable the creation of a user-friendly URL, but all nodes have a node ID, and since the node/id URL path is in reality just a simple query, all nodes can have "pages" generated for them by querying against their node IDs in this way.

I would say as long as you just refrain from placing these content types into a menu, you won't need to worry about it. It's highly unlikely that a user would manipulate a URL on their own in order to find the content's page.
> 0 votes

---
Tags: 7
---


# Question
Title: How can I set product price per taxonomy term on Ubercart?
I need price per taxonomy terms for products. Here is what I need precisely. So when I add products 'X', 'Y', 'Z' to Ubercart I sets them taxonomy term 'Offer' which has price 10$. These products then have same prices. So when customer add any of these products from this term to cart it will get same price for every product.

Thanks for help M.

# Answer
> 1 votes
If you want to automate this, use Rules module. another option is ubercart core options.

---
Tags: 6, taxonomy-terms, ubercart
---


title: Ubercart external file download

text:
# Question
Title: Ubercart external file download
I am using Ubercart 7.x-3.2 on Drupal 7.

I am trying to sell files on my new website using this ecommerce system.

How can my users download files from an external website when they have paid for it?

I am trying to re-direct them to the website that actually provides the files

Thanks

# Answer
> 1 votes
Just a couple of ideas:

1. Alter the email template to include the external link to the purchased files.
2. Create a tab on the user profile with the links of of the files on the external site.
3. Create a module to allow the default "File download" module on Ubercart to link to external files and not only to upload ones.

**Other readings:**

Creating an E-Commerce Site Using Drupal & Ubercart

Selling Digital Goods (Mp3's, Photos, Movies, etc)

---
Tags: 7, ubercart
---


title: Large search box on front page

text:
# Question
Title: Large search box on front page
I want to make my front page look like simple google search page.

Elements:

1. Large search box
2. Footer
3. Login/Register

I'm having hard time figuring out how to have only these 3 elements.How can i edit search box area and its position?

# Answer
> 1 votes
1. The first step is to set "search" as the path of your homepage in the "Site Information" configuration section of the site. This step requires that you have already enabled the search module.
2. If still have blocks of content on your home page the edit each one of the and make sure to set home page " \< front \> " as the place where they are not visible.
3. Add the login block to the footer and you are done.
4. If the any menu is still showing the create a page-front.tpl.php (D6) or page--front.tpl.php (D7) by duplicating page.tpl.php and the remove the code that shows the menus.
5. To make the search field larger you can use CSS.

---
Tags: search, theming
---


# Question
Title: Develop new content type for xml to html translation (Drupal 6)
What I would like to achieve is the this:

1. Develop new content type
2. Add two fields to the content type : XML, XSLT, / text areas
3. When I use this content type later on I want to be able to paste some XML into the XML field, some XSLT into the XSLT field. When I save my new content I want the XML to be translated into HTML.

So in view mode I would always see the HTML, 'edit' mode would give me away of manipulating the XML / XSLT

I started following this tutorial: http://drupal.org/node/231019. But that does not cover how /where to save my new fields. This is how far I got following the tutorial:

```
/**
* Implementation of hook_node_info().
*/
function xmlparser_node_info() {
  return array (
    'node_amlparser'=>array(
    'name'          => t('XML Parser'),
    'module'        => 'xmlparser',
    'description'   => 'This module takes XML and XSLT to generate HTML'
  )
 );
}
/**
* Implementation of hook_perm().
*/
function xmlparser_perm () {
  return array ('create xml content','edit own xml content');
}
/**
* Implementation of hook_access().
*/
function xmlparser_access($op, $node, $account) {
  if ($op == 'create') {
    // Only users with permission to do so may create this node type.
    return user_access('create xml contene', $account);
  }
  if ($op == 'update' || $op == 'delete') {
  if (user_access('edit own xml content', $account) && ($account->uid == $node->uid)) {return TRUE;}
  }
}
/**
* Implementation of hook_form().
*/
function xmlparser_form (&$node, $form_state) {
  $type = node_get_types('type', $node);

  $form['title'] = array(
    '#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5
  );
  $form['xml'] = array(
    '#type' => 'textarea',
'#title' => check_plain('xml'),
'#required' => TRUE,
'#weight' => -5
  );
  $form['xslt'] = array(
    '#type' => 'textarea',
'#title' => check_plain('xslt'),
'#required' => TRUE,
'#weight' => -5
  );
  $form['body_filter']['body'] = array(
    '#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#required' => FALSE
  );
  $form['body_filter']['filter'] = filter_form($node->format);
    return $form;
}

```

So this brought me to the point that my content type comes up when creating new content - cool. But where do I need to go now to actually save my values? Where would I save my HTML once the XML is parsed on submit?

I know quite a few question, but any input would be great appreciated!

Thanks, Uwe

# Answer
> 0 votes
Here is an idea that will keep coding to a minimum using already existing modules:

1. Using CCK if D6 or the fields if D7 create a regular content type and add an extra field for the XML as I will use the automatically added body to store the XSLT. On the content type display section hide the XSLT field, this way the data is collected, but it is not shown when the node is been view.
2. I will install the custom formatter module to create a text formatter where I can apply the XSLT to the XML and then present it as HTML.
3. If I can not apply the formatter directly to the body field in the content type display settings I will the hide both fields (body & XSLT) and using views attachment in D6 or EVA in D7 attach the body field with the formatter applied to the content type.
4. Last but not least if I plan to re-use this setup in others sites I will use the "Features" module to exported.

---
Tags: nodes
---


# Question
Title: Display views block only on user profiles
I created a views block that lists all the content a user has created. I just want this block to appear on the user's profile page, not anywhere else.

User profiles can NOT be found under www.mydomain.com/users/username but under www.mydomain.com/username, so there is not really a way to just display the block on any arg(0)-predefined path.

If I were using Profile2 (which I am NOT, as I haven't figured out a big advantage of Profile2 over the core profile module in combination with the field permissions module yet) I could simply add the contextual filter "Content: NID" and validate with content type "profile". However, my user profiles aren't nodes and so this can't be done.

Is there any way to resolve this issue without using Profile2? All my users will have one profile only and this is really the first time where I would need user profiles to be nodes.

# Answer
If you want to display this block only if the path "username" you should use Context.

In the view you have to add the relation on "Author" and then you should have the filter criteria to show contents of the logged user.

With Context you can say "When I'm on the path X then display the block Y in the region Z".
> 1 votes

# Answer
I'm not familiar with Profile 2, but the way I'd go about this would be to use views\_embed\_view() on in the user-profile.tpl.php template file. You could base the View's contextual filter off the user's id or username and pass that as the third argument in views\_embed\_view().
> 0 votes

---
Tags: views, users
---


# Question
Title: POST parameters not received in drupal module
I am sending a POST to a Drupal module. How can I receive the parameters values in the module and display?

I have tried using `$val = $_REQUEST['']`, `$_POST['']`, `$_GET['']` but it is just showing the null value.

I want to get the POST request and send the response back in JSON.

```
function module_menu(){
  $items = array();
  $items['page-json'] = array(
  'title' => 'JSON Output',
  'page callback' => 'json_page',
  'page arguments' => array(1),
  'access callback' => TRUE,
);
  return $items;
}
function json_page(){
  $dt = $_REQUEST['param'];
  return drupal_json($dt);
}

```

# Answer
> 1 votes
You cannot use an empty string with those super global variables. You need to use a string that is the parameter you request, such as in `$_GET['q']`, or `$_REQUEST['q']`.

---
Tags: 7
---


# Question
Title: What is the correct way to iterate over multivalue items of a form element in D7?
I'm sure there is a function to help with this by I can't find it in the API docs. What I want to do is: in a hook\_form\_alter, iterate over all of an element's items and and manipulate them.

The example form below is from a bean form which has a multivalue field collection called field\_listing\_articles. I want to iterate over all the instances of that element. They are located in the form under field\_listing\_articles -\> und -\> 0, 1, 2 etc

If I do a foreach and iterate over $form\['field\_listing\_articles'\]\[LANGUAGE\_NONE\] I will pick up all the other (non-numeric) parts of the form at that level. I realise I could put an if is\_numeric condition in there but I'm sure there is a more 'Drupal' way of doing this.

Any advice appreciated.

```
$form
--label
--title
--view_mode
--bean
--actions
--#validate
--#submit
--#parents
--#entity
--field_listing_articles
----#type
----#attributes
----#weight
----#tree
----#language
----und
------0
------1
------2
------3
------4
------5
------6
------#theme
------#field_name
------#cardinality
...etc

```

# Answer
element\_children() returns any array's key that doesn't start with *#*, used for properties in form API arrays, and in rendering arrays. It doesn't return numeric keys, as the function would pass to your code an array key such as `"item"`, for example.

Instead of using the constant `LANGUAGE_NONE`, I would use field\_get\_items(), which returns the values for the language currently set for the field, which could not be for the `LANGUAGE_NONE` language.
> 1 votes

---
Tags: 7, forms
---


# Question
Title: How to remove "authenticated-user" from this [user:roles:join-path]/[user:name]
I have these roles:

* anonymous user,
* authenticated user,
* administrator,
* members,
* partners.

In URL Aliases I changed at USER PATHS with this: \[user:roles:join-path\]/\[user:name\]

I created 2 views for user: first for members role and second for partners role (the views contain userpicture and username). The link for these users in both roles are :

* www.example.com/authenticated-user/members/username
* www.example.com/authenticated-user/partner/username

I know that authenticated user role is default for authenticated users, but it is possible to remove from USER PATH: from „www.example.com/authenticated-user/members/username” to „www.example.com/members/username”?

Thank you.

# Answer
> 1 votes
You can implement hook\_pathauto\_alias\_alter(), which is invoked from pathauto\_create\_alias(). The function passes the pattern used from the Pathauto module before the tokens are replaced in `$context['pattern']`. You probably want to check the pattern contains `"[user:roles:join-path]"` to avoid `"authenticated-user"` is removed where the pattern explicitly uses `"authenticated-user"`.

The alternatives would be:

* Implement hook\_tokens\_alter() to alter the output of that token, but that would change it in any place the token is used, not only in alias created from the Pathauto module
* Implement hook\_tokens(), and hook\_token\_info() to implement a token similar to `[user:roles]` but that doesn't include the string for the authenticated user role

Notice that it is the Pathauto module that handles the :join-path part of the token, in pathauto\_tokens().

# Answer
> 0 votes
If Pathauto doesn't let you to specify a single role, I think you should create a little module that makes the same thing of pathauto but add only your favorite roles.

Pathauto has also some api and hooks, try to search there.

---
Tags: tokens, users
---


# Question
Title: how do you add a cookie policy to the site so it appears when a user arrives?
> **Possible Duplicate:**
> eu cookie compliance

I think this is now a legal requirement in the uk so I want to add one but I have not been able to find a module to do it. Has anyone found one or achieved it by doing a workaround?

# Answer
> 1 votes
The Cookie Control module works fine to address this question.

Here is a quote from its project page:

> On May 26th 2011 a new EU originated law came into effect that requires website owners to make significant changes to their sites and may fundamentally change the whole web browsing and shopping experience for everybody.This Cookie Law is amended privacy legislation that requires websites to obtain informed consent from visitors before they can store or retrieve any information on a computer or any other web connected device.
>
> Cookie Control does just that, presenting users with clear information on whether cookies are present, linking to your privacy policy (where you should have specific information about what cookies are in use), and advising users on how to adjust browser settings and what cookies mean for them.

---
Tags: cookies
---


# Question
Title: How do I download drupal from my webhost so I can run on my home server?
I have made a database for it in mysql and uploaded the file to my home phpmyadmin but I am not sure which files needed to configured. This is the error I get on the page:

```
 PDOException: SQLSTATE[28000] [1045] Access denied for user
'mydb_Rem412'@'localhost' (using password: YES) in lock_may_be_available()
(line 167 of /home/magpie/public_html/includes/lock.inc).

```

# Answer
> 1 votes
Answer courtesy of Dipen:

"You need to adjust the username/password value in settings.php. You need to put valid username/pwd applicable on home server mysql instance."

---
Tags: database
---


# Question
Title: domain access display content to ANONYMOUS USER
I have create basic page that only displays on domain one and not the others which I want. The issue is that the page will only display when the user is log in and I want ANONYMOUS USER to see the content

Under the permissions the View published content has the ANONYMOUS USER ticked but I can't seem to find a way or why the content is not displaying until an authenticated user is logged in

# Answer
Under admin/structure/domain/roles you have to checkbox guest -\> all domains.
> 5 votes

---
Tags: 7, nodes, domain-access
---


# Question
Title: Turn location CCK 'city' field into taxonomy autocomplete field
I am using the "Taxonomize Location" module to automatically save all Location CCK Field submissions into the "location" taxonomy. Terms in the location taxonomy are saved in 3 layers: Country -\> Province -\> City.

The location CCK field offers Country and Province as select lists, and City merely as a text field. Is it possible to display the City field as an autocomplete field that pulls city suggestions from the third layer of my location taxonomy, depending on what Country and Province was selected?

# Answer
> 1 votes
What you can do is use hook\_form\_alter. You will define an #autocomplete\_path and use hook\_menu to create a menu item for this path. In hook\_menu, you will define a page callback. This will be a function that will return the list of cities from your taxonomy items.

---
Tags: 7, taxonomy-terms, entities, location, ajax
---


# Question
Title: How can I save 30,000 nodes in less than a day?
Recently I have written a module that reads contents from a file; downloads associated image files; and then saves that to the Drupal 7 as a new node using node\_save. The script works fine, but the minute I start the script I have about 16 to 24 hours before it would finish all 30,000 entries. Yea, that's way too long.

What are some suggested design patterns for my module to finish this as fast as possible? Here is the current architecture:

```
$items = getArrayOfItems();    //reads file and gets an array of items
foreach ($items as item) {
    $node = new stdClass();
    $check_exits = check_title_exits($item[title]);    // note: call to database
    if(!$check_exists) {
        populateNodeObjectFields($item);
    }

    if($images = hasPhotos()) {    //note: must dl up to 4 images from web using CURL
        //create file object and apply to node image field
        $node->image_field = $images;
    }

    //do final custom validations
    validate($node);

    if($node = submit_node($node)) {
        node_save($node);    //note: call to database
    }
}

```

Everywhere I have a note I believe is a bottleneck. Here are my theoretical thoughts on improving the speed. 1) instead of checking against the database for a title (exists) load all titles into an array and check against the array 2) maybe I can separate the file downloads for a separate process to handle later after the node has been saved? 3) This is the biggest bottleneck. If I am understanding the Drupal API correctly, this opens a connection and saves the node one by one - or more than 30,000 times. How can I just open up one call to the database and save all nodes in one batch?

My original solution was simply to have multiple scripts run simultaneously and be responsible for a certain chunk of the data. 12 scripts for example should have cut it down to 2 hours tops for all the data. The problem with that is I keep getting PDO exceptions - serialization errors. Please see this link where I wrote about it. PDOException: SQLSTATE\[40001\]: Serialization failure: 1213 Deadlock found when trying to get lock;. If I could fix that, I would be happy to continue with that solution.

Thoughts on the best way to approach this?

# Answer
Inserting 30K nodes in a day is possible and you are also right about the bottlenecks.

1. Avoid unnecessary table scanning. What happen if a title is duplicated? if you just add a couple more words to it to make different then apply this change after the import is done by running a query against the DB showing you only node titles duplicated. See query at the end.
2. The CURL method will be major as well because it depends on your server connection to the server where the images are hosted and everything in between like load balancer, etc. An idea here will be if possible to download the image before the import and have the located already on the server so that it will be a simple move instead of the whole CURL thing.
3. Does the custom validation do more DB table scanning? If that is the case can you prepare the data before running the import. Like if you know the title have to be unique and maybe you have to convert the date to unixtime and so on, then you might be better off creating a temp table where you can hold all the changes done to the data and the last step is just to run the import against that table instead of the original table with no processed data on it.
4. Two more things come to mind when migrating data:

a. Create a batch method (http://api.drupal.org/api/drupal/includes%21form.inc/group/batch/7)

b. Use the migrate module (http://drupal.org/project/migrate)
5. Depending on your setup if you can optimize your MySQL to handle the load it will be a big plus so that you have a lot less table or row locking.

Queries:

**Duplicate title after import query:**

```
select title, count(*) from node group by title HAVING count(*) > 1;

```

**Preparing node titles to be unique:**

```
INSERT INTO temp_table (title,body,date) VALUES ('title','body',UNIX_TIMESTAMP('2008-12-01 12:00:00')) ON DUPLICATE KEY UPDATE title=title+'Other words';

```
> 3 votes

# Answer
I think you should have a look at the migrate module. I have used it to create 60k plus nodes via xml in less than an hr. It has a learning curve attached to it but the examples are good and it will import in a clean and proper manner.

Also it has command line integration with drush so you do not run into timeout issues.
> 4 votes

---
Tags: 7, database, nodes
---


# Question
Title: How to setup a Multilingual site using A LOT of taxonomy terms and CCK content taxonomy?
I am going through the process now of translating my site into multiple languages. I have A LOT of vocabulary terms and I use them with Content Taxonomy CCK fields on my nodes. I don't believe I can have separate vocabularies as the content taxonomy CCK field on the node can only use ONE vocabulary to save to.

So what are my options? What is best practice? I have wanted to offer my site in multiple languages for a long time but just a bit confused.

Also regarding menu items, should I create a separate menu for each language or use the Translate interface and search for each menu text string and add translations. There seem to be multiple ways to do everything and I think this is adding to the level of confusion. Anyone that has done this before it would be a great help!

My site is a online directory of listings, so LOTS of content and a rather complicated interface, so I want to make sure I start this off right, rather than just going into it by guessing. Thanks!

---

Thanks for the link! But I think you misread the question. I am not referring to menus.

I'm having trouble using localize terms method on vocabularies with the Content Taxonomy field on my node. It's showing both the vocabulary dropdown list of the terms as well as the content taxonomy dropdown list of the terms. They are translating just fine and showing properly, but it shouldn't be displaying double the dropdowns. Content taxonomy should be hiding the Vocabulary dropdown. I am trying to figure out why it's not. any ideas?

# Answer
> 1 votes
Check this for taxonomy translation: http://drupal.org/node/335205

The approach for menu translation depends on your menu and site structure. It is a bit painful but I would recommend using the menu translation interface. Managing multiple menus may work fine if you are planning 2-3 languages max but as you add more languages it will get out of control.

---
Tags: taxonomy-terms, i18n-l10n
---


title: Theming the userpage

text:
# Question
Title: Theming the userpage
I want to modify the userpages with some changes:

1. change the page-title
2. hide some or all of the local taks items (the tabs)
3. display some user-infos
4. insert a view

Here is how I want to solve it:

1. use THEMENAME\_preprocess\_page() to change the title
2. use THEMENAME\_menu\_local\_task() to hide the tabs
3. use the user-profile.tpl.php to display user infos
4. create a view and use views\_embed\_view()

Is there a better way of doing that? Should I consider using `page--user.tpl.php` or a combination?

Edit: concerns Drupal 6

# Answer
> 1 votes
1. Yes, THEMENAME\_preprocess\_page() is fine for this, but one could argue that it's better to implement hook\_user when $op == 'view'. That way you would make the change available for all themes (who knows you will be adding a mobile theme a couple of months from now?).
2. I wouldn't use THEMENAME\_menu\_local\_tasks() for this, but instead do `$variables['tabs'] = '';` in THEMENAME\_preprocess\_page(). Of course, only do this for the user page, otherwise you will lose the tabs on all pages.
3. Yes, use user-profile.tpl.php to print out variables. If you need additional variables, fetch them in THEMENAME\_preprocess\_page() and add them to the $variables array to make them available in your template. Depending on what you need to do, see also user-profile-category.tpl.php, user-profile-item.tpl.php and their respective preprocess functions.
4. Yes, that's an option. You can also create a block display of that view and enable the block on the user page.

I recommend not to use multiple page templates (like page-user.tpl.php) if you can. When you do, a simple change to page.tpl.php will often need to be applied to all other page templates as well, which is a bore.

# Answer
> 0 votes
To change the title for profile page use hook\_username\_alter(), or the other method as mentioned in the other answer.

---
Tags: theming, users
---


# Question
Title: How to build my own view for apache solr module
After successful integration of apache solr module in drupal 7 and displaying the result Ii found that it is using the view files (search-results.tpl.php & search-result.tpl.php) from the core search module to display the result.

How can I use my custom files similar to (search-results.tpl.php & search-result.tpl.php) inside the apache solr module folder to display the result?

Since I am new to drupal and just started can somebody guide me to implement it.

# Answer
Copy the search-results.tpl.php & search-result.tpl.php into your theme folder. Drupal will then use these files instead of the core. If you want to pass extra variables to the search-result you can use hook\_preprocess\_search\_result

```
function mymodule_preprocess_search_result(&$variables){
    $variables['myvariable'] = 'this is a variable pass to the search-result.tpl.php';
}

```

and then access your variables from within search-result.tpl.php like

```
print ('My variable: '.$myvariable);

```
> 0 votes

# Answer
This is a duplicate of the question https://stackoverflow.com/questions/12496764/how-to-build-my-own-view-for-apache-solr-module so the answer is the same as well. Let me quote:

> The .tpl.php files are theme template files, and you can override them by using identically named files in your own theme. Some deeper reading at Drupal docs.
>
> Or you could use the search features provided by Google, as I did, and find an already existing answer on a related site.
> 1 votes

---
Tags: 7, search
---


# Question
Title: How do I build a search form with filter options / checkboxes?
I'm a noobie to Drupal - recently "converted" from WordPress.

I want to create custom search forms that use checkboxes to allow visitors to search in a specific content type. Sorry for the shady example, but the search form on the front page of the Pirate Bay is *exactly* what I'm looking for. It would also be great to be able to set the default option based on context - if the user is on a page of a particular content type, that content type should be set as the default in the search checkboxes.

I've installed Drupal 7, Apache Solr search, and the Facet API. I'd give a link, but it's installed locally on mamp for development.

I want the custom search form because the site I'm building has a lot of different - and interrelated - kinds of information separated into different "areas" of the site defined by content type. One area is for social service resources, another is for social service organization profiles, another for trainings and workshops, etc. Each of these use Views to display related information in other content types (i.e. "Related Trainings" listed in the sidebar of a resource page). In essence, the site maps out the entire social service system in our community and serves as an information center for clients and case workers.

When someone visits our site looking for emergency shelter, for example, the information they are looking for is in the "Resource" content type and I don't want them getting a deluge of info from trainings, org profiles, forums, etc. Another example would be a case worker wanting training on how to apply for Social Security disability benefits for a client - I want them to be able to choose to restrict search results to the "Training" content type. Faceted search seems to be able to allow users to drill down and refine results, but I want them to be able to filter *before* getting results.

Anyone know how I might do this?

# Answer
Take a look at this module, it may be what you need: http://drupal.org/project/custom\_search. It extends drupal built-in search module. You can add filters for content types, taxonomies etc in drop-down triggered when searching.
> 0 votes

---
Tags: search
---


# Question
Title: How to avoid Pathologic module to change a javascript src value?
I need to insert a javascript code in a textarea field of a node. This one:

```
<script type="text/javascript" src="http://www.avaibook.com/js/avaibook.js"></script>

```

The problem is that this line becomes:

```
<script type="text/javascript" src="about:blank"></script>

```

The real source value: `http://www.avaibook.com/js/avaibook.js` is replaced by `about:blank`.

I already know that the pathologic module is the cause (if I disable it it works fine), but can't disable since I need it for other purposes.

Is there any way to avoid this?

# Answer
You can try adding Javascript in your template files by using

```
<?php
drupal_add_js(drupal_get_path('theme', 'mytheme') .'/mytheme.js');
?>

```

also this works in modules etc as explained here: http://drupal.org/node/304255

sometimes it is comfortable to add whole JavaScript inline:

```
drupal_add_js('jQuery(document).ready(function(){
   // Your stuff
   })
', 'inline');

```

Hope that helps avoid that module behaviour.
> 1 votes

---
Tags: nodes, uri
---


title: Module and Custom Content Type

text:
# Question
Title: Module and Custom Content Type
I am trying to create a module (Drupal 7) which will have the following workflow: 1. User enters data via form (frontend) 2. The data is validated and get stored in database (custom content type e.g. Reservations ) 3. User will receive confirmation e-mail 4. User will be redirected to another page 5. Data will be manipulated by Admin (CRUD functionality)

Ideally, I would create custom content type via GUI e.g. Reservations. And when use the Views module to manipulate the data. Could anyone suggest any tutorial or explanation about how should I proceed Pls. Note that already played with Webform module and found that I prefer to do it via custom module and Form API

Thank you in advance

# Answer
You can do it via drupal's form API, First create your content type

1.Create a module (http://drupal.org/node/361112)

2.Create menu callback

```
function form_example_menu() {
  $items = array();
  $items['examples/form_example/tutorial'] = array(
    'title' => 'Form Tutorial',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('form_example_tutorial_1'),
    'access callback' => TRUE,
    'description' => 'A set of ten tutorials',
    'type' => MENU_NORMAL_ITEM,
  );
}

```

3.Use form api create form with necessary fields

```
function form_example_tutorial_1($form, &$form_state) {
  //your fields goes here
   $form['name']['first'] = array(
     '#type' => 'textfield',
     '#title' => t('First name'),
     '#required' => TRUE,
     '#default_value' => "First name",
     '#description' => "Please enter your first name.",
     '#size' => 20,
     '#maxlength' => 20,
   );

 }

```

4.Add necessary validation

```
function form_example_tutorial_1_validate($form, &$form_state) {
  //your validation goes here
}

```

5.Add form submission codes

```
function form_example_tutorial_1_submit($form, &$form_state) {
  //here you can process your data, in your case you want save it to a content type. so you can use node_save here
  $node = new stdClass();
  $node->title = $new_node['title'];
  $node->body['und'][0]['value'] = $new_node['body'];
  $node->type = 'article';
  //include all necessary fields
  node_save($node);

  //after success full save you can  write code for confirmation e-mail and redirection page
 }

```

6.As you have saved data to a content type, You can create a view with all required details, with edit delete functionality

If you have any doubt in module development and implementing form api you can get examples on this page http://drupal.org/project/examples

hope this may helps you
> 1 votes

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


# Question
Title: Drupal.settings.ckeditor is undefind in CKEditor module
I have installed CKeditor module as per the guidelines of ckeditor README.txt file. But in neither text area ckeditor is loading. When I inspected in firebug it shows me following error

> Error: TypeError: Drupal.settings.ckeditor is undefined Source File: localhost/drupal7/sites/all/modules/contrib/ckeditor/includes/ckeditor.utils.js Line: 5

I am wondering is there any problem in configuration?

I have installed and configured CKEditor module previously many times but I haven't encountered such type of error

# Answer
> 0 votes
Finally I got a clue. I had enabled HeadJs module for improving jquery loading time. This module was creating bottleneck. Just uninstalled this module and work like a charm.

---
Tags: 7, wysiwyg
---


# Question
Title: Easy PHP, Radioactivity module: Read out a node's current energy?
Sorry, this is a super stupid problem but I'm new to PHP and failed at solving it myself.

On my node I have an energy field (Radioactivity module) and a computed field. The computed field is supposed to read out the node's current energy, plug it into a function and return another value.

I have tried all of

float( $entity-\>field\_energy ),

float( $entity-\>field\_energy\[0\]\['value'\] ), and

float( array\_pop(array\_pop(field\_get\_items($entity\_type, $entity, 'field\_energy'))) )

to read out the node's current energy, but everythings gives me an error. When I replace the above with a static number everything works fine.

Can anyone tell me how to read out the energy? I don't even know what data type is used to store the energy.

(I couldn't add a radioactivity tag. Unfortunately I don't have enough reputation points for doing so.)

# Answer
My guess is that it is something like

```
float($entity->field_energy['und'][0]['value']);

```

Also, you can do

```
print_r ($entity->field_energy);

```

to see what is contained in object.

also, it may be contained in node object so maybe it is

```
float($node->field_energy['und'][0]['value']);

```

My blind guess but it may help you :)
> 3 votes

---
Tags: nodes, entities
---


# Question
Title: Add class and extra HTML to specific menu items with hook
In page.tpl.php I have the following to echo out the main menu:

```
<?php if ($main_menu): ?>
        <?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'top', 'class' => array('links')))); ?>
<?php endif; ?>

```

The site is responsive so on desktop monitors it displays like this:

But as you reduce the screen to mobile size it turns into a navigation list that can be opened and closed with a button. See here:

However the desired effect is to have small descriptions for each of the menu items in the mobile version simply by using `<p class="monly">little description</p>` wrapped within the menu li and a tags. See here:

I also want to add CSS class *'nobile'* to tthe list item 'Home' in the menu so that it doesn't display on the mobile version.

So how can I add this CSS class to the 'Home' `<li>`? And how do I go about adding the link descriptions to each `<li>`? Can I use a hook in template.php? If so how do I go about this?

Thanks for your help!

# Answer
You can add a custom class to menu items by using the Menu Attributes module. You can also use `hook_menu_link` for the same. For displaying the menu description, here is a sample code. Paste it in your template.php file

```
/**
* Implements theme_menu_link().
* Adds menu description under main menu
*/
function themename_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';
  $element['#localized_options']['html'] = TRUE;

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }

  if ($element['#original_link']['menu_name'] == "main-menu" && isset($element['#localized_options']['attributes']['title'])){
    $element['#title'] .= '<span class="description">' . $element['#localized_options']['attributes']['title'] . '</span>';
  }

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

```

**Note :** You've to use css/js to show/hide the menu description based on the screen size.
> 5 votes

---
Tags: 7, routes
---


title: Show virtual node in views

text:
# Question
Title: Show virtual node in views
How to show virtual node if there is no result in the views(date template) that use Contextual filters?

# Answer
Inside your view under the advance tab

Click on "no result behavior"

Chose " Entity: Rendered entity "

Add a label

Entity type "node"

Entity id "enter the node id" for the node you want to show if no result was found.

chose appropriate view mode.

here an export of a view that returns node 1 if you have no articles in your system

```
$view = new view;
$view->name = 'retrun_homepage';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Retrun homepage';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* No results behavior: Entity: Rendered entity */
$handler->display->display_options['empty']['entity']['id'] = 'entity';
$handler->display->display_options['empty']['entity']['table'] = 'entity__global';
$handler->display->display_options['empty']['entity']['field'] = 'entity';
$handler->display->display_options['empty']['entity']['label'] = 'Show homepage';
$handler->display->display_options['empty']['entity']['empty'] = FALSE;
$handler->display->display_options['empty']['entity']['entity_id'] = '1';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'article' => 'article',
);

```
> 1 votes

---
Tags: 7, views
---


# Question
Title: Product reference field (autocomplete) length limitation
I use taxonomy based pricing calculations with rules. There are 4 differrent taxonomy vocbularies used as taxonomy reference field. So when I "bulk generate" the products, I become 1152 product variations. The field "product reference" on product display node is limited to 2048 characters so it is not possible to reffer all my 1152 variations. How to extend the limitation of product reference field?

# Answer
> 1 votes
This limitation takes affect only when the product reference field widget ist set to "autocomplete". Set up the "product reference field" to checkboxes, list or turn of the widget when you use "bulk add" product

---
Tags: commerce
---


# Question
Title: Permissions and ownership of /var/www and /var/www/example_drupalsite.com
I would like to get some feedback on my setup of permissions and ownerships for the following directoriess:

* **/var/www/**
* **/var/www/drupalsite.com**

Right now I have the following for:

```
drwxr-x--- 11 root www-data 4096 2012-01-01 00:00 www
drwxr-x---  4 root www-data 4096 2012-01-01 00:00 drupalsite.com

```

I am a single user on this vps: **developer1** in a group called : **developers**

1. Is this secure and logical? A default ubuntu install starts with root as the owner and group with permissions of **drwxr-xr-x** but using those if I set these this /var/www/drupalsite.com becomes unavailable.
2. What's the best to do if I want to be able to have write permission as **developer1** to the files in /var/www/drupalsite.com?

# Answer
What I do is, on *dev* machines I make all of my Drupal files owned by my user account (e.g. developer1), and I make the group www-data. I use chmod g+w to give write access to the web server on the directories that need it (see article quoted above in question comments, http://drupal.org/node/244924).

On *production* and *staging* machines, I make all of my Drupal files owned by a special www-admin user, and give sudo access to www-admin to any user account (e.g. developer1) that might need it. I then can do, for example, `sudo -u www-admin git pull` if I want to operate on the Drupal files. (Aside: I usually store my git root at /var/www/drupalsite.com, and point the webserver document root at /var/www/drupalsite.com/htdocs. This puts the .git directory outside the web root, and also gives me another place to put file and directories that belong with the site, but should not be served by the webserver, e.g. D7 private folder.) If I am hosting on a small shared hosting site, I sometimes keep only the dev site under git revision control, and use `drush rsync @dev @prod` to push just the files over. By making the Drush site alias remote-user www-admin and setting the Drush rsync mode to 'rlptz' (e.g. `$command_specific['rsync'] = array('mode' => 'rlptz');`), then the filesystem modes will be copied over (so the folders that are g+w on dev will be g+w on prod), but all of the files will still be owned by www-admin on the target site.

I'm supposed to write some docs about this for Drush, but have not yet. :p See: http://drupal.org/node/1343892 and referenced issues.

**Update:** I'm in-progress on working on a Drush command to fix / set permissions. See http://drupal.org/node/990812. The default values used in that command give some hints on ways to set permissions, although different strategies are possible.
> 5 votes

---
Tags: files
---


# Question
Title: How To Calculate Sum() of a field in a view using use aggregation=Yes option
I have a field called payment\_value for different customers i need to calculate the sum of payments for each customer , i can see ""use aggregation =Yes" at the view page but i dont know how to implement this option . thanks a lot.

# Answer
I am not sure if you have already found the answer. I found this question from Google, so I am answering this so that somebody else might benefit.

When you are using Aggregation = Yes, remember one rule of thumb : All the fields that you are selecting must either use GROUP BY that field or some aggregation function on that field.

In your case you have two fields, User Name and Payment value. Once you enable the Aggregation, you will find `Aggregation settings` beside your fields in Fields, Filter and Sort groups.

1. For User Name - click on `Aggregation settings` and select "Group Results together".
2. For Payment Value - click on `Aggregation settings` and select Aggregation type as SUM.

Check List

1. In-spite of the above if your view is not using, then the culprits are sort and filters. Be careful about them. Removing them and adding them back one by one may be a easier solution.
2. Remember that sorting is not necessary as GROUP BY does default sorting of groups. And more over if you add a sort it might add an additional GROUP BY, if your settings are not right.
> 6 votes

# Answer
Aggregation is currently broken in Views 3. See all of the issues

Try View Calc module. Currently the is only a Drupal 6 version. I see from your comment you are looking for a Drupal 7 solution see the status here
> 4 votes

# Answer
If you're looking for one line per customer with the sum of their payments, then Views Group By is the module you're looking for. The release version only supports COUNT, the dev version supports SUM, MIN, MAX and AVG, too.
> 1 votes

---
Tags: views
---


title: Image style in D7

text:
# Question
Title: Image style in D7
The following code I used once in node.tpl.php template to construct a jquery gallery in Drupal 6 where I found somewhere.

```
 <ul id="jgallery">

   <?php foreach($field_myimage as $key => $image):?>
    <li><?php print theme('imagecache', 'imagecache_name', $image['filepath']); ?></li>
   <?php endforeach; ?>

 </ul>

```

I wonder how it should be used in Drupal 7, the image style. And how to add in extra attributes like class. Thanks

# Answer
I think theme\_image\_style() is what you're looking for.

Eg:

```
$image = array(
    'style_name' => 'style_name', // imagecache_name
    'path' => $image_uri, //  uri (String, 27 characters ) public://image.jpg
    'alt' => 'Alt text here',
    'title' => 'Title text here',
);

print theme('image_style', $image);

```
> 2 votes

---
Tags: theming
---


# Question
Title: Download entire drupal contrib repository
I would love to download (or, preferably, clone via git) the entire drupal contrib repository (6 for now, but 7 also). That way I can do cool stuff like search the repository via grep for hooks, examples, and implementations that I can reflect upon, improve, copy or steal. Is this possible? Is there a native way to do this via drupal.org or github.com/drupal? Do *you* have a current-ish copy of said repository. Please. Don't be greedy.

# Answer
http://drupal.org/sandbox/greggles/1481160

> This project provides one way to help solve the issue Provide a way to download the entire git codebase for all projects.
> 5 votes

---
Tags: version-control
---


# Question
Title: How can I get a select drop-down menu based in terms of the a vocabulary to display in a block or a theme?
I need to get a select drop-down menu based in terms of the a vocabulary. I need to display this select drop-down in a zone of the theme or in a block not in the edit/create forms.

I have a vocabulary named: "myterms" and I have the following list of terms in this vocabulary:

```
term1
term2
term3
term4

```

I need a menu - select -drop-down that shows term1 and term3 to select and when I put click in the term1 or term3 go to the respective page. In the menu select drop-down won't show all terms, I need to choose the terms.

Thanks in advance for your help.

# Answer
Have you tried http://drupal.org/project/entityreference? works well for me. basically your turn the field of "term" into a drop-down select on Node edit forms and a link on content.
> 0 votes

---
Tags: 7, navigation
---


# Question
Title: How to change scheduler date format in *_node_form
When I go to fill a \*_node\_form I find that Scheduler module only have this date format "Y m d" "H:m:s" and I would like to have "d m Y" "H:m:s".

I'm looking to the module and I don't find anyway, also , I have make a dpm with $form, And I don't find anyplace to change the date format.

Can be done this?

Thanks

Oskar

# Answer
> 0 votes
I find it the url is: admin/config/content/scheduler

The strange is that it doesn't have a "configuration" link in module page list.

Oskar

---
Tags: nodes, datetime
---


# Question
Title: Organic Groups Support for Context Module
I would like to achieve following functionality.

* In Context Conditions check Group Type such as Pubic, Private, Moderate
* Check User is member of a Group or Not !

Is it possible using any module ?? I verified Context OG module but it's not giving options that i am looking for !

Any solutions to override the context and check for above conditions ?

# Answer
Have you read this article? http://drupalconnect.com/blog/creating-drupal-context-plugins

I think it can help you to build you own module to use with context.

Oskar
> 1 votes

---
Tags: organic-groups, 7
---


# Question
Title: How do you theme the taxonomy description field?
I need to theme the `description` field on a taxonomy page. I've tried `field--description.tpl.php` with no success.

Also, do I also copy the contents of `/modules/field/field.tpl.php` as a default template?

# Answer
The term description isn't a field, it's actually a property of the taxonomy term entity and doesn't have a theme/template associated with it.

It's built up in `taxonomy_term_view()` as a standard render array:

```
$build['description'] = array(
  '#markup' => check_markup($term->description, $term->format, '', TRUE),
  '#weight' => 0,
  '#prefix' => '<div class="taxonomy-term-description">',
  '#suffix' => '</div>',
);

```

So to theme it you could write a preprocess function for the taxonomy term template, maybe something like:

```
function MYTHEME_preprocess_taxonomy_term(&$vars) {
  if (!empty($vars['content']['description'])) {
    $vars['content']['description']['#prefix'] = '<div class="my-class">';
    $vars['content']['description']['#suffix'] = '</div>';
  }
}

```
> 9 votes

---
Tags: taxonomy-terms, entities, theming
---


title: Change css based on the page url

text:
# Question
Title: Change css based on the page url
I am using drupal 7. I wanted to change the colors of the block and everything for certain pages. The ThemeKey module works fine but i have to do all the block configurations again in this. This is tedious. Since i want to change only the css any other module will solve ma problem?

# Answer
> 4 votes
The `body` element will have a boatload of classes on it. This does vary by theme, but typically there will be a class like

```
body.page-the-url-for-this-page

```

that you can use in your CSS.

Do a view source on various pages and take a look. Or, use the Inspect Element feature of Firefox's Firebug or Google Chrome, or the Firefox Web Developer extension.

If the class isn't there, you can do something like

```
function thetheme_preprocess_html (&$variables)
{
  $variables['classes_array'][] = "page-" . str_replace("/", "-", request_uri());
}

```

You may also want to investigate the Context module, which can aid in section-specific features for a site.

# Answer
> 0 votes
This is a good approach, and very succinct. I think the following code works better, since 'replace' throws an error:

```
function thetheme_preprocess_html (&$variables)
{
  $variables['classes_array'][] = "page-" . str_replace("/", "-", request_uri());
}

```

---
Tags: 7, theming
---


# Question
Title: Can't get the author's picture printed onto a node in Drupal 7
After reading the documentation, it seems that the correct way of doing that is like this:

```
php print $user_picture;

```

It won't work (it doesn't print anything at all).

Afetr asking around, I get this answer, which sadly won't work either:

```
global $user;
$image = theme('user_picture', $user);
print $image

```

That code was suggested as a "last resource", but when I try to use it, I get this error message:

> Fatal error: Cannot use object of type stdClass as array in /includes/theme.inc on line 1054

Line 1054 is the following one:

```
  // Line 1054
  if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
  //
    $element = $variables;
    $variables = array();
    if (isset($info['variables'])) {
      foreach (array_keys($info['variables']) as $name) {
        if (isset($element["#$name"])) {
          $variables[$name] = $element["#$name"];
        }
      }
    }

```

It´s pretty clear that it should work, but it doesn't.

Using contemplate module, I get this output as an alternative, but it doesn't work either.

```
<?php print $node->picture ?>

```

I've tried then with Devel module (using the /devel tab of the node):

I get this:

```
picture (String, 4 characters ) 2876
$...->picture

```

Wich won't work, because the output is just "2876", but is the only "picture" there.

So what can I do? How can I trace this problem?

# Answer
I´ve got it! It was really something silly now that I´ve found it :) Just in case anyone out there wonders: Under /admin/structure/types/manage/{nodetype} you have this option: "Display author and date information". That option has to be checked.

I´ve checked that users were able to have pictures (the option "enable user pictures", under /admin/config/people/accounts), but in D7 there´s this option under each content type...

Hope this helps someone.
> 1 votes

# Answer
Have you tried examining the $user object itself? It should be something like

```
    <?php
    global $user;
    print $user->picture;
    ?>

```

Or if that is loading the logged in user(which it will) as opposed to the user(creator of the node) you are viewing try on a node:

```
<?php
$user_object = user_load($uid));
print $user_object->picture;
?>

```
> 1 votes

# Answer
The reason `theme('user_picture', $user)` is not working is that `theme_user_picture()` is expecting an array, but you are passing an object. That is exactly what the error message is telling you.

The right way to call `theme_user_picture()` is the following one.

```
$image = theme('user_picture', array('account' => $GLOBALS['user']));

```

As evident in template\_preprocess\_user\_picture() code, the theme function will return the markup for the picture if the content of the Drupal variable "user\_pictures" doesn't evaluate to `FALSE`. Differently, the theme function will return an empty string, which also what happens if Drupal is not able to load the user's image, or the default image set for users.

Notice also that what returned from the theme function is not merely the markup for an image; if the user has the permission to access user profiles, the image is also a link to the user profile. If you just need to output the markup for the image, then you need to use your own code.
> 0 votes

---
Tags: 7, users, media
---


# Question
Title: What's inside "print render($page['content'])"? I want to style my front page in Omega subtheme
I'm using an Omega sub-theme in Drupal 7. In my front page, I have some sort of "river of news" with all content that has the "promote to the front page" checkbox checked. I would like to create a special front page, so I've copied my page.tpl.php into a new page--front.tpl.php.

I would like to add a special CSS class to that list of content. (The list is filled with all teasers by default.) When I try to target that specific piece of content, I get only this:

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

```

Inside that is the content section, and the sidebars sections.

How do I target only the list of teasers?

# Answer
The content of the `$page` array is described in hook\_page\_alter(), where the documentation says:

> The `$page` array contains top level elements for each block region:
>
> * `$page['page_top']`
> * `$page['header']`
> * `$page['sidebar_first']`
> * `$page['content']`
> * `$page['sidebar_second']`
> * `$page['page_bottom']`
>
> The 'content' element contains the main content of the current page, and its structure will vary depending on what module is responsible for building the page. Some legacy modules may not return structured content at all: Their pre-rendered markup will be located in `$page['content']['main']['#markup']`.
>
> Pages built by Drupal's core Node and Blog modules use a standard structure:
>
> ```
>   // Node body.
>   $page['content']['system_main']['nodes'][$nid]['body']
>   // Array of links attached to the node (add comments, read more).
>   $page['content']['system_main']['nodes'][$nid]['links']
>   // The node object itself.
>   $page['content']['system_main']['nodes'][$nid]['#node']
>   // The results pager.
>   $page['content']['system_main']['pager']
>
> ```

You can use `$page['content']['system_main']['nodes'][$nid]['body']`, remembering there is a `$page['content']['system_main']['nodes'][$nid]['body']` for each node. Check its structure to see in which way you can add a CSS class to that array.
> 5 votes

---
Tags: 7, theming
---


# Question
Title: How to add java script in a content type: article or blog or basic page
I need to add following kind of java script and html element in one of my computer programe coding tutorial article:

what I want to add a java script + html to create a text box to add function to copy the text inside the box on mouse click. (I know the code and html for that, but I was unable to paste that here)

I am looking to do it through: content tab in administrative tab: add content: article: new article creation form in full html option.

Please let me know how to do it in drupal 7: by article or blog creation form or if there is any other easy way to do it.

Thanks.

# Answer
You can add javascript in template file using hook\_preprocess\_page() function.

```
<?php
function mythemename_preprocess_page(&$vars, $hook) {
  if(arg(0) === 'node' && arg(1) === 'add' && arg(2) === 'article') {
    drupal_add_js(path_to_theme().'/js/events.js');
  }
}
?>

```

Other solution is that you can use theme function.

```
function theme_content_type_node_form($form) {
  drupal_add_js(...);
  return theme('node_form', $form);
}

```

This just calls the default theme function for the node add form after adding the js. As the theme function is called even the form is cached, this works nicely. You also need to implement hook\_theme to make this work.
> 0 votes

---
Tags: javascript, theming
---


# Question
Title: Multisite- different localizations and domains but same codebase and user base
I have an established site which caters to Australian market and now I want to launch a similar site for US market.

* New site will have a different domain
* New site will have different content

However, I want both sites to share code and users so that someone who has an account on Australian site should be able to log in to US site plus any changes in code should reflect on both sites.

Sorry I am bit a knoob and will appreciate some guidance.

# Answer
You're going to have lots of fun with this one if you're a "knoob".

The module you want to look at is Domain Access. This will do pretty much exactly what you want to do. It's a slightly heavy configuration so if you are new, then you might struggle but you can probably get some assistance on #drupal-support on freenode.
> 2 votes

---
Tags: multi-sites
---


# Question
Title: Is there a module equivalent for Suggest a Friend for Drupal 7?
I am creating a social networking site for which I need the Suggest a Friend module, but it is not available for Drupal 7. Is there a similar module for Drupal 7?

# Answer
Very powerful social networking module for creating inner social network for Drupal 7 is User Relationships.

It is well supported so i guess you can accomplish what you need.
> 3 votes

---
Tags: 7
---


title: Auto-update of features?

text:
# Question
Title: Auto-update of features?
On a production site, I don't want admins to be able to perform many tasks at all, to limit the risks the site is exposed to, so modules like "Views UI" will be turned off.

However, I still want a number of administrators to have access to Views and similar functionality, so they can perform changes without a developers help.

Thus I would like to see the ability to have *some* features "auto-export" themselves, a script that commits them to the VCS, and then deploys to a stage-server where they can be tested and approved.

Is there any public work at all on this type of functionality, or would I need to start from scratch? Is the idea entirely in-sane, and if so, what other options should I pursue?

# Answer
My own suggestion is a cron job that runs

```
@drush fu [feature 1] [feature 2]
git commit -m "Auto exported features" features-dir/
git push

```

and while that could certainly work, I'm also fairly certain all kinds of problems will be discovered along the way, meaning this script will need to evolve substantially over time.

Leaving question open at least until someone with actual experience (maybe myself) leaves an answer.
> 2 votes

---
Tags: features
---


title: Problem with content type permission

text:
# Question
Title: Problem with content type permission
I have a content type called: **Activity**. Then I have a role called: **Gestor** In /`admin/people/permissions` I make sure I checked (for the Gestor role):

Activity: Create new content

Activity: Edit own content

Activity: Edit any content

Activity: Delete own content

Activity: Delete any content

Now I login with a Gestor user role and tried to go to /node/add/activity and I get **ACCESS DENY**

The content type has the defaults fields: **body** and **title**.

I already rebuild permission at: `/admin/reports/status/rebuild` but not working...

**UPDATE** **If I check `Bypass content access control` I get access to fully manage ALL content type**

# Answer
> 0 votes
You probably have a content access module (e.g. Content Access) installed that's conflicting with the default access settings.

---
Tags: nodes, users
---


# Question
Title: Change display of teaser based on content type of page in which it is displayed
So I know you can define how to display a teaser for different content types using `if($teaser)` in node--content\_type.tpl but how can I add logic to render the teaser in different formats depending on the content type of the page in which it is being displayed?

I want to do this

```
if($teaser && CONTENT_TYPE_OF_PAGE_THAT_TEASER_IS_DISPLAYED_ON == content_type)

```

within node--content\_type.tpl is there a way to go about this?

For example I have teasers of content type blog. But I want these teasers to display different when they are on a page of content-type:blog, to when they are displayed on a page of content-type:level\_3.

Thanks for your time

# Answer
> 0 votes
It is possible. In \*node--content\_type.tpl\* I can get the content type of the page in which the teaser is displayed like so:

```
$node = menu_get_object($type='node');

```

I can then use logic to render my teasers in different ways depending on the page's content type:

```
if($teaser && ($node->type == 'my_content_type')){
    //render in this way
}

```

# Answer
> 0 votes
Have you tray display suit?

Display suit let you configure how you want to print the teaser and the full content type with a great UI

Oskar

---
Tags: 7, nodes
---


# Question
Title: Drupal 7: adding html (image) to view's exposed filters fields
im having a little trouble theming the output of a view's exposed filter.

I have a `node reference` field, and in the exposed filter i want to show it as a checkbox list with, instead of the title of the referenced node, the image (that is a field, obvious).

Im doing the same thing for the node\_edit form:

```
    // This function is called via #process fapi key
function _mytheme_theme_pittogrammi(&$element)
{
    $lang = isset($element['it']) ? 'it' : 'und';

    foreach($element[$lang]['#options'] AS $nid => $label)
    {
        $pittogramma = node_load($nid);
        $image_field = _dwork_field_get_value($pittogramma->field_image);

        $image = '<img class="bubbleUp" src="'
                . image_style_url('pittogrammi', $image_field[0]['uri']) . '" alt="'
                . $pittogramma->title .'" title="' . $pittogramma->title .'" />';

        $element[$lang]['#options'][$nid] = $image;

        $element[$lang][$nid] = array(
            '#label' => $image
        );
    }
    return $element;
}

```

and it works perfeclty; For the `view_exposed_form` i hat to make a little change in the function (becose the lang is not present), but is almost the same:

```
function _mymodule_theme_pittogrammi_view_form(&$element)
{
    foreach($element['#options'] AS $nid => $label)
    {
        $pittogramma = node_load($nid);
        $image_field = _dwork_field_get_value($pittogramma->field_image);

        $image = '<img class="bubbleUp" src="'
                . image_style_url('pittogrammi', $image_field[0]['uri']) . '" alt="'
                . $pittogramma->title .'" title="' . $pittogramma->title .'" />';

        $element['#options'][$nid] = $image;

        $element[$nid] = array(
            '#label' => $image
        );
    }
    return $element;
}

```

And this `works` somehow, but the problem is that the image HTML looks like is passed throught `htmlspecialchars()` or something like, and rendered as text.

Im wondering why and why only on view's exposed form...

How can i change this behavior?

# Answer
> 0 votes
Solved: I am using BEF module (Better Exposed Filters) that, in row 532 of `better_exposed_filters.theme` used to check\_plain even the label.

Commenting that line do the trick, knowing that youre raping someone'else module (but this is the only way i found since there is no an option to dont check\_plain the label)

---
Tags: 7, views
---


title: Load entities referenced by the user

text:
# Question
Title: Load entities referenced by the user
I am using Entity reference module.

In one of my content types I have added Entity references as Users of the website. So is there any way or API function to load the entities with logged in user is associated.

**For Ex:** When User1 is creating an article node and will add other users such as user2 etc in one of my entity reference field. Now when user2 is logged in i would like to inform him that he was referenced by user1. Is there any API function to achieve it ?

# Answer
> 2 votes
I have created a view which will display all the entities in which current logged in user is referenced. Just Import this view and change it as per the content type you want.

Enjoy!!!!

```
$view = new view();
$view->name = 'users_referenced_entity';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Users Referenced Entity';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Entities in Which Logged in User is Referenced';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Referenced users (field_referenced_users) */
$handler->display->display_options['arguments']['field_referenced_users_target_id']['id'] = 'field_referenced_users_target_id';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['table'] = 'field_data_field_referenced_users';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['field'] = 'field_referenced_users_target_id';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['default_action'] = 'default';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_referenced_users_target_id']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'article' => 'article',
  'page' => 'page',
);
$handler->display->display_options['filters']['type']['group'] = 1;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['path'] = 'users-referenced-entity';

```

---
Tags: entities
---


# Question
Title: Finding the code generating the menu with links
Where is the code that generates the menu and links shown in the following photo?

# Answer
Have you tried this: http://api.drupal.org/api/drupal/includes%21theme.inc/function/theme\_link/7#comment-24463
> 0 votes

---
Tags: navigation
---


# Question
Title: Unexpected session reset when making authenticated user REST requests
1. I am using Drupal 7 and Services module
2. To create endpoints for login and subsequent functionality exposed for logged in users
3. As noted here and here, the ideal workflow should be -- Make a POST request with username and password \> to end point /user/login (the end point is already enabled) \> return data contains Session name and Session id \> you join both of them with an '=' in between to form the cookie \> you send that cookie in subsequent requests in the request header \> these requests automatically get treated as authenticated user requests \> All is good
4. But in my case when I do the last step (send cookie in request header) something weird happens. The `uid` associated with that particular session in the `sessions` table is set to 0. (In effect the session is authenticated user session anymore, it is not destroyed either, it just goes anonymous)

I am really puzzled by this. I have replicated the behavior on multiple setups, and hoping that this is just a case of me missing something obvious here.

Any help would be much appreciated? Super many thanks in advance.

# Answer
Well. I found what was causing the error (unexpected behavior) reported above. There are chances that others might get stuck in a similar fashion, so I am answering my own question -

The above resetting of Session was taking place because my service end point was not configured to work with 'authenticated sessions'. When creating a new service endpoint there is an optional checkbox labeled **Session authentication** with description `Choose which authentication schemes that should be used with your endpoint. If no authentication method is selected all requests will be done by an anonymous user.` which one needs to check so that web service resources created under that end point and allow authenticated sessions.

If you fail to check this checkbox at the time of creating the endpoint, you could do so later too, by editing the particular endpoint and clicking on the EDIT tab.
> 2 votes

# Answer
I ran into the same issue, but I'd already set session authentication for the service (REST). The request worked fine when my site was installed on root, e.g. "www.domain.com" but did not work when the site was installed in a directory at "www.domain.com/my-directory/

The solution was modifying /sites/default/files/settings.php, line #271:
`$base_url = 'www.domain.com/my-directory'; // NO trailing slash!`
> 2 votes

---
Tags: 7, theming, services
---


# Question
Title: VBO custom action: get the list of selected items
I need to create an vbo action to produce a document (pdf) with a page for every item selected in the list.

Using im using `hook_action_info` but the callback get called once for every item selected; I need to have a function that get called with the list of selected items.

I've seen the `Pass ids as arguments to a page` action, that can fit my needs, but hey I'll love to avoid having such kind of urls (if possible, of course)

Is possible?

# Answer
> 1 votes
First, I need to point out that what you are trying to do is not a smart use of VBO. VBO is usually used with single-off tasks like publishing a single node or sending an email.

In your worker function (key of your hook\_action\_info() return array), you can receive an extra argument that has meta information of the current running task and total number of tasks.

You can however do some ninja work to set another batch work and append the generate PDF function there but it's difficult to do in most cases.

# Answer
> 2 votes
You don't do it at once, you generate the document page by page (item by item). The document gets created on first run, and on the last run you do whatever cleanup you need.

See archive.action.inc that ships with VBO for an example of this approach.

You can mark your action as "aggregate", and get all rows, but that's going to significantly limit the number of items you can add to the document (depending on your memory limit). VBO is designed to work item-by-item.

---
Tags: 7, views, actions
---


# Question
Title: Redirect to profile2 page after adding user based on roles?
I'm using rules and trying to get this workflow.

Site administrator adds new user -\> redirected to the user's profile page to fill out information about the user.

I'm using the page redirect action to redirect to the profile2 edit page for the newly created user which works great. But I can't get this rule to trigger only for site administrators.

I've tried using data comparison \[ roles= site administrator \] and user roles equals site administrator but neither work.

The idea is that the site administrators can add new users and fill out their profiles immediately.

# Answer
Here's how to fix the problem I was having and a little more context on how to do it.

First you need the Rules module. http://drupal.org/project/rules

* Go to the rules configuration page, usually located at example.com/admin/config/workflow/rules

1. Add a new rule
    2. Add condition

    + User has role(s)
        + Parameters should be User: \[site:current-user\], Roles: roles for condition
        + in my case Parameter: User: \[site:current-user\], Roles: developer, site administrator
    3. add an action

    + Page redirect to new user profile
        + Parameter: URL: user/\[account:uid\]/edit/'profilename'
        + replace 'profilename' with whatever your profile2 profile is called

Before I was using the default 'account' parameter, changing it to the User: \[site:current-user\] fixed my problem.
> 1 votes

---
Tags: rules, users
---


# Question
Title: making user profile available for anonymous user viewing
I am creating a views to list the users in that I want anyone to be able to access the user's profile node. However,there doesnt seem to have any such options. Any suggestion?

# Answer
I was having this same problem and was able to solve it by going to EDIT VIEW \> ACCESS (under Page Settings) \> PERMISSION and changing it to VIEW COMMENTS. Then in the POEPLE \> PERMISSIONS area I made sure that anonymous users were permitted to view comments.
> 4 votes

---
Tags: nodes, users
---


# Question
Title: Moving Host - concern about PHP memory limit
I'm moving my projects from Bluehost to GreenGeeks, and I'm concerned about the Drupal (v7) PHP memory limits. Maybe I'm overly concerned, but has anyone experienced any issues with GG or BH about running Drupal for clients' commercial projects requiring more than average PHP memory levels above 64meg to a max 128meg memory requirement. Any comments welcome.

# Answer
> 35 votes
A 128M memory limit is often not "more than average" for a Drupal project. Also, just because you've specified 128M as the memory limit, that doesn't mean your webhost is giving you that much (or even half as much).

Let me explain. I'll use Commerce Kickstart v2 with the demo store installed as an example (matching a medium-sized Commerce store). It has 10 content types, 6 product types. 146 modules installed, out of that 23 provided by Drupal core, and 123 contrib.

Installing Commerce Kickstart requires 77M of RAM (xhprof peak memory usage). A Kickstart page (frontpage, the view that lists products in a category, faceted search page) takes about 17M (as reported by devel). This number can spike easily on admin pages that show many items, or thanks to a misbehaving module.

Our minimum memory limit requirement for Kickstart is 128M, based on our personal experience developing Drupal sites (it's easy to get "memory limit exceeded" with less than that). Also, if the server doesn't have enough memory when generating the request, it won't give you how much you asked for. I saw it with my own eyes (MacBook Pro, Chrome with a million tabs, only a bit of RAM left. PHP fails to allocate 77M of ram despite the memory limit being 128M). I also saw this complaint from people with shared hosting (I strongly believe that running anything more than a blog on shared hosting is pure masochism without excuse in the age of cheap VPS).

Why does Drupal need so much memory? Among other things, because it has a cache problem (which of course saves your database) Drupal currently likes to cache ALL views in one place, ALL fields in one place, etc. So once you get a site with many content types, fields, views, the caches become huge, and they are all loaded into your memory with each request. Thankfully, this is being fixed as we speak, thanks to people like catch (See this article for details).

The fix to Views got committed a few days ago and is now available in 7.x-3.x-dev. Quoting #29 from that thread, where the memory usage for Views dropped from 34M to 17M:

> So, for normal use, there's a 15% improvement in execution time, and 49% improvement in memory usage.

There is also a RTBC fix for fields in Drupal core that should make it into the next Drupal 7 release. Benchmarks showed savings between 1M and 50M (depending on your number of fields).

There's an in-progress fix for the system (module & theme) list in Drupal core that should shave a megabyte or two as well.

So, install Devel, go to admin/config/development/devel, enable "Display memory usage", and find out how much your pages need. Also follow the fixes I mentioned, test them and see how much they help you (they give me a few megabytes of savings on the Kickstart install, which still counts).

And of course, find a decent hosting (I don't know if GreenGeeks is decent, don't have much experience in that field), set a decent memory limit, and don't worry too much :)

# Answer
> 3 votes
Bojan's answer is great, and I gave it a +1.

Although the question was about memory limits, and not php.ini, I wanted to note that I, coming from a virtual-private-server background, initially thought that in a managed / shared hosting environment, I had to take whatever the provider gave me for php.ini.

I don't have any experience with bluehost or greengeeks, but on another managed environment I recently started using for a pro-bono client, the default memory\_limit in /usr/local/lib/php.ini (the default, uneditable location) was only 64M. The documentation was not great, but it turned out that if I copied php.ini to my home directory, then the webserver would pick it up and use it, and I could adjust the memory\_limit as needed.

So, as Bojan said, just because you set memory\_limit to a larger value (I'm using 256M) doesn't mean that you'll necessarily get that much, your fist step should be to figure out how to customize your php.ini. If you haven't already done so for your hosting provider, contact their support service and ask how, or search their documentation. Different providers may have different ways to do it.

# Answer
> 3 votes
On WebEnabled.com development servers -- Commerce Kickstart V2 requires at least 99M for a successful install. It varies, depending on the release (e.g. RC1, Beta-01) but the bottom-line is: most Drupal install profiles these days are resource hungry.

You have to put the PHP version into the equation too (although Drupal 7 runs on PHP 5.3 very well) -- sometimes contrib modules for D7 run well with PHP 5.2 and vice-versa *(we can't expect all contributors to always optimize for both php versions)*

Another observation I have when testing / building Drupal app-bundles for WebEnabled is that some install-profiles run better on a specific Linux VPS template (e.g. Ubuntu, OpenWall, CentOS) -- just my personal observation *(I have not yet tried using benchmarking tools / reports)*.

---
Tags: configuration
---


# Question
Title: Notifications from Workbench included content type
I added a new content type for my drupal 7 site and I have a form in this content type. It has the workbench enabled in this form so that the moderator can approve the submissions and close the forms if they are complete.

The functionality that I am looking to implement now is mailing the user upon the status change of the form. i.e, if the form changes from draft to closed, the user should be notified. I looked for modules or related content for implementing this, but could not find any. What is the best way to do this? Please let me know.

Thanks in advance.

# Answer
You can do this with the Rules module: http://drupal.org/project/rules

It should be pretty straightforward, once you figure out how to use Rules. (You can find some video tutorials here: http://drupalize.me/videos/basics-rules-link)

Basically, you are going to create a rule that is triggered when a node's workbench moderation state changes. When the rule runs, it will send an email. In that email, you should be able to include tokens (http://drupal.org/project/token) that will be specific to the node that was just changed.

Hope that helps.
> 2 votes

---
Tags: 7, notifications, workbench
---


# Question
Title: Why should the Hacked! module not be used on a production server?
In the source code of the Hacked! module, it says it should never be used on a production server.

```
/**
 * @file
 * The Hacked! module, shows which project have been changed since download.
 *
 * We download the original project file, and hash all the files contained
 * within, then we hash our local copies and compare.
 * This module should never be used on a production server.
 */

```

Why not? How would it compromise security?

# Answer
A quote from the developer of the module, in response to exactly the same question:

> The module is aimed at developers wanting to know what other developers got up to, not to detect if someone broke into your webserver and changed some code.

As such it doesn't really belong on a production server; it doesn't appear to be a security risk (although it does download to your local files folder), it's just not what the module was designed for.

There's also another comment on that post that sums it up nicely:

> It's not that it's fragile, unstable or (very) dangerous. It's just that "You're doing it wrong" if a production site is where you actively use the features provided by "hacked".
> 3 votes

---
Tags: 7, security
---