# Question
Title: How do I remove the Title "Languages" from the Language Icon Module?
I am trying to create a bilingual site from a Drupal 7 site that already exists in English. I have absolutely no programming background, yet have managed to make it quite far thanks to reading other individuals' questions and answers on Drupal Answers. Thanks guys!

Now I have some questions of my own :) For these questions the page I am referring to is http://laidea.us/testingpage

1. I would like to remove the title "Languages" or "Idiomas" (in Spanish) from the Language Switcher block. I tried seeing if I could do that in views, but couldn't find the Language Switcher block there.
2. I would like to have my language icons be side by side, and without the list bullets next to them.
3. I've noticed that it says what language the content is in, and there is a language switch below my text. How do I get rid of/ hide these fields?

Thank you for your help!

-Jane

# Answer
> 0 votes
previous answer is correct, you need CSS styling. The reason that I provide another answer is because you said you have no programming background, so I guess you don't know where to copy-paste the correct code. So here is what you can do:

* download the module css injector
* enable the module
* go to configuration -\> development -\> css injector (admin/config/development/css-injector)
* create a new rule and give a name to the rule: e.g. front-page styling
* Finally in this rule write your CSS. (here paste the code provided by Елин Й.) **EDIT**: if you can't find a way to remove the LANGUAGE title, there is a quick and dirty solution: add the following:

```
#block-locale-language-content h2 {display: none;}

```

If you want to style your website, you really **need to** study a bit CSS, which is very easy and not like difficult programming. You just target(select) the correct things, the styling of which you would like to change, and then apply some changes to them. It's really simple, don't be afraid of it!

for example

```
li {
  color: blue;
  background-color: red;
}

```

would select all the lists in a website (like the language lists) and make the color blue and the background color red :)

To recap:

# Answer
> 3 votes
To remove the title 'Languages', configure the block, and set the title as `<none>`

To have the icons side by side and remove the list bullets you need to specify some css in your theme:

```
section.block .content .language-switcher-locale-url li {
  background: none; // in your case, you have background set
  display: inline-block; // to make them side by side
  list-style-type: none; // to get rid of listing bullets
}

```

---
Tags: 7, i18n-l10n
---


# Question
Title: Is Drupal following W3C standards? How to change the DOCTYPE?
I tested two of my sites in W3C validator. One site passed the test and other site gave me lot of errors. Site2 was having the doctype `-//W3C//DTD HTML+RDFa 1.1//EN` instead of HTML5. But site1 was having HTML5.

How to change the doctype to HTML5 for Site2?

# Answer
This would completely depend on the theme you are using on the Drupal site, as the markup of the site is handled on the theme layer.
If you are using an HTML5 theme, then the it will show the appropriate DOCTYPE i.e. `<!DOCTYPE html>`. In short, your theme should support HTML5 in order to get the DOCTYPE.

To answer your question, you'll need to either make your theme compatible to HTML5, or use any other HTML5 theme.
There is a very good article for Converting Your Drupal 7 Theme Into HTML5 which could give you a good start.
> 6 votes

# Answer
The HTML+RDFa 1.1 Doctype (which will be valid for HTML4 & 5) is still under development:

As such The W3 validator doesn't recognise it, even though your document might well validate against the standard itself.

So to answer your question, yes, Drupal (or what's more likely, the *theme* that you're using) is conforming to W3C standards, it's just that the spec hasn't been ratified yet.

You might see advice out there telling you *not* to use that `DOCTYPE`, that `<!DOCTYPE html>` should be used instead. That advice is incorrect, per the specification
> 6 votes

# Answer
I recently had to validate a Drupal website and was happy to find out that the W3C has a "Nu", experimental validator, which can be preset to take RDFa 1.1 into account (among other things).

Using this validator instead of the default one made all of the RDFa-related validation errors disappear, but you have to manually set up the "Preset" parameter to `HTML5 + SVG 1.1 + MathML 3.0 + RDFa 1.1 + Microdata`.
> 1 votes

---
Tags: theming
---


# Question
Title: Validate CCK field to not allow links/URLs
I want to allow users to input free text, but don't want them including any links or references to URLs. I know how to set up a filter on the CCK field so that 'a' tags cannot be included, but this will not stop the user typing www.google.com etc.

I have tried searching for modules to achieve this, but have not managed to find any. Does anyone know of a module to filter CCK fields to validate for 'www', '.com' etc, or alternatively one for custom CCK validation?

If there aren't any modules I think I would have to follow these instructions to build a custom CCK Validation module. I would appreciate advice on whether this would be the most efficient approach or if this would be reinventing the wheel?

# Answer
> 1 votes
Ok, So I have worked out how to do this.

First install the Field validation module.

Then go to the 'manage fields' page for your content type. To the right of each field is a 'validate' link. Click on validate for the field you wish to add validation for.

Click 'PHP code' and note the 'Be careful, it is powerful and also dangerous.' warning!

Enter a rule name such as 'dont allow URLs'.

In the PHP code box enter the php you wish to validate. I made an array of all the the top level domains etc I didn't want users to use, and checked the input against this in a foreach loop. The code I used to do this is:

```
$mystring = $this->value;
$arr = array("http", "https", "www", ".com", ".org", ".net", ".info", ".mil", ".mobi", ".edu", ".gov",  ".biz", ".ac", ".ad", ".ae", ".af", ".ai", ".al", ".am", ".ao", ".aq", ".ar", ".as", ".at", ".au", ".aw", ".ax", ".az", ".ba", ".bb", ".bd", ".be", ".bf", ".bg", ".bh", ".bi", ".bj", ".bm", ".bn", ".bo", ".br", ".bs", ".bt", ".bw", ".by", ".bz", ".ca", ".cc", ".cd", ".cf", ".cg", ".ch", ".ci", ".ck", ".cl", ".cm", ".cn", ".co", ".cr", ".cu", ".cv", ".cw", ".cx", ".cy", ".cz", ".de", ".dj", ".dk", ".dm", ".do", ".dz", ".ec", ".ee", ".eg", ".er", ".es", ".et", ".eu", ".fi", ".fj", ".fk", ".fm", ".fo", ".fr", ".ga", ".gd", ".ge", ".gf", ".gg", ".gh", ".gi", ".gl", ".gm", ".gn", ".gp", ".gq", ".gr", ".gs", ".gt", ".gu", ".gw", ".gy", ".hk", ".hm", ".hn", ".hr", ".ht", ".hu", ".id", ".ie", ".il", ".im", ".in", ".io", ".iq", ".ir", ".is", ".it", ".je", ".jm", ".jo", ".jp", ".ke", ".kg", ".kh", ".ki", ".km", ".kn", ".kp", ".kr", ".kw", ".ky", ".kz", ".la", ".lb", ".lc", ".li", ".lk", ".lr", ".ls", ".lt", ".lu", ".lv", ".ly", ".ma", ".mc", ".md", ".me", ".mh", ".mk", ".ml", ".mn", ".mo", ".mp", ".mq", ".mr", ".ms", ".mt", ".mu", ".mv", ".mw", ".mx", ".my", ".mz", ".na", ".nc", ".ne", ".nf", ".ng", ".ni", ".nl", ".no", ".np", ".nr", ".nu", ".nz", ".om", ".pa", ".pe", ".pf", ".pg", ".ph", ".pk", ".pl", ".pm", ".pn", ".pr", ".ps", ".pt", ".pw", ".py", ".qa", ".re", ".ro", ".rs", ".ru", ".rw", ".sa", ".sb", ".sc", ".sd", ".se", ".sg", ".sh", ".si", ".sk", ".sl", ".sm", ".sn", ".sp", ".sr", ".ss", ".st", ".sv", ".su", ".sx", ".sy", ".sz", ".tc", ".td", ".tf", ".tg", ".th", ".tj", ".tk", ".tl", ".tm", ".tn", ".to", ".tr", ".tt", ".tv", ".tw", ".tz", ".ua", ".ug", ".uk", ".us", ".uy", ".uz", ".va", ".vc", ".ve", ".vg", ".vi", ".vn", ".vu", ".wf", ".ws", ".ye", ".za", ".zm", ".zw", ".name", ".pro", ".aero", ".asia", ".cat", ".coop", ".jobs", ".museum", ".tel", ".travel");
    foreach ($arr as &$findme) {
           $value = strpos($mystring, $findme);
           if ($value === false) {
           } else {
               $this->set_error();
           }
    }

```

Check the tick box that says 'Set errors using field API'

In the last text box you add your custom error message. E.g.

```
Please remove all links/URLs for example: 'www', '.co.uk'& '.com'. Please check that you have a space after each full stop.

```

I hope that this helps somebody else.

---
Tags: forms
---


# Question
Title: How to write options lists with drush vset?
When we want to pin a variable for an environment, we'll set the value in the admin, then go look it up in the database, and copy the name and value into a bash or phing script, to insure that that variable is always set to the appropriate value for the environment.

However, for complex variables, such as options lists, what should set string look like? For example node\_export\_file\_types looks like this in the database:

```
a:29:{s:4:"blog";s:4:"blog";s:10:"case_study";s:10:"case_study";s:7:"analyst";i:0;s:5:"asset";i:0;s:4:"book";i:0;s:6:"course";i:0;s:8:"download";i:0;s:8:"employee";i:0;s:19:"evaluation_download";i:0;s:4:"news";i:0;s:17:"front_page_header";i:0;s:11:"hero_banner";i:0;s:12:"landing_page";i:0;s:11:"layout_page";i:0;s:10:"news_event";i:0;s:10:"news_press";i:0;s:7:"product";i:0;s:16:"product_overview";i:0;s:17:"product_resources";i:0;s:15:"product_webinar";i:0;s:8:"workshop";i:0;s:12:"registration";i:0;s:8:"resource";i:0;s:7:"license";i:0;s:7:"support";i:0;s:16:"training_courses";i:0;s:16:"training_request";i:0;s:17:"training_webinars";i:0;s:7:"webform";i:0;}

```

if we wanted to set that using drush vset node\_export\_file\_types 'somestring' what that 'somestring' look like?

# Answer
> 1 votes
You can use drush.

`drush vget foo --pipe`

The `--pipe` option will format the output as php code.

As far as using that with `drush vset`, I would recommend against that and instead set via an update hook, or directly in settings.php.

---
Tags: configuration, importing-exporting
---


title: Creating user profile types

text:
# Question
Title: Creating user profile types
I'm trying to make a record of different user profiles. And each of them, possess or display different items, apart from those who normally come (Username, Email, Photo, etc..). Something like:

* Profile of Visitors ==\>\>\>\> Only Images / Photo
* Employee Profile ==\>\>\>\> Birth Date, Curriculum Vitae, etc.
* Artist Profile, ==\>\>\>\> Albums of: Videos, Music, and / or Photos
* Business Profile ==\>\>\>\>Photo Albums / Images.

And each user is able to handle each of these elements.

E.g.: \- If I am a musician, update my music files or Albunes Photo. \- If employed Update My Currillo vitae. And so on ...

It will be possible to do this with Drupal 7?. Please Any suggestions?

Best Regards

# Answer
There is Profile 2 module

> Profile2 allows for creating multiple profile types, which may be assigned to roles via permissions (e.g. a general profile + a customer profile)

Also check this wonderful answer by kiamlaluno
> 2 votes

# Answer
One option is to add all the fields to the user profile for all users, and then control access based on Field Permissions and assigning roles. If you only have a few fields with this requirement, controlling them via permissions may be the simplest way, but if you have to do a lot of fields this way, it will quickly become very complicated, and I would use Profile2 as Nikihil M suggested.
> 2 votes

---
Tags: views, users
---


title: Login Security block my IP address

text:
# Question
Title: Login Security block my IP address
I installed the Login Security module to block IP address for more than 4 number of login attempts, but unfortunately my IP blocked.

I tried uninstall the module, but still my IP address blocked. How to remove ban for my IP address. It shows the message **Sorry, 00.000.00.00 has been banned.**

I'm using Drupal 6.

# Answer
> 2 votes
Even though I uninstalled the module, I kept being banned. To remove the ban for a particular IP, I followed the following steps:

* Connected to the database
* Changed the *access* table; either changing the status to 1 or deleting the row with mask equal to '127.0.0.1' and type equal to 'host' works

I found the solution on Sorry, 127.0.0.1 has been banned.

---
Tags: 6, users
---


# Question
Title: Problem using ColorBox with Media Galllery
I want to create photo gallery using the Media Gallery module. One of the requirements given is to unpack the ColorBox jQuery plugin in `sites/all/libraries`.

I downloaded the file `colorbox-master.zip` and extracted it in `sites/all/libraries` so the path of colorbox is `sites/all/libraries/colorbox-master`

I am able to create gallery but effect of the ColorBox is not visible. What do I have to do to make the gallery photo show up in the ColorBox?

# Answer
> 2 votes
Actually all you should need to do is change... Well, you'll need to change two things actually:

1. Rename `sites/all/library` to `sites/all/libraries`
2. Rename `colorbox-master` to `colorbox`

The final output should look like this: `sites/all/libraries/colorbox`

And don't forget to flush the caches after you make the changes, just to make sure the system recognizes them. ;)

Hope that helps... :)

---
Tags: javascript
---


# Question
Title: How to Display terms only if associated with a node
Using Drupal 6: I need to show child terms for the currently viewd taxonomy term in a block. I finally stumbled on a piece of code that does exactly what I want. Original code from here

As per the instructions I've added the following to my template.php

```
function themename_child_terms($vid = 1) {
  if(arg(0) == 'taxonomy' && arg(1) == 'term') {
    $children = taxonomy_get_children(arg(2), $vid);
      if(!$children) {
        $custom_parent = taxonomy_get_parents(arg(2));
          $parent_tree = array();
          foreach ($custom_parent as $custom_child => $key) {
            $parent_tree = taxonomy_get_tree($vid, $key->tid);
          }
          $children = $parent_tree;
      }

    $output = '<ul>';
    foreach ($children as $term) {
      $output .= '<li>';
      $output .= l($term->name, 'taxonomy/term/' . $term->tid);
      $output .= '</li>';
    }
    $output .= '</ul>';

    return $output;
  }
}

```

I've then created a block and added :

```
<?php // $vid is the vocabulary id.
    print themename_child_terms($vid = 1);
?>

```

This shows the child terms of the current term perfectly. However, it shows ALL terms that exist under the parent term, even if there are no nodes tagged with that term.

e.g. viewing the page with all items in 'Term 1', I get

child 1 child 2 child 3

correctly listed in the block. But, if there are no pieces of content tagged with 'child 3' for example, it's still showing up that term in the block. This isn't very useful as it links to an empty term page.

How would I modify the code to only show children that actually have nodes associated with them. So if there are no children tagged 'Child 3', then that term would not show up..

I've found this function in taxonomy.module Can I use this function to do what I want?

```
/**
 * Count the number of published nodes classified by a term.
 *
 * @param $tid
 *   The term's ID
 *
 * @param $type
 *   The $node->type. If given, taxonomy_term_count_nodes only counts
 *   nodes of $type that are classified with the term $tid.
 *
 * @return int
 *   An integer representing a number of nodes.
 *   Results are statically cached.
 */
function taxonomy_term_count_nodes($tid, $type = 0) {
  static $count;

  if (!isset($count[$type])) {
    // $type == 0 always evaluates TRUE if $type is a string
    if (is_numeric($type)) {
      $result = db_query(db_rewrite_sql('SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 GROUP BY t.tid'));
    }
    else {
      $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.status = 1 AND n.type = '%s' GROUP BY t.tid"), $type);
    }
    $count[$type] = array();
    while ($term = db_fetch_object($result)) {
      $count[$type][$term->tid] = $term->c;
    }
  }
  $children_count = 0;
  foreach (_taxonomy_term_children($tid) as $c) {
    $children_count += taxonomy_term_count_nodes($c, $type);
  }
  return $children_count + (isset($count[$type][$tid]) ? $count[$type][$tid] : 0);
}

```

Thank you kindly for any solutions.

Nick

# Answer
Hmm... I'd try something like this:

Change this part of your code:

```
foreach ($children as $term) {
  $output .= '<li>';
  $output .= l($term->name, 'taxonomy/term/' . $term->tid);
  $output .= '</li>';
}

```

to something like this:

```
// Avoid unnecessary "Invalid foreach" errors showing up in the log:
if (!empty($children)) {
  // If not empty, run the foreach loop:
  foreach ($children as $term) {
    // Then check to see if any nodes exist for that term id:
    $number_of_nodes = taxonomy_term_count_nodes($term->tid);
    // If there ARE nodes...
    if ($number_of_nodes > 0) {
      // ... then add them to the output:
      $output .= '<li>';
      $output .= l($term->name, 'taxonomy/term/' . $term->tid);
      $output .= '</li>';
    }
  }
}

```

Hope that helps... :)
> 0 votes

---
Tags: taxonomy-terms
---


title: Filter view with multiple displays

text:
# Question
Title: Filter view with multiple displays
Using Drupal 7. I have a view with several page displays, 2 of them being /review and /mentions. I have some exposed filters on these pages visible on a side block of the page.

When clicking the apply button to filter the content, I get redirected to /review?filter=.... whether I am on the /review page or /mentions page.

How can I make the filter work so that
\- when filtering the /review page, I land on /review?filter=...
\- when filtering the /mentions page, I land on /mentions?filter=...

Thanks for your help,
Jerome

# Answer
> 0 votes
I found what I was doing wrong.

I assumed that the exposed filter block for the view was the same for all displays of that view, When it actually creates 1 block per display.

I disabled the block "Exposed form: filter\_view-page" for the /mention path and added the another block "Exposed form: filter\_view-page\_2" for it.

Works fine now.

---
Tags: views
---


# Question
Title: Problem trying to create a boolean view filter
Drupal 7.22 Views 7.x-3.7

Hi, I have two similar content types and have added a boolean field to both (x for one and y for the other). I want to create a view that displays any of the two types if x or y is true.

If I add the first filter criteria: Content: x (= Yes), I see a result in the preview pane. If I remove the first filter criteria and add the second filter criteria: Content: y (= Yes), I see a result in the preview pane.

So both work on their own. **If I try to 'or' them I get neither?**

I have tried this in various ways (one filter group or two separate groups). I have also tried simplifying this by changing the fields to text but the or is still not working?

Please can anyone help or point me in the right direction?

Thanks! a.

# Answer
> 1 votes
Add a boolean value to both content types, should be the same boolean you created. no need to create a different boolean field for each content type.

create a view:

1. filter for the "Operator - Is one of" and chose your two content types.
2. filter for you boolean field wich was added to both content types "Operator - Is one of" and select "yes" or 1 depending on your field yes value.
3. add what ever fields needed.

I have created two content types "content one" and "content two" and added the boolean field "check me" to both.

here is my view:

---
Tags: views
---


# Question
Title: How can I prevent users from inputting URLs into a field?
I'm pretty sure this is a dupe of a question from a couple weeks ago but I've been searching for about 15 minutes and I can't find it (somehow forgot to favorite it).

I want to prevent users from inputting their e-mail addresses or URLs into a text field. How can I automatically reject such submissions?

On the `Plain text` input filter, there is an option to **Convert URLs into links**, which also converts e-mail addresses into links. But what I want to do is *remove* all URLs, including e-mail addresses, that would be converted via this option. Is that possible?

# Answer
The Field validation module let you set up your own regexp or PHP code to validate (or not) what user puts into a text field. However to reject e-mail addresses, your validator must be clever enough to not only recognize regular e-mail addresses such as `spammer@example.com` but also obfuscated e-mail adresses such as `spammer(at)example.com`.

Added note (about filtering): If, instead of rejecting input that do not validate, you want it filtered by having email addresses and links removed (or replaced with some string indicating redaction), you can use the *Plain text* input filter as a starting point, and just replace the code that currently turns email-adresses and URLs into live links, with code that redacts these things instead. Then, just rename the result of hacking the code, and add it to your configuration as a custom filter.
> 3 votes

# Answer
You can always create a module that defines its own filters. If you look in the core filters.module, `_filter_url()` is the bad boy that implements the **Convert URLs into links** filter, so I'd take that as a good starting point for the regexs need to obfuscate or remove the urls from the field in question. Then create a new input filter using your new filter instead of the stock ones and assign that to that field and you should be on your way.

Now, if you wanted to reject the node submission if any email address or urls were present anywhere in the field, then the Field validation module mentioned above/below is a great way to go.
> 2 votes

# Answer
I've been struggling with this problem too. My solution was to use Field validation module with custom PHP. Despite a lot of searching I only just came across your question. I have already documented the code I used over on the question I asked about this. I don't know whether it would be best 'Drupal Answers' practice to repeat the code here or not?
> 2 votes

---
Tags: forms
---


# Question
Title: Code in URLs despite clean URLs turned on
The site I'm working on, shows the URL like this: `http://www.sitename.com/page-name#.Uad4adKmjoY`

It shows "`#.Uad4adKmjoY`" at the end of url, even though I've enabled the clean urls.

Anyone know why it is showing this? I've not come across this before.

# Answer
> 0 votes
According to this posting on StackOwerflow and this one on Drupal Answers, these appear if there is Javascript in place to add "AddThis" tracking to the website. They do no harm, and if it's not your site, you should leave them alone.

(Note that this has nothing to do with clean URLs in Drupal. Drupal's clean URLs changes things like `example.com/?q=node/123` into `example.com/node/123`. It does nothing with hashmarks added to URLs.)

---
Tags: uri
---


# Question
Title: How can I use Rules to publish nodes depending on changing the value in a Field?
I would like to set up rule to detect if I change one specific field in the content type. For example if I choose the field "dyzury", then the rule will publish this node to the front page with the new value in the field.

How can I achieve this?

# Answer
> 1 votes
Set the rule to fire on the event *Before saving content* so you will have both values of the field available.

Set the conditions as follows:

1. *Node is of type* and select your content type.
2. AND *Entity is new*. Your data selector should be `Node` and negate the condition (NOT new)
3. AND *Entity has field*, Again your data selector should be `Node` and select your field\_dyzury from the drop-down list to make the field available to the rule.
4. AND *Data comparision* and using data selectors for both values choose `[node-unchanged:field-dyzury]` and `[node:field-dyzury]`. Select the `Equals` operator and negate the condition (NOT equal)

It is important to detect that the node is not new, or there will be no existing data value for the comparison.

Then set the Action to *Promote content to front page*. Again, data selector should be `Node`.

This rule will detect any change in field\_dyzury, and will promote the content to the front page when a change is detected.

Edit:

The conditions should look like:

```
+ Content is of Type
+ AND
    + NOT Entity is new
+ AND
    + Entity has field
+ AND
    + NOT Data comparison

```

The AND's force the rule to require ALL of the conditions to evaluate to true before the actions are performed.

---
Tags: entities, nodes, rules
---


# Question
Title: View published content to anonymous users front page only
I have the *Content access* module installed, but it's not good for sorting this. I just want to make it so deny access is not denied on frontpage.

In permissions I have de-selected view publish content for anonymous users, but how can I make it so they can view the front page?

# Answer
As long as they don't have permission to view content, and as long as your template file(s) say `print render($page['content'])` then they should be denied access.

However, you *could* do something like this:

1. Make a custom template file called `page--front.tpl.php` inside your theme's folder
2. Copy the contents of `page.tpl.php` to that file
3. Alter the new `page--front.tpl.php` file so that it either doesn't render any content anywhere (including the sidebars), or make it so it only renders the content to logged in users.

Example:

```
<?php if (user_is_anonymous()): ?>
  <?php print t('Hello. This is where you would normally see content.'); ?>
<?php else: ?>
  <?php print render($page['content']); ?>
<?php endif; ?>

```
> 2 votes

---
Tags: nodes
---


title: Filtering Views using referencing nodes

text:
# Question
Title: Filtering Views using referencing nodes
I have a bit more complicated problem here, so I'll describe the background first.

In my Drupal 7 site, there are two content types: the 'car' and the 'inspection'. The only two important things about them is that the 'inspection' includes 'Date' field and that 'car' and 'inspection' are linked using Node References module (there's Node Reference Field named 'Car' in 'Inspection').

Now, here's my problem. I need to create a view that shows only the cars that haven't been on inspection in last two years which means that they have no 'inspection' with date \> two years ago referencing them.

I'm able to achieve that if there's only one or none inspection referencing the car. In that case, I simply use 'Filter Criteria' on Date property of Nodes referencing this car (using relationships) and it works just fine.

However, if there are more 'inspections', the filter takes every single one and list the car whenever there's at least one with date \< 2 years ago (even if there's another one newer).

What I need is to somehow create a filter that would consider all 'inspection' nodes that are referencing the 'car' and shows the car only if there was none that would be newer than 2 years ago.

I hope it is clear.

//I have one more smaller problem that is (probably) connected with this one. I need to show the date of the newest inspection of a car in a view of cars. The view, however, always shows the oldest one (Table-\>Fields-\> Date field of 'inspection'-\> Nodes referencing this one 'car').

//BTW: If you don't understand the problem I have because of my level of English, please tell me. I'll try to rewrite it in a simpler way.

# Answer
> 0 votes
The first thing I would say is that it sounds as if you have node references going both ways. This is generally a bad thing in terms of database structures. In this case you should only have inspections pointing at cars and use reverse references if you need to do the opposite.

Anyway here's what I would do:

A view based on inspections, filter the content type to inspections only and also filter the date. That gives you all the old inspections.

Put the Car Node Ref into the field list and then Group By that field (Group By is under View \> Advanced \> Use aggregation)

You could then add a relationship based on the Car Node Ref which then gives you access to the individual Car fields.

This will give you one row per car for inspections older than \[whatever you choose\].

My only concern then is whether you might get a car which has inspections for \>2 years ago and also more recent ones. So will appear in the list even though it has more recent ones.

---
Tags: views, nodes
---


title: Comments custom fields access by role

text:
# Question
Title: Comments custom fields access by role
Ive added a custom comment field to comments of my node i.e. new fields beneath comment\_body that being field\_flag\_reason and field\_unflag\_reason

I want to hide these two fields for specific roles so I'm looking to use a hook with the logic to display when appropriate, the difficulty I'm having is I'm confused as to what element I should be trying to target in the rendered array and any changes I try don't seem to take effect, think I might be going about it the wrong way, any help would be greatly appreciated.

# Answer
> 1 votes
Have you ever tried Field Permission. I think it'll help to solve your requirements. Check the video tutorial to use that module Drupal 7 Field Permissions Module

---
Tags: entities, nodes, comments
---


title: drush cc all != "Flush all caches"

text:
# Question
Title: drush cc all != "Flush all caches"
If I try and clear my drupal site's cache using drush cc all command - the command completes successfully but when I pull up my drupal site in a browser its a mangled mess because there is no CSS.

Whereas if I sign into my site as an admin go to "Flush All Caches" my site works just fine.

This is discussed briefly here: http://dnotes.net/blog/dark-side-drop/david/why-all-my-css-gone-drush-cc

Although I don't really see a solution.

I think the underlying issue is that drush cc all isn't re-creating LESS CSS files but the "Flush All Caches" is? Is there some way I can make drush re-create the LESS files after a cache clear?

Thanks Brad

# Answer
> 16 votes
Clearing cache via the UI and via drush both end up calling `drupal_flush_all_caches()`, but there is a subtle difference.

When you run from the UI, the PHP executes as Apache (or however you have your webserver configured). When you run from drush, it runs as the user who executed the command.

The problem in your case is that the LESS module will run its cron functions, which clears out the less directories in sites/default/files and makes a new one. When this happens, there is often a permission problem: your drush user owns the less directory and Apache can't write to it. Therefore, your CSS files don't get regenerated and your site end up unstyled.

My solution is to make sure my drush user is also in the Apache group on my server, and that my sites/default/files directory has 2775 permission on it and with ownership by apache:apache. I also make sure that the umask of httpd makes things group writable.

This makes sure that any files and directories that get created always have group ownership by apache, and that Apache can write to any directories that get made, regardless of whether it was done by httpd or from the command line.

EDIT:

There is one more difference that is worth noting. When you clear with drush, you just clear the caches. When you clear from the UI, you clear the caches and then the page reloads. When the page reloads from a cold cache, the parts used to rebuild that page get cached again. This includes making CSS files from the LESS sources.

# Answer
> 1 votes
You could use the 3.0 branch, currently 7.x-3.0-rc1.

The 3.0 version through Drush only deletes directories on cache clear, and does not recreate them, thus avoiding the issue of Drush running under a different user as the web server.

Directories are created on demand by the LESS module, so only when a user requests a page through the web server, so the directories are created under the web server user.

A full 7.x-3.0 release will be coming out as soon (hopefully this week).

---
Tags: drush, theming
---


# Question
Title: webform save draft after each field update - ajax error for anonymous user
I wanted to save webform's draft after each field's update, and i did it with help of this post: Webform save draft after each field update .

But it is only working for logged in user, if i try it with anonymous i get ajax error

"An AJAX HTTP request terminated abnormally. Debugging information follows. Path: /system/ajax StatusText: n/a"

Does anybody have any idea why is this happening? thank you ..

# Answer
> 1 votes
The save draft functionality has not yet been committed for webform for anonymous users.

According to the post you mentioned, @Stefan in his answer claims he added the functioanlity by incorporating my patch from this issue. (We are testing an updated patch which will be posted to the issue cue within the next couple of days.)

---
Tags: forms, ajax, webforms
---


# Question
Title: WYSIWYG editor not displaying buttons and plugins
I'm new to drupal and have not found an answer on SO yet. I've updated to drupal 6.28, not ready to update to D7 yet, and the WYSIWYG and TinyMCE are not displaying. Also I can't click/unclick checkboxes for buttons and plugins because I don't see checkboxes! I also can't

Using `TinyMCE 5.3.8`. Other User Interface modules my site has are `Superfish, jQuery plugins, IMCE Wysiwyg API bridge`

Screenshots below. Thanks!

https://i.stack.imgur.com/McA7x.jpg

https://i.stack.imgur.com/Zzvwa.jpg

# Answer
> 0 votes
Please look at your browser javascript console (native, Firebug, etc.), when the page with TinyMCE is loaded and post any error here (if there is no error, please reload the page). It will make possible to determine the cause of issue.

---
Tags: 6, users, wysiwyg, input-formats
---


title: run javascript every 24 hours

text:
# Question
Title: run javascript every 24 hours
I want to run a piece of javascript every 24 hours for each specific user? This is to clear HTML5 local storage, how would I run this script every 24 hours for each user when they are logged in?

# Answer
The best way would be to to store an additional value in local storage that is the last time you cleared it.

Each page view, you simply check that value and if the last time was \> 24 hours ago, you clear the local storage and set the last clear time to now.

```
(function () {

  var lastclear = localStorage.getItem('lastclear'),
      time_now  = (new Date()).getTime();

  // .getTime() returns milliseconds so 1000 * 60 * 60 * 24 = 24 days
  if ((time_now - lastclear) > 1000 * 60 * 60 * 24) {

    localStorage.clear();

    localStorage.setItem('lastclear', time_now);
  }

})();

```

Put this in a JS file that is added only when the current user is logged in.

Here is an example using a module named 'sample':

```
/**
 * Implements hook_init().
 */
function sample_init() {
  global $user;

  // User with uid 0 is anonymous/logged out, any uid greater is logged in.
  if ($user->uid > 0) {
    drupal_add_js(drupal_get_path('module', 'sample') . '/js/sample.js');
  }
}

```
> 5 votes

# Answer
The simplest way to perform a periodic execution of a javascript code is to use **setTimeout(functionname() , time in millisecond)** function. Write a function say func() and write the javascript code you want to run in the function and at last use setTimeout() function.. e.g.

```
function func() {

.....
........
line of code....
......
.....

setTimeout(function(){
  func(arguments if any);
},24*60*60*60);
}

```

For customizing this for each user you may use php code to check for user authenticity.Hope This helps..
> 0 votes

---
Tags: 6, cron
---


# Question
Title: Is there any way to dynamically add a CSS class selector to a view with submitted exposed filters?
I need to add some different styling to a view based on whether the exposed filters have been applied or not. Eg add the class "filtered" once a person has submitted their info in the exposed filter?

# Answer
> 4 votes
You can do this with View's pre\_render hook, eg, something along the lines of this:

```
function YOURMODULE_views_pre_render(&$view) {

  if ($view->name=='NAME_OF_YOUR_VIEW') {
    drupal_set_message('<pre>' . $view->exposed_data . '</pre>'); // to see what you have to work with
    if (!empty($view->exposed_data['type'])) {
      $view->display_handler->set_option('css_class', 'view-has-been-filtered');
    }
  }

}

```

The above is based on a node type exposed filter, you will need to look at your View to see what filter names are involved, but the logic is that the exposed\_data filter arrays will be empty until you have applied the filter. For example, here, this looks like this when you first go to the View:

```
Array
(
    [type] => Array
        (
        )

    [submit] => Apply
    [form_build_id] => form-85a47ba22bc12a8b443e4cc35afe75f7
    [form_token] => 105c57eec73efe4cfedd9acabc55786a
    [form_id] => views_exposed_form
    [] => Apply
)

```

and this is what it looks like after selecting 'foo' as a type in the exposed filter:

```
Array
(
    [type] => Array
        (
            [foo] => foo
        )

    [submit] => Apply
    [form_build_id] => form-85a47ba22bc12a8b443e4cc35afe75f7
    [form_token] => 105c57eec73efe4cfedd9acabc55786a
    [form_id] => views_exposed_form
    [] => Apply
)

```

ADDITION:

If this works for you, and per your comment, I suppose the following would work for any/all Views, but I haven't battle tested it...

```
function YOURMODULE_views_pre_render(&$view) {

  $filter_classes=array('view-has-been-filtered');

  if (!empty($view->exposed_data) && is_array($view->exposed_data)) {

    foreach($view->exposed_data as $k => $key) {
      if (is_array($key) && !empty($key)) {
        $filter_classes[]='view-has-been-filtered-by-' . str_replace('_', '-', $k);
      }
    }

    if (count($filter_classes) > 1) {
      $view->display_handler->set_option('css_class', implode(' ', $filter_classes));
    }

  }

}

```

...with the logic here being the only arrays in `$view->exposed_data` are filters, and if they aren't empty, the View has been filtered.

EEEK ADDITION:

My logic is somewhat flawed in that my initial tests were for filters that allowed multiple selections, and, of course, Views used arrays to capture them in `$view->exposed_data`. If your filters are just single value fields, Views will do something like this first:

```
Array
(
    [multiple_value_allowed_type] => Array
        (
        )

    [field_single_value_field] => All
    [submit] => Apply
    [form_build_id] => form-f601bde36c625db96bad7a84bf4fa210
    [form_token] => 105c57eec73efe4cfedd9acabc55786a
    [form_id] => views_exposed_form
    [] => Apply
)

```

so I guess the following dull ax approach would work:

```
function YOURMODULE_views_pre_render(&$view) {

  $filter_classes=array('view-has-been-filtered');

  if (!empty($view->exposed_data) && is_array($view->exposed_data)) {

    foreach($view->exposed_data as $k => $key) {
      if (is_array($key)) {
        if (!empty($key)) {
          $filter_classes[]='view-has-been-filtered-by-' . str_replace('_', '-', $k);
        }
      } else {
        switch ($k) {
          case 'submit':
          case 'form_build_id':
          case 'form_token':
          case 'form_id':
            break;
          default:
            if (!empty($k) && $key != 'All')  {
              $filter_classes[]='view-has-been-filtered-by-' . str_replace('_', '-', $k);
            }
        }
      }
    }

    if (count($filter_classes) > 1) {
      $view->display_handler->set_option('css_class', implode(' ', $filter_classes));
    }

  }

}

```

DOUBLE D'OH ADDITION:

Of course, this quick and dirty logic also works:

```
function YOURMODULE_views_pre_render(&$view) {

  if (!empty($view->exposed_data) && count($_GET) > 1) {
    $view->display_handler->set_option('css_class', 'view-has-been-filtered');
  }

}

```

ADDITION DUE TO COMMENTARY:

If you are setting css classes via the UI that you want to preserve, you can do this:

```
$view->display_handler->set_option('css_class', $view->display_handler->get_option('css_class') . ' view-has-been-filtered');

```

which gets that UI option and then adds the `view-has-been-filtered` class to it. Please note the required space in front in the code :)

# Answer
> -2 votes
To any view,you can add a different css class by 1. First clicking on the editing option on a view 2. In the Page details,click on ADVANCED properties 3. Add the **css** class to the second last attribute present there which is css class. This way you can add css classes to every view.

---
Tags: views
---


# Question
Title: Can you resume sending mails to a list of which only part of the addresses are having had a newsletter?
I set cron throttle to 500 and then cron to run every hour. Using a shared server on hostgator, apparently this appears to be too much. So what ended up happening is only 1000ish of my 2500 mail address were being sent a simplenews newsletter.

So is there any way of picking up where I left off so these 1000 people will not receive the same mail again (and unsubscribe). And if not, would there be any way to export the simplenews log in a way where you can easily edit the adresses that were begint a newsletter and make a temporary list?

Update; my question comes down to whether a log of the actual successful (or failed) email adressess is accessible. I've looked into the watchdog table and queried `SELECT messages FROM watchdog`. This gave me a list where the column that's supposed to contain the 'To:' addresses, actually contains a wildcard. So instead of the value being an actual email adres, the value is `%To`.

Yet, on the site, I could go to `admin/reports/dblog` and would be able to filter `simplenews`. This way I can consult emailadresses that have been sent, but I would have to click each rown over 1.000 times and then copy/paste the email adres in excel or plain text to create a new list for the remaining addresses? I hope there is a way that I can link these wildcards with their actual address and then be able to export it into something that I can use to bulk operate?

# Answer
> 0 votes
To avoid automated spam testing, most hosting companies avoid reporting back on failed sending. If you somehow know who got and email and who didn't, you could suspend or remove subscription for those who did, send email again and after that re-enable users. That's pretty universal method, works for any mass sending mechanism.

If you don't know who got your email and who didn't, only raw number, you have a problem that's unsolvable.

For the future, Drupal integrates pretty well with some paid mail sending services. That's a solution for sending large amount of mail and keeping page on shared hosting. If you want to avoid mail sending services, virtual private server shouldn't have a limit on sent mail count. Sending mails is pretty expensive in terms of cpu and memory, and it's an outdated technology, so it's only to be expected shared hostings will limit and discourage it, except for small quantities like registration confirmation etc.

---
Tags: 7, emails
---


# Question
Title: Add Block to Content but set it to appear after the node content?
I have added a block to appear in the Content region, however it appears above the content of the node for French, but below the content of the node for English - which is strange as (as far as I know) they're both the same content type and should be the exact same templates.

Although the block name (and /url) is the same as the English nodes' url so maybe that's causing some problems which causes the block to appear after the nodes' content?

Is there any way to specifically define that you want a block to appear after the nodes' content? i.e. through weighting inside the module that adds the block?

**EDIT:** I've set the weighting on the blocks admin page, it's +15 for the block and the Main Page Content is -17. I also dragged it out of that region then back (without saving) before saving but still appears above for the French node and below for the English node...

**EDIT 2:** Seems to be a problem with the cache, at least a localhost version showed same error until I cleared cache... only problem is I don't have access to clear cache directly, could I code something in the module to clear the cache?

**EDIT 3:** So I have access to clear cache now, except the block is still showing up above for the French node and below for the English node... even though in Block Structure, the block is below the Main Page Content.

# Answer
> 0 votes
So I found out that the main content block was set to show up only for English and not for French!

Weird, since by default I would have assumed that if you didn't display the main content block then you wouldn't see any content. However I suppose Drupal has a default setting which must be a much higher weighting than any block can be (so why it was always appearing after all blocks!).

I set the main content block to be shown for all languages and it works perfectly now.

# Answer
> 0 votes
Go to "Structure \>\> Block" and drop down your block to the main content.

---
Tags: 7, blocks
---


# Question
Title: Drupal error after creating new theme ,Undefined variable: hide_site_name and other similar error
I am new to drupal theme . I have created a direcory `mytheme` and added `mytheme.info` to it and copied other files from drupal's default theme directory . Now after editing the `page.tpl.php`, drupal is showing the errors below .

```
Notice: Undefined variable: hide_site_name in include() (line 99 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined variable: hide_site_name in include() (line 109 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: featured in include() (line 168 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: highlighted in include() (line 187 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: sidebar_second in include() (line 212 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: triptych_first in include() (line 220 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: triptych_middle in include() (line 220 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: triptych_last in include() (line 220 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: footer_firstcolumn in include() (line 230 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: footer_secondcolumn in include() (line 230 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: footer_thirdcolumn in include() (line 230 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: footer_fourthcolumn in include() (line 230 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).

```

After searching on google, I have found that clearing cache will solve the problem . But even after clearing my cache,it remains the same !

# Answer
> 2 votes
It looks like you copied the Bartik theme and put inside your "mytheme". Do you create new theme or just create theme base on the Bartik theme? If you want to create the subtheme base on Bartik theme. Please add the default regions in your new mytheme.info like from link : Problems creating Bartik sub-theme

You may also check the tutorial from How to Customize Bartik. It's the nice tutorial for creating subtheme base on Bartik theme.

---
Tags: theming
---


# Question
Title: Create a view which shows related staff members based on taxonomy
I wish to show relevant staff members when users a viewing a particular page. For example when certain pages about membership are being viewed i wish to show the staff members designated as a 'Member Relations Officer'. I have a taxonomy called 'selected job roles', in which 'Member Relations Officer' is a taxonomy term. At the moment I have set up the staff members as users on the site, therefore they are not a distinct content type. I have added a 'selected job roles' term reference to the user fields within Account Settings.

I also added the 'selected job roles' term reference to the basic page content type. I have created a view block called 'selected job roles' in which I am trying (and failing) to set up a contextual filter correctly to show the staff members. I have a basic page with 'selected job roles' set as 'Member Relations Officer' and also a user with 'selected job roles' set as 'Member Relations Officer'. I have been trying to get it to work by doing things like setting up the contextual filter get the 'taxonomy term from url' when the 'Filter Value is not available'. However none of the contextual filter settings i have tried work.

Could somebody please advise me what settings i should using in the contextual filter? Was setting up the staff as users a mistake that is stopping this from working properly? Thank you in advance.

# Answer
> 1 votes
I have now got this to work! While I don't fully understand what is going on I thought I'd share it here in case it helps somebody else.

I created a content type 'staff profile' to work with rather than using users. The staff profile content type has the field 'selected job roles' added to it.

In views I made a new view with a display of block. I added a new contextual filter for 'Content: Nid' and set 'when filter is not available' to 'provide default value' and selected the 'content ID from URL' for the type.

Then I added three relationships.

The first was 'Content: Taxonomy terms on node', selecting my vocabulary 'Selected Job Roles' and ticked the 'require this relationship' checkbox.

The second relationship I added was '(term) Taxonomy term: Content using Selected Job Roles' and ticked the 'require this relationship' checkbox.

The third and final relationship I added was the field itself '(field\_selected\_job\_roles) Field: Selected Job Roles'.

I then added a filter criteria 'Content: Type (=Staff Member Profile)' so that only staff member profiles would be displayed.

Now, having done all of this i clicked on the contextual filter for 'Content: Nid' that I set up earlier. I think that because of the relationships that were added there is now an extra option here that was not there before. This new option is a Relationship drop down. I changed this from 'do not use a relationship' to 'field\_selected\_job\_roles'.

The 'auto preview' at the bottom of the page did not return any results when I added an appropriate contextual filter. However going to my test page everything was working correctly!

I would appreciate it if anyone can provide an explanation on why this works. However in the mean time I am just happy to have resolved the issue.

# Answer
> 0 votes
First you have to do this step by step.

You limit your view to the page being viewed. Set up a view of content and a contextual filter on `Content:Nid` to *Provide default value:Content ID from URL*.

Then relate the view to the Taxomony terms. Create a relationship on `Taxonomy Term:field_job_roles` and make it required.

Now relate the terms to the users. Create a second relationship on `Taxonomy term: User using Job Roles`. Set it to use the \*term from field\_job\_roles\* relationship and make it required.

This type of query tends to produce duplicates, to under *Other \> Query settings* select *Distinct*.

Now select the fields you want to display. Remove the default `Content: Title` and add the field `User: Name`.

When this view is displayed on the page it will display a list of users with the Job Roles corresponding to those of the page.

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


# Question
Title: How do I migrate my site without doing a direct DB export and site upload?
I'm in an odd situation. When I try moving my site from my dev server to my production server the whole thing blows up. I think it is something in my database, it even happens if I export the DB with all but the core modules turned off.

So what then is the best way to export my site (nodes, users, views, panels, contexts et al) to the production server then?

# Answer
> 0 votes
This is what I ended up doing:

After removing some content that wouldn't make it to the main site, I did the following:

* I manually installed all the same modules.
* I used Features to deploy the majority of my data types.
* I used Field Collection Deploy to copy my field collections over (while the entity itself can be copied via Features, the fields it contains are not!).
* I used Node export to copy over most of my nodes (there were some nodes that were not importable due to errors, this is likely part of the problem I was having).
* Recreated other user.

New site seems to be working OK.

# Answer
> 2 votes
What you should have done is remove sites/all/default/settings.php;
Now copy and rename the:
sites/all/default/default.settings.php =\> sites/all/default/settings.php

Phase 2
Migrate the database to the production server
Phase 3
Copy the drupal directory from your dev to production server
Phase 4
On the production server hit the following Your\_Domain\_Name.com/install.php follow the install instructions and set the database settings and you will be redirected to your site with config.
Phase 5
run cron to make sure eveything is running ok and update if necessary

# Answer
> 1 votes
Make sure your htaccess is set correctly, and sometimes you need to manually configure Apache AllowOverride All settings for your directories. Also try clearing the cache tables in the DB.

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


# Question
Title: How can I 'trim' the users returned by a user reference fields' autocomplete widget?
By 'trim' I mean that I want to restrict the usernames returned according to some criterion. For example, if I enter 'S' into my user reference field, I want the drop-down list to contain all usernames begining with 'S' and where, for example, the users favourite color equals 'Red'. 'Favourite color' would be a field added on to the user entity.

My first idea is to use hook\_query\_alter to add a condition clause to the relevant query in user\_reference module, but I'm not sure if this is possible. Has anyone done something like this before?

Thanks

# Answer
> 0 votes
You can use hook\_form\_alter() to provide your own autocomplete path. After that you can code it just like if you were creating brand new autocomplete field. Examples for developers module contains pretty solid autocomplete example, use it as a reference.

---
Tags: ajax, users
---


title: Limit nodes in views per group

text:
# Question
Title: Limit nodes in views per group
I'm using Group field in views. There are several events in one month. How can i limit my events. 2 events should be displayed in every month.

**July**
Event 1
Event 2
Event 3
Event 4

**August**
Event 1
Event 2

Thanks.

# Answer
> 1 votes
If you dont want to write custom code you can use the views limit group module

> This is a basic Views style plugin that allows for a limit on the number of rows displayed within a grouping field.

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


title: Spam accounts created automatically

text:
# Question
Title: Spam accounts created automatically
I need some urgent suggestion. In my live site a lot of spam users are being created every few minutes. I will install captcha and MOLLOM but I need to delete the spam users. How can I identify them and how do I prevent this from happening again?

Please advice

# Answer
> 2 votes
How to prevent it from happening you already know:

* Anti-spam tools like Mollom
* Captcha

For mass deletion, use Views to list them:

* Create a new users view (add new view, show: "Users"),
* add relationships you feel will be helpful to identify spammers, like "User: Content authored".
* add filters based on these relationships, like
    + Created unreasonably high amount of content or no content at all,
    + only users with account younger than the spam wave,
    + et cetera;
* use VBO to actually delete unwanted ones \- just check them, or use select all and uncheck good guys. Of course good filters will reduce number of good gu

---
Tags: 7, performance, captcha
---


# Question
Title: How can I disable the "Text format" pull-down for users that are creating or editing content?
Since the "Plain Text" format can't be deleted (within /admin/config/content/formats) the Text format pull-down will always contain it plus the default format that you would like for the user to use (i.e. Full HTML) when creating content.

When the user creates content (i.e. /node/add/article) I would like the "Text format" pull-down to be disabled so that they can't change it for non-administrators.

How can I disable the "Text format" pull-down for users that are creating or editing content?

# Answer
> 0 votes
I ended up getting rid of the text format pull-down by using hook\_form\_alter:

function workbench\_moderation\_custom\_form\_alter(&$form, &$form\_state, $form\_id) { if (isset($form\['type'\]\['#value'\]) && $form\['type'\]\['#value'\] . '\_node\_form' == $form\_id) { drupal\_add\_js('jQuery().ready(function(){jQuery(".filter-wrapper").hide();});', 'inline'); } }

# Answer
> 0 votes
The absolute easiest way would be to hide the selection using CSS.

I only say this because there's nothing "bad" that can happen if someone does use the plain text format.

Otherwise you're looking at assigning custom permissions and probably using hook\_form\_alter() which just seems like it's more trouble than it's worth!

```
.filter-wrapper { display: none; }

```

---
Tags: nodes
---


title: Email field anonymizer

text:
# Question
Title: Email field anonymizer
I want to allow anonymous users to create nodes, and their email address (entered by them into a field) will show on the node view as 'anonymized'.

The idea is that anyone can enter an email address, and the page will show an email address that looks something like "siouent-12393@this-site.com", which automatically forwards to the actual person's email.

Are there any modules for doing this? I have seen something about tokens for the email field, but I think that is not the right direction.

Does this require some deeper server system?

# Answer
You are looking to integrate your MTA's (mail transfer agent = mail server's) virtual user table with something that can be managed through code running through Drupal. There are multiple ways to do that and the exact mechanics will depend heavily on the particular MTA you are using, but the general idea will be the same. As for specific instructions for your particular MTA, I'd try Google or ServerFault.

That said, if I can be allowed to use Postfix as an example, what you are looking for seems to be configured primarily through the `virtual_mailbox_maps` configuration setting. Official documentation, Postfix and MySQL howto, quick guide to get you started and Virtual mailhosting guide with Postfix on Gentoo.

Once the MTA looks to a database table for address translation, adding a forwarding address becomes a simple `INSERT` SQL query with appropriate values. If everything is set up correctly it should then take the e-mail that was received and redirect it to the user's real e-mail address.

Oh, and one more thing; make very sure you properly validate the user's provided e-mail address, so you don't become a source of spam for others. Send them a short e-mail with either a link to click on or a code that needs to be entered to activate the forwarder.
> 2 votes

---
Tags: emails
---


title: Number of item in cart at theme level

text:
# Question
Title: Number of item in cart at theme level
I have to display number of item in cart/basket in design where I can't use the menu. So my question is...how to access number of item of cart at theme level?

Is there any function for template file which can return me this, so that I can show it in page.tpl.php ?

# Answer
You can use `commerce_cart_order_load()` to load the order for the current user, and an `EntityMetadataWrapper` to extract the relevant field data, and `commerce_line_items_quantity()` to get at the actual quantities. e.g.

```
if ($order = commerce_cart_order_load($GLOBALS['user']->uid)) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $quantity = commerce_line_items_quantity($order_wrapper->commerce_line_items);

  // Do something with $quantity...
}

```

This code can be used in a module or theme.
> 3 votes

---
Tags: 7, theming, commerce
---


title: drupal get node revision by timestamp

text:
# Question
Title: drupal get node revision by timestamp
I'm building a module that gets the value of a custom field based on a timestamp that a user clicked on it in the past.

To not make it too specific and complex I simplified my question so other users can use this as well.

Basically I'm selecting from the pop\_links\_stats ( has the timestamp ), node, node\_revision, and field\_revision\_field\_custom tables:

```
$query2 = db_select('pop_links_stats', 'p');
$query2->join('node', 'n', 'n.nid = p.nid');
$query2->join('node_revision', 'nr', 'nr.nid = n.nid');
$query2->join('field_revision_field_custom', 'f', 'nr.vid = f.revision_id');

```

I already have the $nid so I set the condition to that $nid

```
$query2->condition('n.nid', $node->nid);

```

grouping by so it will only select one 'click' per day, per node, per ip ( added the following for the completeness. I need this but it is somewhat unrelated to my question so ignore the groupBy if this is not causing any problems. )

```
$query2->groupBy('DATE(FROM_UNIXTIME(p.timestamp))')->groupBy('n.nid')->groupBy('p.hostname');

```

selecting the fields I need ( for now just the revision id) :

```
$query2->fields('nr', array('vid'));

```

So my guess is to `join the node_revision table and selecting the max vid where nr.timestamp <= p.timestamp and n.nid = nr.nid` OR `'selecting' the max nr.timestamp where nr.timestamp <= p.timestamp`

But I'm having trouble implementing that in the drupal DB API

EDIT:

Here's a query I've used in mySQL which gives me the result I want:

```
SELECT p.cid, FROM_UNIXTIME(p.timestamp), FROM_UNIXTIME(nrev.timestamp), n.nid, nrev.vid FROM pop_links_stats p
JOIN node n ON n.nid = p.nid
JOIN node_revision nrev ON nrev.vid = (SELECT max(vid) FROM node_revision nr WHERE nr.nid = p.nid AND nr.timestamp <= p.timestamp )
GROUP BY DATE(FROM_UNIXTIME(p.timestamp)), p.nid, p.hostname

```

So what I'm looking for is how to make the join in:

```
JOIN node_revision nrev ON nrev.vid = (SELECT max(vid) FROM node_revision nr WHERE nr.nid = p.nid AND nr.timestamp <= p.timestamp )

```

# Answer
There doesn't seem to be a structured way to shoehorn an advanced join like that into an API query...so you'll probably just have to go manually:

```
$query = db_select('pop_links_stats', 'p')
  ->fields('p', array('cid'))
  ->fields('n', array('nid'))
  ->fields('nrev', array('vid'))
  ->groupBy('DATE(FROM_UNIXTIME(p.timestamp))')
  ->groupBy('p.nid')
  ->groupBy('p.hostname');

$query->addExpression('FROM_UNIXTIME(p.timestamp)', 'p_timestamp');
$query->addExpression('FROM_UNIXTIME(nrev.timestamp)', 'nrev_timestamp');

$query->join('node', 'n', 'n.nid = p.nid');
$query->join('node_revision', 'nrev', 'nrev.vid = (SELECT max(vid) FROM {node_revision} nr WHERE nr.nid = p.nid AND nr.timestamp <= p.timestamp )');

```

That produces:

```
SELECT p.cid AS cid, n.nid AS nid, nrev.vid AS vid, FROM_UNIXTIME(p.timestamp) AS p_timestamp, FROM_UNIXTIME(nrev.timestamp) AS nrev_timestamp
FROM
{pop_links_stats} p
INNER JOIN {node} n ON n.nid = p.nid
INNER JOIN {node_revision} nrev ON nrev.vid = (SELECT max(vid) FROM node_revision nr WHERE nr.nid = p.nid AND nr.timestamp <= p.timestamp )
GROUP BY DATE(FROM_UNIXTIME(p.timestamp)), p.nid, p.hostname

```
> 1 votes

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


# Question
Title: How to require one of many modules in your own module?
Let's say my module needs functionality X. This functionality can be provided by two other modules. For example, front-end with two backends to store data, and at least one backend is needed for frontend to work. Is there a way in Drupal to mark it?

In GNU/Linux and BSD operating systems there usually is a marker like `provides`, for example Bison provides Yacc, and everything that would need a Yacc can work with only Bison installed. That's about what I'm looking for here.

# Answer
One option is to feature detect the modules using `function_exists()` or `class_exists()`, and then use some logic to pick the one you want.

You can also wire up a `hook_requirements()` to hard fail in the `$phase == 'install'` step or soft fail in the `$phase == 'runtime'` step.

How you handle the failures really depends on your application.
> 5 votes

---
Tags: 7
---


# Question
Title: Drupal Custom Search Results Per Content Type
So I have a View that is a list of all content on my site. I have an exposed form in a block that is "Search Terms". I have a custom template for my view to customize the results page. I have a couple of content types including "Products" and "Locations".

I'd like the Products to be displayed in a grid format with their corresponding product images and the Locations to be displayed in a list with a corresponding map. What would be the best way for me to accomplish this?

# Answer
Here's a sketch of an answer: in a views template for the result set you will have access to the original results in $view-\>result. If the view is set up for fields output, and includes all the fields required including content type, you can iterate through it 3 times, each time ignoring entries that have the content type you don't want for that case.

It's quite hard to come up with clean-looking code because of the way that views names the field data, but if you don't mind that, you can use the dpm() function of the Devel module to inspect it then code accordingly.
> 0 votes

---
Tags: views, theming
---


# Question
Title: How can I enable/disable programatically added fields from a custom module?
I'm trying to create a custom module for payment. When installed, the module automatically adds two fields to the '*Article*' content type.

I have 'enable/disable checkbox' in the form:

**Enable**: Should mean that people on my live website can use it

**Disable**: Should mean that no-one can use it (I don't want to remove the variables or the fields in the article content typ, I just want to hide everything in relation with the module)

Is there any hook or any thing that can do that? Turn the module off?

# Answer
> 0 votes
You should try `module_disable(array)` function. Here is the documentation for it. Module Disable Programmatically

You should first check its existence by `module_exists` and you can also have a look at `drupal_uninstall_modules`.

I hope this will help you.

---
Tags: 7, hooks
---


# Question
Title: How to use websolr with Apache Solr module? (D7)
I´ve got a Drupal 7 site and I would like to use apache solr.

Is there any way to connect websolr to that module? Haven´t found any module to do that (ie. as the Acquia module).

Thanks!

# Answer
> 1 votes
Apache Solr presents a generic API, and you should be able to use any search module which uses Solr with Websolr. We tend to recommend the Apache Solr Search Integration module.

---
Tags: 7, search
---


# Question
Title: How can I indicate "NEW" content in faq module after updating an entry?
I use the faq module in Drupal 7.

After I update an entry, I want to display a visual indicator (e.g. "NEW!) if the node has been changed/updated recently.

if I don't use views module.

# Answer
> 1 votes
To do this you can use the Computed Field module.

Add a field to your FAQ content type and select *Computed Field* as the type.

In the *Computed Code (PHP)* box add the following code:

```
$entity_field[0]['value'] =node_mark($entity->nid, $entity->changed);

```

In the *Display Code (PHP)* box, enter the following:

```
$display_output=theme('mark', array('type'=>$entity_field_item['value']));

```

Set the field NOT to store the value in the database.

Go to **admin/structure/types/manage/faq/display**, move your field above the answer field, set the label to *Hidden* and the display format to *Unsanitized*.

This will display either 'New' or 'Updated' as the case may be for the FAQ page, just as it is displayed on the content list..

---
Tags: 7
---


title: Get the TID from taxonomy view

text:
# Question
Title: Get the TID from taxonomy view
I am using one of the packaged views that comes with the Views module titled 'Taxonomy term' to handle what product looks like when someone searches the taxonomy. Is there a way to grab the tid of the term being viewed from the theme page or node template file?

Edit: Maybe I should explain what I am trying to do. I have a couple of selectmenu (also created by views) that get the terms from a certain taxonomy grouping. When a user selects an option, it takes them to the Taxonomy term view. I need to be able to grab the tid so that I can make a new select menu out of the choice they made.

Application: Let's say a I have a bunch of products in a number of brands. Someone picks a brand. I need a new select menu created for all the product in that brand.

If there is a way to do this in views, that's fine, but if i had the tid, I could just make a module or a function that creates the select menu.

# Answer
It seems you are looking for Hierarchical Select module.
> 0 votes

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


# Question
Title: content type showing as link but not in "node_type" table
In the development of a Drupal7 site, I have used various methods of creating profiles for customers of the site. One of the methods involved using a rule to create content for user who creates an account.

Unfortunately, this method did not work out, so the plan changed. At this point, the content type that was created by the rule cannot be removed and is showing up in the list of options for creating content, but is not in the node\_type table in the MySQL database. I cannot seem to be able to remove this content type from showing up on such list.

The content type is not showing up under the content types administration interface, but it is showing under the add content list given to users who want to add content.

What methods can i take to manually remove a content type from the list of options given to a user in creating content?

# Answer
> 3 votes
Found the resolution on drupal.org

One comment explains how to "reset" the content type from the navigation menu.

> This fixed the problem! What I did:

* Go to the navigation page, admin/structure/menu/manage/navigation
* find the link to the content type that is no longer there. It should be in the list under "add content".
* To the right there's buttons to edit and reset the link. You want to reset. This forces Drupal to reevaluate the link.
* It refreshes and poof! Gone from navigation, from add content page as well.

---
Tags: nodes, rules, database
---


title: add user to role

text:
# Question
Title: add user to role
i'm trying to create custom drupal 7 module , i'm using 'user\_roles()' function to get all the roles in the system , and then i assign those roles to checkboxes API Form Control

```
  $form['roles_group'] = array(
  '#type' => 'checkboxes',
  '#options' => drupal_map_assoc(user_roles()),
  '#default_value' => isset($field['roles_group']) ? $field['roles_group'] : '',
  '#required' => TRUE
);

```

in the display mode i'm getting a list of checkboxes like this :

```
<input type="checkbox" id="edit-mtc-roles-utilisateur-anonyme" name="mtc_roles[utilisateur anonyme]" value="utilisateur anonyme" class="form-checkbox">

```

in the :

```
name="mtc_roles[utilisateur anonyme]"

```

the system automatically put the human readable name in the 'Name' attribute of the inputs

and that's makes me wonder if there is a drupal 7 function that can assign a role by the 'human readable name' to a specific user , or do i have to fix attr '#options' in the form checkbox API

> PS : the same issue with the content types

thanks in advance ^^

# Answer
> 4 votes
Actually you do not assign the user to a role, but the reverse. You assign the role to the user.

First use the following to load the role using the plain langauge role name:

```
$new_role = user_role_load_by_name($role_name);

```

This loads the role object.

Then load the specific user using their user id:

```
$account = user_load($uid);

```

Then update the roles as follows:

```
$account->roles[$new_role->rid] = $new_role->name;

```

And save the user:

```
user_save($account);

```

This will add the role to the specified user.

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


# Question
Title: Comment pagers in D7: They appear even when the page has only 1 comment!
I have this Drupal 7 site (updated from my D6 site). I have nodetypes wich allows comments. I have the pager for comments at the very end of the comment lists that shows (as you can imagine) the complete pager: \<\< 1 2 3 4 ... \>\>

The thing is that the max comments allowed per page is 50, and even in nodes that have 1 or 2 comments the complete pager appears!

How can I prevent that from happening?

Thanks!!

# Answer
After researching for quite some time, I´ve found this reply in the Omega issue queue that gave me the answer. Even when the answer has nothing to do with the theme layer.

**In short:** When this happens to you, it´s probably because the pager is conflicting with a views block with it´s own pager activated, all in the same page.

**You actually fix this** by giving the Views pager a different value than the default zero.

Posted it here just in case anyone encounters with this issue again!

Cheers,

Rosamunda
> 8 votes

# Answer
This is not standard Drupal 7 behaviour. To me it sounds like it is some code in your theme that is causing this or perhaps a module. Try changing theme to see if the pager disappears. If the pager disappears look inside template.php for a implementation of theme\_pager().
> 2 votes

# Answer
I just ran into this same problem on my content pages. After reading this I remembered that I had created a new block view for recent comments. Going to that view and changing the Pager ID field in the pager settings to something higher than the default of 0 (I entered 100) - fixed the issue. I wasn't even using that recent comments view on the page.

There is this note in the pager settings for the view:

Unless you're experiencing problems with pagers related to this view, you should leave this at 0. If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible.

Thanks!
> 2 votes

---
Tags: 7, comments, paging
---


# Question
Title: How to displayed fixed menus, extracted from the main menu?
I am using a Bartik subtheme, and would like to split the main menu into 4 smaller menus, and display them in the four footer columns, side by side. I would like the same menus to be displayed on all pages.

How would I do this?

# Answer
If you go to `admin/structure/menu/add` and add four menus (Footer 1, Footer 2 ...), four blocks of the same name will also be created. Then go to your Main Menu and move the links into the new menus you have created.

Place these blocks where you want them at `admin/structure/block` and modify your stylesheets to make sure they display the way you want.
> 1 votes

---
Tags: theming, routes
---


# Question
Title: How to check the stock count of an ubercart node
I'm using a using a custom function to display child nodes of a taxonomy term while displaying the term page. Here is the function

```
function theme_name_child_terms($vid = 1) {
  if(arg(0) == 'taxonomy' && arg(1) == 'term') {
    $children = taxonomy_get_children(arg(2), $vid);
      if(!$children) {
        $custom_parent = taxonomy_get_parents(arg(2));
          $parent_tree = array();
          foreach ($custom_parent as $custom_child => $key) {
            $parent_tree = taxonomy_get_tree($vid, $key->tid);
          }
          $children = $parent_tree;
      }

    $output = '<ul>';
    // Avoid unnecessary "Invalid foreach" errors showing up in the log:
    if (!empty($children)) {
        // If not empty, run the foreach loop:
        foreach ($children as $term) {
            // Then check to see if any nodes exist for that term id:
            $number_of_nodes = taxonomy_term_count_nodes($term->tid);
            // If there ARE nodes...
            if ($number_of_nodes > 0) {
              // ... then add them to the output:
              $output .= '<li>';
              $output .= l($term->name . ' (' . $number_of_nodes . ')', 'taxonomy/term/' . $term->tid);
              $output .= '</li>';
              }
        }
    }
    $output .= '</ul>';

    return $output;
  }
}

```

This is the output: screen shot. You can can see that it's showing terms and node counts in brackets for items that are not in the 'jewellery' catalogue anymore as they are sold.

The problem I have is that the nodes i'm dealing with are products in an ubercart catalogue - - all items are unique as it's an antique trading site. The function above still counts 'sold' items as nodes associated with the term - a sold item is of course still tagged with a taxonomy term . - so, some terms are leading to blank pages, because I filter out nodes that are sold, from the taxonomy view.

Can another step be added to the function that checks each node associated with a term if it is a has stock level of 1 or above?

I've found the following function in uc\_stock.module:

```
/**
 * Get the stock level of a particular product SKU.
 *
 * @param $sku
 *   The Ubercart product SKU of the stock level to return.
 * @return:
 *   The SKU's stock level, or FALSE if not active.
 */
function uc_stock_level($sku) {
  $stock = db_fetch_object(db_query("SELECT active, stock FROM {uc_product_stock} WHERE sku = '%s'", $sku));

  if ($stock && $stock->active) {
    return $stock->stock;
  }

  return FALSE;
}

```

I just can't figure out where or how to call this function in the original function. It needs to be passed the product 'sku', but i'm not sure how to give it that parameter. I guess it should be something like:

```
$stock = uc_stock_level($sku);
  if ($stock > 0) {
    ...
  }

```

Any help much appreciated.

# Answer
Note: here's a good page to have bookmarked when you use Ubercart with D6: http://www.ubercart.org/docs/api (as opposed to http://api.ubercart.me for when you use D7).

Also note: this ended up being a lot more in-depth than I anticipated, but I was already knee-deep in it so I figured I'd finish it up. ;) That said...

---

You're definitely on the right track... Like you said, you could just supply the function `uc_stock_level($sku)` with the value of `$sku`, but that might be a lot of SKUs and therefore kind of resource intensive.

Another alternative that should work would be something like this:

Change this part of your code:

```
$output = '<ul>';
// Avoid unnecessary "Invalid foreach" errors showing up in the log:
if (!empty($children)) {
    // If not empty, run the foreach loop:
    foreach ($children as $term) {
        // Then check to see if any nodes exist for that term id:
        $number_of_nodes = taxonomy_term_count_nodes($term->tid);
        // If there ARE nodes...
        if ($number_of_nodes > 0) {
          // ... then add them to the output:
          $output .= '<li>';
          $output .= l($term->name . ' (' . $number_of_nodes . ')', 'taxonomy/term/' . $term->tid);
          $output .= '</li>';
          }
    }
}
$output .= '</ul>';

```

To something like this:

```
$output = '<ul>';
// Avoid unnecessary "Invalid foreach" errors showing up in the log:
if (!empty($children)) {
  // If not empty, run the foreach loop:
  foreach ($children as $term) {
    // Then check to see if any nodes exist for that term id:
    $number_of_nodes = taxonomy_term_count_nodes($term->tid);
    // And then check to see what the current stock level is:
    $stock_level = fetch_stock_level_from_termid($term->tid);
    // If there ARE nodes...
    if ($number_of_nodes > 0) {
      // And if the product is in stock...
      if ($stock_level > 0) {
        // ... then add them to the output:
        $output .= '<li>';
        $output .= l($term->name . ' (' . $number_of_nodes . ')', 'taxonomy/term/' . $term->tid);
        $output .= '</li>';
      }
    }
  }
}
$output .= '</ul>';

```

You'll then need to add the function `fetch_stock_level_from_termid()` to your code as well:

```
function fetch_stock_level_from_termid($term_id) {
  $sql = "SELECT SUM( {uc_product_stock}.stock ) AS stock
          FROM {uc_product_stock}
          INNER JOIN {node} ON {uc_product_stock}.nid = {node}.nid
          INNER JOIN {term_node} ON {node}.vid = {term_node}.vid
          WHERE {term_node}.tid = %d
          AND {node}.status = 1";
  $stock_available = db_result(db_query($sql, $term_id));
  return $stock_available;
}

```

Hope that helps... :)
> 1 votes

---
Tags: ubercart
---


# Question
Title: How do I programatically add a field to a node?
I'm trying to create custom Drupal 7 module. In the form setting for the module I have checkboxes where the admin can select multiple content types:

After installing the module I need to automatically create two fields (Price of type decimal (4,2), and currency of type text) only in the 'content types' the admin has selected from the list above.

And this is how I set the content type to the checkboxes list in the `mymodule_payment_admin_settings_form` hook in `mymodule.module`:

```
 $form['test_content_types'] = array(
      '#type' => 'checkboxes',
      '#options' => drupal_map_assoc(node_type_get_names()),
      '#default_value' => variable_get('test_content_types'),
      '#required' => TRUE
    );

```

# Answer
> 1 votes
You need your own form ideally, right now you have a `system_settings_form`. That's typically for only setting `variables` and really simple stuff like that. see the documentation on system\_settings\_forms.

Instead you probably want to create and use a custom menu callback (you've already done that) which has a callback to a custom form you've defined. See the general drupal FAPI guide.

With your own form you create a submit callback. In that callback you take the selected node types and just create and assign **instances of drupal fields** to them. So you have to do 2 things: 1) create the fields, 2) assign them to the content types (entity bundles).

The form submit callback could look like this (not 100% tested code, fill in the blanks, add validation, etc):

```
function mymodule_form_submit($form, &$form_state) {
  if (!field_info_field('field_price')) {
    # Create field singleton
    $field = array('field_name' => 'field_price', 'type' => 'number_decimal',);
    $field = field_create_field($field);
  }
  if (!field_info_field('field_price')) {
    # Create field singleton
    $field2 = array('field_name' => 'field_type_of_currency', 'type' => 'option',);
    $field2 = field_create_field($field2);
  }

  foreach ($form_state['values']['content_type'] as $machine_id => $machine_name) {
    # Create instance on bundle.
    $instance['field_price'] = array(
      'field_name' => $field['field_name'],
      'entity_type' => 'node',
      'bundle' => $machine_id,
      'label' => 'Price',
      'description' => 'The price of an item.',
      'required' => FALSE,
      'settings' => array(),
      'widget' => array(
        'type' => 'textfield',
      ),
      'display' => array(
        'default' => array('label' => 'hidden'),
      ),
    );
    // ... same instance code for currancy type field instance.
    // $instance['field_currency_type'] = ...;

    foreach ($instance as $instance_field){
      field_create_instance($instance_field);
    }
  }
}

```

---
Tags: 7, nodes, entities
---


# Question
Title: Displaying top visited links from other content types in one (filtering)
I have made one block for most visited links (Top Links) in my Drupal website, but I don't know how to list most visited from different pages. For example, if I have created a page named "Drupal" and within that page I have added some content with some title, then I have to examine and count those titles and list the top visited title from each and every page on my homepage (only one from each and every title that is most visited) and list them on my homepage block.

Could anyone help me with this.

# Answer
If you want to use views check this answer.

There is Drupal Most Popular module

> Showcase the most popular content across your Drupal website and engage your audience.

Documentation

Also there is Radioactivity module.

> This module provides a field type which can be used as a hotness metric or a regular view counter for entities and for much much more. In essense, entities receiving attention (views or actions defined by Rules) are heated while inactive ones slowly cool down.
> 0 votes

---
Tags: views
---


title: Transfer money between users?

text:
# Question
Title: Transfer money between users?
Is there a way with Drupal to transfer money between users? Im making a skill sharing website, so users can buy and sell their skills. Thanks

# Answer
I think the Ubercart funds module that is the best answer for your question; the module still has a development snapshot only, though.

This will make you able to transfer funds through your drupal sites to different users.

> Ubercart Funds implements a Site Funds Management System using Ubercart, It integrates features like Deposit Funds, Withdraw Funds, Transfer Funds..etc, which makes implementing most features of a Money site like Paypal or Skrill possible and easy using Drupal.
> 0 votes

# Answer
Was just looking into this myself and came across Commerce Funds.

> Commerce Funds implements a Site Funds Management System using Drupal Commerce, It integrates features like Deposit Funds, Withdraw Funds, Transfer Funds..etc, which makes implementing most features of a Money site like Paypal or Skrill possible and easy using Drupal.
> 0 votes

---
Tags: 7, commerce
---


# Question
Title: cannot see tabs for manage fields etc with administrative toolbars add content bar
This must be something new because never seen it before now. There is a grey bar with the add content find content and edit shortcuts links on it which completely obscure the tabs for manage field etc in content types.

How can I keep the administration toolbar but remove that grey bar? AND WHY would anyone want it placed in such a way as to block out important regularly used tabs?

# Answer
It's an incompatibility between administration toolbar and your theme, and maybe overlay if you are using it. No one placed it like that on purpose, it's just a clash between 3 sets of CSS each written without knowing how other will look.

You can try one or many of the following:

* Use Administration menu instead of toolbar.
* Use Shiny as admin theme
* Toggle overlay - if it's on, maybe without it it'll be OK? If it's off, maybe it'll help?
* Create a subtheme and deliver CSS that will position stuff the way it should be for your particular case. Firebug or Chrome are good for fast prototyping your fix.
> 1 votes

---
Tags: toolbar
---


# Question
Title: increase users to display in who is new block
I need to display more than 10 users in who is new block, i see the dropdown list has at max 10.

So, how can I increase it?

# Answer
> 0 votes
You have two options I see:

* Recreate this block with Views \- changes like that are the very sense of their existence.
* Create custom module with hook\_form\_alter() and add numbers up to some arbitrary max you prefer. Note that it might be a performance hit that way, if block in question loads full user objects. To much and you'll eat your memory.

---
Tags: 7, blocks
---


title: Ajax based commenting system

text:
# Question
Title: Ajax based commenting system
In Drupal 7 I'm facing one problem, I'm going to implement a *comment system* in that way that it should work as *chatting systems*. I've a content type *Article*, at the end there is a *comment box* where users can leave comments.

If I add a comment to the article it should be showed in every user's browser if they are viewing it, and at the same time they can *debate/talk* about that article without refreshing the page.

It will be real time commenting.

# Answer
We have solved this issue with two modules

1. **Ajax Comments**

> Provides ajax comments to Drupal sites (commenting like a social networking sites: Facebook, Google+, vk.com etc).

2. **Block Refresh**

> Block Refresh allows an administrator to configure a block to refresh it's content via 3 different methods: automatically via a timer (eg every 30 seconds) , manually via a 'refresh' link, and once on page load.

You can view the real sample at http://beinghuman.org/.
> 4 votes

# Answer
The Ajax Comments module *AJAXifies comments* \- works well and no need to refresh page.

**Ajax Comments**

> Provides ajax comments to Drupal sites (commenting like a social networking sites: Facebook, Google+, vk.com etc).
> 2 votes

# Answer
There is a patch in ajax comments module to allow for time-based refreshing, but it is not yet committed: https://drupal.org/node/401288

That would allow the usage of just one module alone to achieve the desired functionality.

I wander how you embedded the comments in the block, as I tried both commentsblock and node\_comment\_block but then they both didn't refresh using block\_refresh.
> 0 votes

---
Tags: 7, ajax, comments
---


# Question
Title: Is Menu-minipanels reliable to make a mega menu
I'm going to implement a mega menu in my site and am considering the Menu Minipanels module...

Has anyone tried it? Did you find it easy to use/customize?

What about performance? Panels is often quite a heavy module.

# Answer
Menu Minipanels looks like a good choice.

An alternative you might want to try for a simple 'mega menu' is the Mega Menus module. Worked well for me, once I had my settings and CSS sorted out. See also this answer for lots more mega menu options...

Finally, regarding performance, since Menu Minipanels uses Panels you will have full control over caching of individual panes within it. The performance burden can therefore be significantly reduced.
> 1 votes

# Answer
There's a new mega menu module called TB Mega Menu which I found pretty helpful and extremely easy to use. Its got a friendly user interface (WYSIWYG) along with some nice features such as synchronized with Drupal core menu, nice design, built on Twitter Bootstrap, responsive...
> 0 votes

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


# Question
Title: How do I enable anonymous users to vote?
I created a poll, and I am displaying it in a block on my site. The radio buttons are available, when I am logged in; when I log out, they aren't showing, and the vote results are instead displayed.

How do I enable the anonymous users to vote?

# Answer
> 4 votes
Looks like you need to enable the permission for anonymous users and also

Drupal core poll module only allows one vote per anonymous IP address. check this link https://drupal.org/node/866168

The Poll Enhancements Module modifies this behavior to allow multiple anonymous votes from the same IP address.

> This module enables anonymous users to vote on polls without page cache troubles or IP address restrictions. It is designed to work on top of core Poll module.

---
Tags: 7, polls
---


# Question
Title: What are the changes I should make to the .htaccess file to enable clean URLs?
What actually are the steps to clean the URL of a site.

I have made the following changes in the /etc/apache2/sites-enabled/000-default file.

```
<VirtualHost *:80>

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

```

What are the changes I need to do in a .htaccess file so that I could enable clean URLs?

# Answer
You do not need to do any edits in the Drupal default `.htaccess` file to have *Drupal 7* enable clean URLs. Instead, navigate to *Home » Administration » Configuration » Search and metadata* (its the link named "Clean URLs" on the Admin's Configuration page, and press the button "Run the clean URL test".

If the test is successful, Drupal will make use of its default `.htaccess` to do the rewrites. If the test fails, then you need to review your configuration.

Some suggestions:

Make sure that the Drupal default `.htaccess` is present in your webroot (`/var/www`).

Make sure that you've actually enabled `mod_rewrite` for Apache, e.g.:

```
 sudo a2enmod rewrite

```

You must also restart Apache after changing defaults, e.g.:

```
 sudo service apache2 restart

```

(The example shell commands above are for Ubuntu. If you run a different dialect of GNU/Linux, you may need to use slightly different shell commands.)
> 4 votes

# Answer
Seems like you don't have the default `.htaccess` file present in you Drupal root directory. You can try this

1. Download the fresh copy of Drupal.
2. Copy the `.htaccess` file, from the newly downloaded Drupal tarball to your sites root directory.
3. Run the test again.
> 0 votes

---
Tags: 7, uri
---


# Question
Title: Adding menu with description like mega menu
I would like to create a menu with a description of the menu like megamenu. My menu looks like the following model:

How can I create this?

# Answer
You could try Ultimenu

> Ultimenu is the UltimatelyDeadSimple™ megamenu ever with dynamic region creation.
>
> An Ultimenu block is based on a menu. Ultimenu regions are based on the menu items. The result is a block contains regions containing blocks, as opposed to: a region contains blocks.

Screenshot

**Usage:**

1. Enable or install the module.
2. Visit admin/structure/ultimenu to manage the Ultimenu blocks, regions, a skin library and a few goodies.
3. Once a menu is enabled, dynamic regions will be available to toggle. Only enabled regions (based on enabled menu items) will be visible at block/ context admin.
4. Visit admin/structure/block to assign the "Ultimenu: Menu name" block into header, sidebar, footer or navigation region, except Ultimenu regions.
5. Add other blocks to the Ultimenu regions.
> 1 votes

# Answer
You can try TB Mega Menu, it's got very nice user interface (WYSIWYG) and also multiple built-in styles.

http://drupal.org/project/tb\_megamenu
> 2 votes

# Answer
You can use OM Maximenu to add description or block or menu inside menu.its quite simple and best to add like your design

http://drupal.org/project/om\_maximenu
> 1 votes

---
Tags: 7, routes
---


# Question
Title: One path alias for differents / multiple internal path?
The problem is when a menu item points to a restricted page, the anonymous user can't see the menu link.

So I was looking for a way to setup a path alias so it would point to two internal path =\> one for anonymous and one for logged users.

Is this solution possible? Do you see another way to show restricted menu item to guests ?

# Answer
You cannot have one alias for two items. That's not how router works. On the other side, you can create a page only guests will have permission to see, and place it under the same name in the same menu. Then both guests and logged in users will see identical menu, but they will actually get different set of menu items.

If that's not enough, you can use Menu per Role to get more control of who sees what in your menus.
> 3 votes

# Answer
If you want to display a menu item for a page that the user does not have access to, the easiest way is to enter the full URL into the menu item rather than the path. Drupal doesn't check such items for access. The only downside is that the URL won't be automatically maintained by Drupal, so it won't work across domains for example.
> 1 votes

---
Tags: 7, routes, users, navigation
---