# Question
Title: How can you sort taxonomy terms based on number of times used, in a view?
I'm creating a view that lists the top 10 most popular taxonomy terms (tags). Currently I have the view returning all the terms and I can limit the view to 10 but I can't work out how to order the terms by popularity (i.e. number of times used across all nodes).

Anyone have experience of this?

# Answer
In the end I created my own custom module to get the terms from the database and group/sort them.

Please note that I've modified the code below slightly for posting and I've not tested the modified version. It's also worth noting that it was written for a site using PostgreSQL, but it should work with MySQL.

```
/**
  * Implements hook_block_info().
  */
function MYMODULE_block_info() {

  $blocks['poptags'] = array(
    'info' => t('Most Popular Tags'),
    'cache' => DRUPAL_NO_CACHE
  );

  return $blocks;
}

/**
  * Implements hook_block_view().
  */
function MYMODULE_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'poptags':
      $block['subject'] = t('Most Popular Tags');
      $block['content'] = _MYMODULE_popular_terms();
      break;
  }
  return $block;
}

function _MYMODULE_popular_terms() {

    $vocabId = 1;

    $links = array();
    $results = db_query_range('SELECT taxonomy_term_data.tid, taxonomy_term_data.name, count(taxonomy_term_data.tid) AS times_used FROM taxonomy_term_data INNER JOIN taxonomy_index ON taxonomy_term_data.tid = taxonomy_index.tid WHERE taxonomy_term_data.vid = :vid GROUP BY taxonomy_term_data.tid, taxonomy_term_data.name ORDER BY times_used DESC', 0, 10, array(':vid' => $vocabId));
    foreach ($results as $term) {
        $links['term-link-' . db_escape_field($term->name)] = array('title' => $term->name, 'href' => drupal_get_path_alias('taxonomy/term/' . $term->tid));
    }

    return theme('links', array('links' => $links, 'attributes' => array('class' => 'term-links')));
}

```

Don't forget to change `MYMODULE` for the name of your module. Lastly change the `$vocabId = 1` line in the `_MYMODULE_popular_terms` function to the vid (vocabulary id) of the vocabulary that you want to list the terms of.

Note this is for Drupal 7 only, though it would not take much to port it to Drupal 6.
> 0 votes

# Answer
1. Create a new view
2. limit to taxonomies "show taxonomies of term all"
3. Add a relationship "Taxonomy term: Content with term"
4. Use aggregation
5. Add field "Content: Title"
6. Aggregation type "Count"
7. Change label to something like "number of times used"
8. Add Sort criteria "Content: Title"
9. Aggregation type "Count"
10. Sort to whatever you like

it should look like this:
> 9 votes

# Answer
Views 3 has a (very beta) "group by" feature; you should be able to use this and order a count field.

I wouldn't guarantee it works, but it is probably worth a try.
> 0 votes

# Answer
You could pull the data from tagadelic.

```
$output = '';
$vids = array(1, 2, 3, 4); #Taxonomy vocabulary-ids you want to be included.
$top_tags = tagadelic_get_weighted_tags($vids, 6, 10);
foreach ($terms as $term) {
  $weight = $term->weight;
  $output .= l($term->name, drupal_get_path_alias('taxonomy/term/' . $term->tid), array(
    'attributes' => array(
      'class' => array("tagadelic", "level$weight"),
      'rel' => 'tag',
      'title'  => $term->description,
      )
    )
  ) . " \n";
}

return $output;

```

The only downside is that tagadelic adds some minor overhead for calcuating the "weight", usually to present the tag sizes, which you will not not use.

The upside is that you get caching for free.
> 0 votes

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


# Question
Title: How do I import product category based on taxonomy vocabulary?
I have a products catalog based on taxonomy vocabulary, as advised the term reference field is on the product content type.

Products imports are working fine, but when I try to import product displays the mapping for term reference (Category vocabulary)does not appear in the target list.

I'm using Feeds 7.x-2.0-alpha8, Commerce Feeds 7.x-1.3, Commerce Kickstart 7.x-1.19 and Drupal Core 7.22

Thanks in advance

# Answer
> 0 votes
You probably need to add your taxonomy vocabulary field to the product display.

---
Tags: commerce, feeds
---


# Question
Title: Render content type via Form Block module using module_invoke
I am attempting to use the Form Block module so that I can place one of my content type forms in a block. I seem to be able to get to the block but I'm not sure how to render it. If I do a `print_r($block)` I see the block contents but I don't see anything to do with rendering it.

```
$block = module_invoke('formblock', 'block_view', 'csc_newsletter_subscription');

// Normally I would do something like this if it was just a block_view
$variables['newsletter_subscription_form'] = render($block['content']['#markup']);

```

And then I would be able to take the $newsletter\_subscription\_form variable and display it in my tpl file, but this does not seem to work.

What am I missing?

# Answer
You can print a Block which is generated by a module like this.

```
$block = module_invoke(<module name>, 'block', 'view', <block id>);
print $block['content'];

```

User created block

```
$block = module_invoke('block', 'block', 'view', <block id>);

```

example:

```
$block = module_invoke('block', 'block', 'view', 20);
print $block['content'];

```

In Your cas, since the forms are in blocks you can simply manage them via *exmple.com/admin/structure/block* path :)
> 2 votes

---
Tags: forms, blocks
---


title: Alter markup around a webform

text:
# Question
Title: Alter markup around a webform
I have been trying to alter the markup generated by my webform. .

Example changes which I would like to do:

* Add the class "form-horizontal" to the classes under `<form class=""/>`.
* Add the class "input-xxlarge" to each input field.
* Remove any markup generated by the webform module (e.g. form-item, webform-component, webform-component-textarea).

I've been trying to override these values with the help of Devel. Using `webform-form-[nid].tpl.php`, I have the following line before I make any print statements:

```
$form['#attributes']['class']['0'] = 'form-horizontal';

```

The issue is that I can not alter the form classes. Any insight that can be shared would be highly appreciated!

# Answer
> 1 votes
Have you tried theme\_form\_element ?

> Returns HTML for a form element.

This hook is used to alter the thme of form element in Drupal.

Check theme\_field as well.

How to theme form element in Drupal 7

---
Tags: 7, theming, webforms
---


# Question
Title: Views and Filter Criteria - is this normal behavour? Drupal 7
I decided to modify the View after all the content had been uploaded to the site. Now I am experiencing issues with the Filter Criteria, not picking up the nodes which I would expect to be picked up...

Here are the two different sets of Filter criteria I tried:

This View displays 2 search results.

The view above displays 3 results!

Now, what I was expecting is that the first set of filters would display the same number of results (at least) as the filter above. Because, the condition is OR. But that's not the case...

Is this normal behaviour?

I must not be reading the conditional statements correctly, because I am not displaying the results I am expecting...

# Answer
You have 4 boolean variables here. Let's write some pseudo-code. They are $is\_published $is\_news $is\_display\_on\_news $is\_involved

First set of your rules is:

```
( $is_published and $is_news ) and ($is_display_on_news or $is_involved)

```

Second one looks like that:

```
( $is_published and $is_news ) and ($is_involved)

```

If we remove common part, first one reduces to

```
$is_display_on_news or $is_involved

```

and second one to

```
$is_involved

```

This means in second case you are ignoring nodes with $is\_display\_on\_news set and $is\_involved not set. Thus, first view should always return no less items than the second one.

If that's not the case, you need to enable "show query" in views GUI settings, and compare it on the SQL level. Maybe SQL conditions are rendered in invalid form? Impossible to say without actual SQL query.

Sometimes when you add new field to a content type, it ends not set for old nodes. It makes inner join exclude old nodes altogether. That way you can end up not seeing old nodes when you add OR condition - new join removes them from results before or condition is ever evaluated.

And sometimes it's just cache.
> 0 votes

# Answer
I think you should change the 2nd AND statement to OR and last OR statement to AND. Looks like everything else is fine.
> 0 votes

---
Tags: views
---


# Question
Title: Knocked out my own admin recongizion on my own site
I have Drupal 6 site. In deleting spammers I accidently knocked myself out. Can I reclaim admin on my own site? Help.

# Answer
If u are able to create account,create it and in the database for the **'users'** table update **'1'** to the **'uid'** field for the account you created and if you are unable to create a account then create a account manually in the database

```
INSERT INTO users (uid, name, pass) VALUES ('1', 'yourname',> md5('yourpassword'));

```
> 3 votes

# Answer
Default method should be to backup entire page before mass operations, and then restore it in case of failure. If you cannot do it on your own, your hosting company probably have nightly backups they can restore for you if you ask them.

If that's not the case, but you can access SQL console or SQL web admin tool, see this answer.

If you can't access SQL console directly, but have file access, you can put SQL code in settings.php wrapped in db\_query(), but be *extremely* careful, as it gets executed on almost every page hit.
> 0 votes

---
Tags: 6
---


title: Page Manager URL arguments

text:
# Question
Title: Page Manager URL arguments
This seems like it should be simple, but I can't figure out how to get Page Manager and Pathauto to play nice together.

I'm trying to use Page Manager/Panels for a set of pages of a specific node type. If I use the built-in (System) "node-view" page, the URLs work fine...

`/content/nice-clean-node-title`

But if I try to create my own Pages, I'm forced to use the node id as an argument?

`/content/1`

When you get to the arguments for a URL, there is no option to use node title.

My question is... how do I create variants within Page Manager that deliver node content in different ways based on a (clean) URL...

`/content/some-node-title/overview`

`/content/some-node-title/detail`

`/content/some-node-title/specs`

etc.

Am I missing something? Or is this really difficult to achieve with Drupal?

# Answer
> 1 votes
Node titles are not unique, so they cannot be used directly. You need to create page with nice, machine-readable, numerical ID, and then assign it it's own URL Alias. Works similar in Drupal from 5 to 8 as far as I know, menu names might be a bit different, that's all.

Pathauto is nice automation for aliases, but only on nodes. There was already similar, but not identical question with some answers.

---
Tags: path-aliases, chaos-tool-suite
---


# Question
Title: Commerce discounts by day-of-week and by age
I am creating a store where users can pay for attending events at a fixed rate of £7 for each event; that's the easy part.

The hard parts are as follows:

* Every Tuesday all events are half price (£3.50)
* Students are admitted any day of the week half price
* Senior citizens are given a £1 discount every day of the week

I am investigating the Rules module as the most feasible solution, but I am not sure it will deal with all the scenarios above.

I would appreciate any advice to help me reach a working solution.

# Answer
You can use rules for first requirement. You will need to add PRODUCT PRICING rule & check the day in condition. Just multiply the base price by .5 & you can apply what you wanted.. Anther things are user role based, so if a user has role of student in condition then do the same in another PRODUCT PRICING rule.

Add one more rule for senior citizen, check their user type & apply the new price.

These will work for sure..
> 0 votes

---
Tags: 7, commerce
---


# Question
Title: How to use predefined drupal elements in a custom block/module?
This is regarding the user block but the question is general and could be related to any standard block/module: How to use in a custom block elements that have been defined in standard modules? (for example the "username" field defined in the user block) What is the way to access these elements in my code?

If the above is not clear, in other words what I would like to do is to **use** the "username" , "password" , "..." and all the elements defined in the user module, as independent elements in my custom block. And then build my own Submit which will include both standard drupal and custom items.

I think hook\_form\_alter will not do this trick because it is 1 level higher, right? i want to go one step more into details and manipulate the form items, no the form itself.

# Answer
> -1 votes
When building your own form in your module, you can simply read your defaults from $user variable. Then, in your submit function, use user\_save() function to update your user.

---
Tags: hooks, users
---


# Question
Title: How can I recalculate field values of a rendered node?
For example on a recipe node, exposing a "yield" field on a rendered node to recalculate ingredient quantity values

# Answer
> 1 votes
I dont think there is any module that you can use, you can try hook\_node\_view\_alter hook to change the rendered.

> If the module wishes to act on the rendered HTML of the node rather than the structured content array, it may use this hook to add a post\_render callback. Alternatively, it could also implement hook\_preprocess\_node(). See drupal\_render() and theme() documentation respectively for details.

Check hook\_entity\_view\_alter too

If you want to change in the node create form, there is Conditional Fields Module.

> Define dependencies between fields based on their states and values. Conditional Fields for Drupal 7 is an user interface to the new States API, plus the ability to modify fields appearance and behavior on certain conditions when viewing content.

Installation and Usage

# Answer
> 1 votes
Computed Field module can be configured to work just the way you need:

> You can also choose whether to store your computed field values in the database with other content fields, or **have them "calculated" on the fly** during node views.

---
Tags: 7, entities
---


# Question
Title: When using Zen and Zen grids, where do I put SASS variables?
I am trying to use Zen Grids with the Zen ver. 5 starter theme.

The Zen starter theme comes with a lot of `.scss` files (in the `sass/` subdirectory). I am trying to use Zen Grids to set up a simple layout. I've read up on Sass and think I understand the concept, and I've Compass installed and working.

I've read everything on the Zen Grids website. On the front page of that website, below the promising headline: "Using Zen Grids is easy!", there is a nice introduction to Sass and Zen Grids followed by: "And here’s the complete Sass code:".

The example is strightforward enough. What I am not able to figure out is *where* (as in "in what file") you put the statements used in the example.

(My setup is a Zen sub-theme created from the Zen `STARTERKIT`, straight out of the box.)

# Answer
If you use the Zen `STARTERKIT` ver. 5, *Sass* configuration variables and *Sass* mix-ins similar to those you link to on the **Zen Grids** website is *already* in place in the file named `responsive-sidebars.scss`.

So to create a responsive design by means of **Zen Grids**, you don't add these anywhere, as they're already in place. But if you want to *change* them to other values, you do so by simply editing `responsive-sidebars.scss` in your starterkit sub-theme.

Note that most of the selectors used in the example on the **Zen Grids** website (e.g. `.aside1`) will not do anything in Zen (unless you also change the corresponding template file). You can see from `responsive-sidebars.scss` what selectors to use (e.g. `.region-sidebar-first`).
> 2 votes

# Answer
In the Zen theme structure there are several main style files: pages.scss, nodes.scss, blocks.scss, forms.scss. Depend on which part of website that you want to make styles. You have to choose the correct files for changing. In order to use the sample code in the Zen Grids . You can go to pages.scss and make changes here . Make sure that your website will generate the same HTML markup structure like the sample by creating new pages.tpl.php.
> 3 votes

---
Tags: theming
---


title: Assign text formats per user roles

text:
# Question
Title: Assign text formats per user roles
I tried to program the logic where friends\_html text format would apply to nodes saved by users with the new 'friends' role, while friends\_somik\_my\_html text format would apply to nodes saved by all 'other' users.

```
function somik_core_node_presave($node) {
  if (!empty($node->nid)) {
    // if it was unpublished update the created/changed
    if ($node->original->status==0 && $node->status==1) {
      $node->created = time();
      $node->changed = time();
    }
  }

  module_load_include('inc', 'somik_core', 'somik_core.base64_images');
  somik_core_remove_node_base64_images($node);

  // apply saved html filter
  $somik_my_html_format = filter_format_load('somik_my_html');
  $field = field_get_items('node', $node, 'body');
  if ($somik_my_html_format && !empty($field[0]['value'])) {
    $body_value = check_markup($field[0]['value'], 'somik_my_html');
    $node->body[LANGUAGE_NONE][0]['value'] = $body_value;
    $node->body[LANGUAGE_NONE][0]['safe_value'] = $body_value;
  }

  if ($node->format == 'friends_somik_my_html') {
    if (array_key_exists('others', $user->roles)) {
      // apply others saved html filter
      $friends_somik_my_html_format = filter_format_load('friends_somik_my_html');
      $field = field_get_items('node', $node, 'body');
      if ($somik_my_html_format && !empty($field[0]['value'])) {
        $body_value = check_markup($field[0]['value'], 'friends_somik_my_html');
        $node->body[LANGUAGE_NONE][0]['value'] = $body_value;
        $node->body[LANGUAGE_NONE][0]['safe_value'] = $body_value;
      }
    }
  }
}

```

# Answer
> 1 votes
The idea behind filters is that you store the raw input in the database, and sanitise it *on display*.

So really all you need to do is update the format for the body field, like so:

```
// Apply somik_my_html filter
$node->body[LANGUAGE_NONE][0]['format'] = 'somik_my_html';

```

# Answer
> 0 votes
Simply limit user roles to given format types using built-in permission system - and add put needed filters in corresponding formats, of course. It seems it can be done without a single line of code.

And if you need changes during presentation, use theme system. Just remember that it can lead to problems - if moderator sees content in different way than some users, or if author sees it different than his audience, it's an easy way for inconsistencies and artefacts.

---
Tags: hooks, users
---


title: Table format in webforms

text:
# Question
Title: Table format in webforms
I have created a customized form using the Webform module in Drupal 7, but I want to have a table with rows n columns one part of this form. I downloaded the Webform Table Element module, but there is no way to configure it or arrange the rows and columns, and mention labels as I want.

Please suggest me a step-by-step way to include a large table in webforms. How can it be managed without coding?

# Answer
> 1 votes
From your Comment "contain user entered data" i understood you need webform submitted data in Table format, If so then download and install this module Webform Report

> This module allows users to create simple, dynamic reports based on data collected by the webform module. It adds a new node type that contains the report criteria, and the data displayed is updated automatically as webforms are submitted.

See the webform report in below image, hope it helps you!!

---
Tags: webforms, theming
---


# Question
Title: Is there a Drupal tool to aggregate and compress CSS files
I know that Drupal 7 has settings for *Aggregate and compress CSS files* and *Aggregate Jacascript files* (under `Administration/Configuration/Development/Performance`).

Is there a tool that let me extract the result of this process?

I am using *Sass* and *Compass*, so I guess that to produce an aggregate and compressed `.css`, I could set `output_style = :compressed` in *Compass* and the just concatenate together all the separate `.css` files, but that won't resolve conflicts or combine overlapping CSS selectors.

I wonder if there are some better way to do this, for instance making use of the Drupal built-in tool that apperently is designed specifically for the job.

This is for a Zen sub-theme. The Zen STARTERKIT produces a lot of CSS-files, and before making this sub-theme generally available, I would like to "clean up" the distribution by consolidating CSS and Javascript into two aggregate and compact files.

(Outside the Drupal universe, YUI compressor seems to be the most popular tool for this.)

# Answer
I'm not 100% sure I'm right in thinking this, but if you're looking for something to reverse the CSS aggregation/compression, but if you are then it doesn't look like there is anything that exists that will give you exactly what was initially compressed. However, the cache Drupal creates is an array that is keyed by the original filename of the cached CSS, so you should be able to find out *WHICH* CSS files are being cached relatively easily (I think the `variable_get('drupal_css_cache_files');` will get the array for you.

If you are looking to mimic what Drupal does when it aggregates and caches your CSS, then take a look at the `drupal_build_css_cache()` function (which, as an FYI, is called by `drupal_aggregate_css()`).

As a point of interest, there is also a `drupal_build_js_cache` as you'd expect.
> 2 votes

---
Tags: theming
---


# Question
Title: Unable to import external RSS feed to site
I want to add a vertically scrolling ticker which is fed content via an external RSS feed.

```
* Modules being used: Views, Feed, CTools, Job Scheduler

* Issue 1

```

I tried setting up a static RSS feed block using Feed Module. I followed many tutorials but in the end all I could do is created 100s of content pages when importing data from feed. But I could never get a consolidated page/block where I could see the list. I created views with Page/Block/Feed but I couldn't find how to link the feed with the view.

```
* Issue 2

```

When I use the Feed Module and map the Feed, I get following errors:

```
•   Notice: Undefined index: 0 in user_node_load() (line 3605 of modules/user/user.module).
•   Notice: Trying to get property of non-object in user_node_load() (line 3605 of modules/user/user.module).
•   Notice: Undefined index: 0 in user_node_load() (line 3606 of modules/user/user.module).
•   Notice: Trying to get property of non-object in user_node_load() (line 3606 of modules/user/user.module).
•   Notice: Undefined index: 0 in user_node_load() (line 3604 of modules/user/user.module).
•   Notice: Trying to get property of non-object in user_node_load() (line 3604 of modules/user/user.module).

```

I have no clue why this error is coming up. I tried looking for existing drupal issues, but found live sites with such errors instead.

```
* Issue 3

```

I want to populate ticker with RSS content with the RSS data.

If anyone has a tried and tested link which guides step by step for importing external RSS feed for Drupal 7 (I found too many links but mostly for drupal 6), I'll be really grateful. Also, please let me know if there is any other way to do it besides Feed module \[I'm using aggregrator but I want content to be created for each RSS feed entity\].

Also, if ticker module allows to use RSS feed any guidance will be really appreciated.

'Note: Tried https://drupal.stackexchange.com/questions/21719/how-to-display-external-rss-using-feeds-module-and-views. I don't have content type Feed. Am I missing modules?'

# Answer
> 0 votes
Using Feeds. You create a feed importer with RSS syndication import (common syndication parser). if there is only one feed, in basic you don't need to attach to content type (use standalone form) and set the periodic import time. Node processor attach to bundle type (your content type to receive the nodes. Then map the feed fields to your content fields. Finally navigate to /import to see feeds listed and add the url. Nodes can be listed in views normally (from your content type - the bundle), I scroll them using views ticker

---
Tags: views, feeds, entities
---


# Question
Title: How can I have a field value that is the sum of other (decimal) field values?
I have created a custom content type with three decimal fields. I need to tally these three fields and then wrap the output of each one with a specific data attribute, stating their respective value as a percentage of the total.

Am new to drupal so if someone could point me in the right right direction as to how best achieve this it would be much appreciated.

# Answer
> 3 votes
This question is tagged with Views, so I'm just going to go out on a limb and leave this here just in case: Views Calc

> This module adds simple calculations to a views table. Requires the Views module.
>
> You can SUM, AVERAGE, COUNT, MIN, MAX, or AVG selected columns. A plug in theme makes the view look more spreadsheet-like (right justifies numeric fields, shades calculated columns and rows, and underlines calculated rows).

# Answer
> 2 votes
The standard method to set up variables and pass them to a template file is through the use of a preprocess function. In the case of the node.tpl.php file this would look something like:

```
function MYTHEME_preprocess_node(&$vars) {
  $field_1_items = field_get_items('node', $node, 'field_something');
  $field_2_items = field_get_items('node', $node, 'field_something_else');

  $computed_value = $field_1_items[0]['value'] + $field_2_items[0]['value'];
  $vars['computed_value'] = $computed_value;
}

```

Then in your template file you could do something like:

```
<div class="some-class">
  <?php echo $computed_value; ?>
</div>

```

That's just an example, your use case will likely differ significantly; but that's the basic method behind it.

Remember that the template files should only ever be used for presentation (adding HTML markup and outputting PHP variables that have been prepared elsewhere), *never* for logic. The only exception to this is conditional logic (`if`/`switch` statements) and other basic logical operations such as `&&`, `||`, etc. As you're performing a calculation on field results you're implementing logic, so using a preprocess function is the correct method in my opinion.

It might seem like a small thing, but separating your presentation and logic will stand you in good stead for future development. If you don't do it you'll end up with a messy code base and future maintenance will be harder than it needs to be :)

# Answer
> 1 votes
If you consider this to be a presentation issue, best place for this operation is node.tpl.php (or analogous template for content type with fields in question) in your custom theme.

If you consider it a second set of actual data, the way to go is Computed Field module or similar solution.

---
Tags: views, entities
---


# Question
Title: why some PDOException errors are displayed in details on users screen and some other not
A user reported to me seeing the following error on his screen:

The watchdog entry for this error looks like this:

```
PDOException: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction: INSERT INTO (.............)

```

I would like this kind of errors not to be displayed in detail on user screens.

However, I am not able to replicate this problem of displaying error in detail on the screen. During my tests, SQL errors are ***NOT*** displayed in detail at all. So, even if I apply a solution (like setting display\_errors to FALSE in settings.php) I won't be able to test it, because I can't replicate this particular scenario which causes errors to be displayed on screen with details.

As part of the testing, I've made a deliberate mistake (in table name) in a database query in mymodule\_node\_view to test how such error will be visible on user screen. The problem is that in both cases, whether display\_errors is turned "on" or "off" (checked on Site Status report: `http://example.com/admin/reports/status/php`), the result is identical. On user screen the error is displayed as:

It's not displaying any details, although in the watchdog log, it is similarly also a PDOException:

```
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.nodeaa' doesn't exist: SELECT (..............)

```

So, I don't understand. Why is Drupal displaying details of some PDOExceptions on user screen and not displaying details of some other PDOExceptions? How to effectively check whether a setting (e.g. display\_errors set to "off") will fix the problem for all sorts of PDOException?

# Answer
> 4 votes
The problem is - error that gets displayed means "Hey, I cannot connect to database! To many users already!". And the setting you are using to prevent error display are in database. And watchdog's log is in database. That's why Drupal shows it - it cannot know you set it not to, the very error prevents it from knowing. And even if it could, it cannot log it in any other way than to user's screen

To get this sorted out, you need two things:

---
Tags: 7, database, security
---


# Question
Title: How do I create a "More like this" block?
Is there a way to create a "More like this" block with the Views, and the Search API Solr modules?
I saw this, but it doesn't work.

# Answer
> 12 votes
Here is the recipe for search\_api\_solr as per the OP. Note: both apachesolr and search\_api\_solr leverage Solr's builtin more like this feature. It is, therefore, not available to *normal search*.

1. Enable some modules: search\_api, search\_api\_solr, search\_api\_views
2. Create a Search server of the Solr class.
3. Create a Search index (or use the *Default node index*) and point your Solr search engine at it.
4. Create a new view on **your search index** NOT on Search index. eg:

`Show *Default node index* sorted by *unsorted*`
5. Continue and edit.
6. Reveal *Advanced* and Add a Contextual filter.
7. Filter on Search or scroll down to find *Search: More like this*.
8. Under *When the filter is not available* select *Provide default argument: Content ID from URL*.
9. Configure by selecting the *Fields for Similarity* that you want to determine *likeness* on.

http://drupal.org/node/1250304#comment-4870278

# Answer
> 1 votes
You don't need anything to create the 'more like this block', just go to admin/structure/block/manage/apachesolr\_search/mlt-001/configure.

However, you can follow this tutorial on how to create it with the Views module, but it's based on taxonomy terms.

---
Tags: views, search
---


# Question
Title: Attribute about not allowed on element article at this point
While i checked the markup of my drupal-7 site in http://validator.w3.org/check it shows me a error:

> error Details:
>
> Attribute about not allowed on element article at this point.

I have checked my markup as well as all the functionality that are running properly. Why i am getting this error?

# Answer
It looks like there is a markup error *somewhere* whereby you have an `<article>` tag with an `about` attribute (i.e. `<article class="my-class" about="blah">`).

I would imagine the site is working fine as the attribute will just be ignored if it's not applicable, so I'd find the page and line from the validator error and double check your markup.

You could also try running it past the newer HTML5 W3C validator at http://validator.w3.org/nu/ just in case.
> 1 votes

---
Tags: entities, nodes, users
---


# Question
Title: How do I change value of a boolean field on a node when a user clicks a button?
I am building a small site for a friend who is getting married and they have their gift list online. Each gift is a node which I am thinking will have a boolean field called something like "bought". The functionality I want to create is that visitors can look at a list of gifts and, if they want to buy something for them they just need to click a button next to it.

So my question is simple, can I change the value of a node field when a user clicks a button?

# Answer
There is a ready contrib module: Wishlist.

> Other site users can indicate their interest in purchasing an item from a wishlist. When that happens, everybody can see that somebody purchased the item and duplicated gifts are eliminated (or reduced - the wishlist module does rely on people playing nicely together).

If you just want the job done, that's your way to go. If you want to learn, read about node\_save() and Form API.
> 1 votes

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


# Question
Title: How to add "load more" link to comments?
I am trying to style my comments list to be similar to Facebook comments, so that user can load more comments by clicking on a link to load more. If there is a big number of comments then he should be able to load more and more comments.

Any suggestions how to start this?

# Answer
Views Infinite Scroll and many similar modules allows you just that.

> Views Infinite Scroll provides a Pluggable pager that enables views infinite scrolling ( autopaging, depaging, endless pages ...you name it) by using jquery.autopager plugin. using this module with views page display will load another page whenever the user reaches bottom of the page.

Views Load More is other example.

> Yes, this is indeed, Yet another load more pager for views.

And you can show anything with Views. Comments too.
> 3 votes

# Answer
This module does a similar thing, More Comments

> More Comments module replaces the default pager of comments with a button that loads the next page of comments using ajax.
> 3 votes

---
Tags: comments
---


# Question
Title: Designing different content types with the same fields' name (shared fields)
For my website I need several content types (at least five), but all that have some fields' name in common as title, subtitle, body, teaser, image and so on.

Shall I use the same field (machine name) for all the content types or is better an its own field for each content type?

For example, if I have the two content types "articles" and "recipes" and create the field "field\_subtitle", shall I use this field for both content types or is better to create the two fields "field\_articles\_subtitle" and "field\_recipes\_subtitle"?

Are shared fields better or worst in term of performance?

# Answer
> 7 votes
Performance isn't a huge issue in my opinion, the advantages you will gain from having correctly built relational data will outweigh any performance gains.

Use the same field across your different content types. If you are storing the same "thing" then semantically using the same field has many advantages.

1. Doing things that are common to that field work across content types. Eg, pulling out the subtitle and displaying it under the H1 in the page template.
2. Some common settings across the entities. This means that if you know a subtitle will never exceed 200 characters, you need only enter this one, keeping your models a little more dry.
3. If you would like to ever list these things together, you can use views to list the common fields with no extra effort.
4. CSS can be written more generically. Subtitles are usually grey and italic, this can be applied across bundles or entities much easier if the fields are common.

There are some disadvantages of creating lots of fields across entities to represent the same data:

1. Messy field lists and lots more database tables. While this wont have too much of an impact on performance, it's simply a technical debt that can be avoided.
2. Messy code. Having to reference -\>field\_articles\_subtitle vs -\>field\_subtitle is simply duplicating information we already know (that we are working with an article).

In terms of CSS, if you would like to define custom types of formatting to different entities you can always use:

```
.node-type-article .field-field-name{ custom-css: true; }

```

In short, for the example you stated use the same field.

# Answer
> 2 votes
As a general rule, I don't share fields unless they are being shared on entities that are part of the same section (or feature if that makes it easier)of my site.

For example, if I need an Entity Reference field that links to users on both a Blog content type and a Blog taxonomy term (I'm not sure why I would, but I can't think of a better example at the moment), then I would probably share it. If, however, I then wanted a field exactly the same on my News content type (i.e. one that references users), then I would create a new field. This means that my blog and news "sections" are independent of one another.

I haven't ever run any performance benchmarks or anything, this is jsut a personal preference that means if I bundle my site config up as a Feature using the Features module, there aren't any conflicts between my Blog and my News features.

On another note if it helps illustrate my point, I also tend to name my fields with a view to where they're being used wherever I can (e.g. `field_blog_userref` or `field_blog_header_image`)

**EDIT**

If you're concerned about making your CSS easier/harder, then even with seperate fields you can give them the same markup/CSS classes with the Fences module.

> Fences is a an easy-to-use tool to specify an HTML element for each field.

So you could have two different fields, but you can give them both the class `.my-text-field` to make styling easier :-)

# Answer
> 1 votes
The big question is - are those field supposed to hold the same data? If yes, then do reuse. Subtitle for article is the same, from business point of view, as subtitle for recipe. They probably are going to be themed the same way, to be searchable (or not) the same way, and so on.

On the other hand, if fields share name by pure coincidence, like "icon" as a religious work of art and "icon" as a small graphical representation of a computer software, keep them separate, with names like icon\_art and icon\_software.

For performance, if your server caches data in a reliable way, it shouldn't matter.

# Answer
> 1 votes
Another consideration that hasn't been mentioned is whether the fields are going to require different settings in the different content types. Some settings (such as label text) can be set per-content-type but others such as cardinality apply across all.

So if only one subtitle can be entered in content type A but content type B can have more than one, then you need to have two separate subtitle fields.

---
Tags: entities, nodes, performance
---


# Question
Title: Content profile fields not showing up on user registration page
I have created content profile fields that I would like to appear on the user registration form. I am using drupal\_render to render these fields on a custom user registration page but they are not appearing. However the other non content profile fields are appearing. Any ideas as to what I could possibly be doing wrong?

I am using Drupal 6.26

Thanks.

# Answer
Fields added in the Content profile will appears in user registration page once you check the check box " use on registration".

You can add default profile fields in admin settings-\> user management-\>profile to show in user registration page.

Instead the uses of Content profile fields here can control for specific role by giving permission but profiles fields in user settings are default for all user registration form .

You can render the fields in custom user registration tpl page by this

drupal\_render($form\['CATEGORY CHOOSED WHILE CREATING FIELD'\]\['PROFILE FIELD'\]);
> 0 votes

# Answer
Can you see the fields when you create a user as admin (admin/user/user/create)? If so, this means that permissions are not properly assigned to authenticated users to create those fields. So you need to go to permissions page and edit permissions to each new field that you have created on profile node type.
> 0 votes

# Answer
To appear content profile in user registration form, edit your content profile content type. Choose "content Profile' Tab and choose 'Use on Registration' check box and save.
> 0 votes

---
Tags: 6, users
---


# Question
Title: How to add a option in wysiwyg editor so that blocks can be selected as images?
Using the Wysiwyg module, we are able to add an image. Is there any way so that I am able to view my blocks in it as well as assign those blocks in any place inside a page?

# Answer
Seems you will need to write your own plugin. There are dozens of manuals, like Creating a CKEditor Plugin with a Custom Dialog Window \- this one seems to be good for you, as you might want to have dialog window to allow user select a block.

You will need tips from this Drupal.org thread to

Don't forget to consider security issues when deciding who should be able to add what.

Last but not least, publish your module on Drupal.org for future developers.
> 2 votes

---
Tags: wysiwyg
---


# Question
Title: How to show a content without creating node for it on Drupal site?
I am creating a custom node page called node--mynode.tpl.php. The code I'm putting in is `<p> test</p>`

Unfortunately nothing shows up on my Drupal site. I have also added a node.tpl.php on the same folder as my node--mynode.tpl.php. However I'm not sure if I have to add any code to the node.tpl.php?

Is it anything I need to add on my template.php?

Many thanks

# Answer
> 3 votes
While not at all suggested or encouraged, if you really want to create a static page in drupal, you can fake it out by creating a `page--PATH.tpl.php` template, but just realize that while it will show up, behind the scenes drupal will be throwing 404 / not found errors.

See Drupal 7 Template Suggestions for more information.

What I would suggest instead, though, is to look into Drupal's Menu System and create a callback for the page in question.

# Answer
> 0 votes
Sorry, you cannot create content inside Drupal without creating nodes. That's against the very basic concept behind Content Management Systems.

If you need, however, a static HTML page, make just that - a static HTML page inside your Drupal installation, but without using any Drupal's systems. It will get served, files have precedence over Drupal. **I strongly discourage this**, but it will work.

If are willing to add node, create one with fields you will most probably need to edit, like title, body and so on. This way you will be able to edit them on site if needed, archive, revision and so on. And you will be able to use Entity Reference or Views Field to show other things along it: comments, image galleries and so on. Both projects are well documented, and works with each other if needed.

# Answer
> 0 votes
as per you are asking you need to put an function $content = node\_load('nid'); . Then print the $content, you can get the values of the node what you mentioned in nid. nid is nothing but the node id of the node which is having field\_image\_1 from another content type. for the current node you need to put another funtion $content = node\_load(arg(1)); arg(1) is nothing but the current nid passing on the url. Finally you can print the current node(product) contents and also print the another content type contents(image field)..

---
Tags: nodes, theming
---


# Question
Title: page "/node/add" that I would like to programmatically limit the links that are displayed based on the users role
I have a page "/node/add" that I would like to programmatically limit the links that are displayed based on the users role. Is using either hook\_form\_alter or hook\_form\_ID\_alter the way to do this? I just figured out that "/node/add" is not a form so I can't use hook\_form\_alter or hook\_form\_ID\_alter but in doing a little research it appears that I may be able to user hook\_page\_alter() instead to filter out some of the links.

# Answer
> 3 votes
If you set node creation permission (Node Module on `www.yourhost.com/admin/user/permissions`) to specific roles, the existing form should take care of this automagically by itself, eg, if the user accessing `www.yourhost.com/node/add` can't create a specific node type, it won't be presented on that page.

Based upon commentary, `node/add` is built via:

```
function node_add_page() {
  $item = menu_get_item();
  $content = system_admin_menu_block($item);
  return theme('node_add_list', $content);
}

/**
 * Display the list of available node types for node creation.
 *
 * @ingroup themeable
 */
function theme_node_add_list($content) {
  $output = '';

  if ($content) {
    $output = '<dl class="node-type-list">';
    foreach ($content as $item) {
      $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>';
      $output .= '<dd>'. filter_xss_admin($item['description']) .'</dd>';
    }
    $output .= '</dl>';
  }
  return $output;
}

```

so you most certainly could create a new `YOURTHEME_node_add_list()` function that filters the links based upon a user's role realizing that if the user entered the link directly it would nonetheless still work.

You could also create a `node-add-list.tpl.php` in your theme's directory with basically this in it as a start:

```
<?php

  $output='';

  if ($content) {
    $output = '<dl class="node-type-list lrfm-ed">';
    foreach ($content as $item) {
      $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>';
      $output .= '<dd>'. filter_xss_admin($item['description']) .'</dd>';
    }
    $output .= '</dl>';
  }
  print $output;

```

and then modify it however you wanted.

Just flush caches after either to make drupal's theme system see and pick up the changes.

---
Tags: hooks, forms
---


# Question
Title: Custom theme function for language switcher block
I have a problem with theme hook suggestion for language switcher block. I just need to place theme\_links\__locale\_block() in MYMODULE.module file

**My module:**

```
/**
 * Implements hook_theme()
 */
function MYMODULE_theme() {
  return array(
    'MYMODULE_links' => array(
        'variables' => array(
            'links'      => NULL,
            'attributes' => NULL,
            'heading'    => NULL
        )
    )
  );
}

/**
 * It doesn't work...
 */
function theme_MYMODULE__locale_block(&$variables) {
    // custom function code ...
}

```

It works in my template.php file:

```
function MYTHEME_links__locale_block(&$variables) {
    // custom function code ...
}

```

I don't want to leave it in template.php because it is a part of my module.

Any help would be appreciated.

# Answer
**SOLVED!**

adding hook\_theme\_registry\_alter(&$theme\_registry) was the answer.

```
/**
 * Implements hook_theme_registry_alter
 *
 */
function MYMODULE_theme_registry_alter(&$theme_registry) {

  $mod_path = drupal_get_path('module', 'MYMODULE');

  if (isset($theme_registry['links'])){
    $theme_registry['links__locale_block']['theme path'] = $mod_path;
    $theme_registry['links__locale_block']['function'] = 'MYMODULE_links';
  }
}

```
> 0 votes

---
Tags: blocks, theming, i18n-l10n
---


# Question
Title: $base_url and $THEME_ARRAY using together
I have this in settings.php:

```
$THEME_URLS = array(
  array('/optoelectronics','sky'),
);
foreach ($THEME_URLS as $info) {
  if (strpos($_SERVER['REQUEST_URI'], $info[0]) === 0) {
    $conf['theme_default'] = $info[1];
  }
}

```

I have two domains each based on a different theme. The issue is that I'm trying to use part of the old theme for just these two sections but the other theme is entirely based on SKY and if I make any modifications to the css or create a page-optoelectronics.tpl.php, then both sites receive the modifications, which I don't want.

So I duped the theme "sky" and changed all appropriate names and such to 'optotemp' but as I mention above, Drupal still disregards the "http://www.site.com" part and switches to 'optotemp' when it sees /optoelectronics.

So I found $base\_url which returns the full path, including the host.

I'm a little rusty with the combination of an if/else command and including the array above in one fell swoop.

I want to say: If the absolute path is http://www.sitea.com/optoelectronics use theme optotemp. Otherwise, use the default theme. This command would then mean by default that http://www.siteB.com/optoelectronics would still use the theme assigned to that domain via the domain access module, which is Sky.

In other words, www.sitea.com has a new entire theme, but two sections of www.sitea.com will need to use optotemp but www.siteb.com uses sky.

I need help on knowing the syntax to get this right.

```
var $usOrEuro = $base_url;
if ($usOrEuro == 'http://www.sitea.com/optoelectronics'){
  $appliedTheme = 'optotemp';
}

$THEME_URLS = array(
  array($usOrEuro, $appliedTheme),
);
foreach ($THEME_URLS as $info) {
  if (strpos($_SERVER['REQUEST_URI'], $info[0]) === 0) {
    $conf['theme_default'] = $info[1];
  }
}

```

# Answer
> 0 votes
This should do it:

```
$hosts = array('sitea.com', 'www.sitea.com');
if (in_array($_SERVER['HTTP_HOST'], $hosts) && $_SERVER['REQUEST_URI'] == '/optoelectronics') {
  $conf['theme_default'] = 'optotemp';
}

```

---
Tags: theming
---


# Question
Title: How to add custom css class to block wrapper
I need to add custom css classes to several blocks (can be blocks from view, or facet api, etc). Is there a way to do it without creating a template for every block? It could be useful a theme function, or a hook, that should do something like:

```
 if ($var == 'block_name') {
   $class_custom = 'my-custom-class';
 }

```

Is it possible?

# Answer
There's a template function for this: template\_preprocess\_block.

Use `$variables['classes_array']` to add classes to the block.
> 2 votes

# Answer
You can also use the Block class project for the matter.

> Block Class allows users to add classes to any block through the block's configuration interface. By adding a very short snippet of PHP to a theme's block.tpl.php file, classes can be added to the parent element of a block. Hooray for more powerful block theming!
> 3 votes

---
Tags: theming, blocks
---


# Question
Title: Rules in Drupal 7: EntityMalformedException in custom PHP
I used to run successfully the following custom PHP code in rules before a node is stored

```
$update_node = node_load($node->nid);
$lat1 = floatval($node->field_geo["und"][0]["lat"]);
//SOME MATH HERE
$update_node->field_winkel_dorf["und"][0] = array("value"=>$winkel);
node_save($update_node);
}

```

But now after a major update of lots of modules I get this error: EntityMalformedException: Fehlende Paketeigenschaft auf einem Element des Types node. in entity\_extract\_ids() (Zeile 7663 von /var/www/vhosts/mydomain/httpdocs/includes/common.inc).

I have no idea what changed....

Any help very very welcome.

# Answer
> 2 votes
You need to remove the first line `$update_node = node_load($node->nid);` because `nid` does not exist yet in node object then remove the last line as well `node_save($update_node);`.

Also, replace each `$update_node` variable with `$node` which is available by rules module.

Your final code should look like the following:

```
$lat1 = floatval($node->field_geo["und"][0]["lat"]);
//SOME MATH HERE
$node->field_winkel_dorf["und"][0] = array("value"=>$winkel);

```

---
Tags: rules
---


# Question
Title: Set all boolean certain fields to 0 if 1 with rules
I'm trying to reset all field\_flag fields of all terms of a taxonomy value, where field\_flag is TRUE (or 1).

Does anyone know how to do that?

Maybe some more back-story: I have a rule that gets fired on creation and editing of a taxonomy term when it has the field\_flag in it. Now out of this I want to "reset" all field\_flags since only one term can have that field checked.

Thanks!

# Answer
> 0 votes
To clarify, you have created a new flag using the Flag module and attached it to a taxonomy bundle (either terms or vocabularies) and want to reset these flags.

You can do this directly in your database with a couple commands. First, you need the Flag ID of your flag which is in the 'flags' table:

```
mysql> desc flags;
+--------------+----------------------+------+-----+---------+----------------+
| Field        | Type                 | Null | Key | Default | Extra          |
+--------------+----------------------+------+-----+---------+----------------+
| fid          | smallint(5) unsigned | NO   | PRI | NULL    | auto_increment |
| content_type | varchar(32)          | NO   |     |         |                |
| name         | varchar(128)         | YES  | UNI |         |                |
| title        | varchar(255)         | YES  |     |         |                |
| global       | tinyint(4)           | YES  |     | 0       |                |
| options      | text                 | YES  |     | NULL    |                |
+--------------+----------------------+------+-----+---------+----------------+

```

You can find this by selecting the fid, and name from flags:

```
mysql> select fid, name from flags;
+-----+---------------+
| fid | name          |
+-----+---------------+
|   1 | bookmarks     |
|   3 | taxonomy_flag |
+-----+---------------+

```

In my development server, the taxonomy\_flag id is 3. Now take a look at the flag\_content table where all the flag content data is stored:

```
mysql> desc flag_content;
+--------------+----------------------+------+-----+---------+----------------+
| Field        | Type                 | Null | Key | Default | Extra          |
+--------------+----------------------+------+-----+---------+----------------+
| fcid         | int(10) unsigned     | NO   | PRI | NULL    | auto_increment |
| fid          | smallint(5) unsigned | NO   | MUL | 0       |                |
| content_type | varchar(128)         | NO   | MUL |         |                |
| content_id   | int(10) unsigned     | NO   | MUL | 0       |                |
| uid          | int(10) unsigned     | NO   |     | 0       |                |
| sid          | int(10) unsigned     | NO   |     | 0       |                |
| timestamp    | int(10) unsigned     | NO   |     | 0       |                |
+--------------+----------------------+------+-----+---------+----------------+

```

What you want to do to reset all the values for your target flag is delete all entries from the flag\_content table, so in my example above that would be

```
delete from flag_content where fid=3;

```

---
Tags: 7, taxonomy-terms, rules
---


title: Access input format based on user role

text:
# Question
Title: Access input format based on user role
I have the Developer user role which should only access the developer\_html input format. I am trying to grant the necessary permission with user\_role\_grant\_permissions().

I got this piece of code here and also tried to edit according to my requirement, but failed.

```
function filter_update_7008() {
  // Build the list of permissions to grant.
  $permissions = array();
  foreach (filter_formats() as $format_id => $format) {
    if ($permission = filter_permission_name($format)) {
      $permissions[] = $permission;
    }
  }

  // Grant text format permissions to all roles that can 'administer filters'.
  // Albeit anonymous users *should not* have the permission, we cannot presume
  // that they do not or must not.
  if ($roles = user_roles(FALSE, 'administer filters')) {
    foreach ($roles as $rid => $name) {
      user_role_grant_permissions($rid, $permissions);
    }
  }
}

```

# Answer
> 1 votes
The general solution for cases like this, where you want to export an input format, a role, and a permission associated to that role is using the Features module. Selecting what you want to export on admin/structure/features/create, the module will create a feature: a module that (once installed) will make available what exported.

If you don't want to use the Features module, you can create a module that:

* Creates the Developer role if it doesn't exist
* Creates the input format if it doesn't exist
* Creates the permission to use that input format if it doesn't exists
* Assigns the permission to use that input format to the Developer role

Assuming that the role and the input format already exist in the site, the code is simply the following.

```
if ($format = filter_format_load('developer_html')) {
  if ($permission = filter_permission_name($format)) {
    if ($role = user_role_load_by_name('developer')) {
      user_role_grant_permissions($role->rid, $permission);
    }
  }
}

```

As to where to use this code, you have two possibilities:

* `hook_install()`
* `hook_enable()`

`hook_enable()` is what the Forum module uses to create the forum vocabulary and the "taxonomy\_forums" field it uses (see forum\_enable()). I would use this hook if the module requires something to be set/present before it runs; differently from `hook_install()`, it has also the pro of not requiring a `hook_update_N()` to be added for those users who update the module, since `hook_install()` runs only during installation, while `hook_enable()` runs every time the module is enabled.

# Answer
> 0 votes
hook\_update\_N() should never be used for data migration or common work of a module. It's one and only purpose is to adjust data between module versions - not your case.

If you need to share initial setup, there are dozens of manuals on *how to make a Drupal distribution* easy to find using any major internet search engine. Just set what settings you need to share, make it a distribution and reuse.

If you need to keep it updated, you can wrap text formats and user roles in a Feature, set one site as a feature server and make others update from it. Or write own XML-based solution.

---
Tags: users, input-formats
---


# Question
Title: How to make custom jquery method accessible from Drupal.behaviors, across multiple javascript files?
I have a custom views plugin. When the view is displayed, the javascript below gets loaded. Note the custom method, `do_stuff`, which gets called from within `Drupal.behaviors`.

```
(function ($) {
  $.fn.do_stuff(indx){
    alert (indx);
  }
  Drupal.behaviors.mymodule = {
    attach: function (context, settings) {
      if (settings.hasOwnProperty('mymodule')) {
        $('.my-item').each(function(indx, item) {
          // do stuff to each item
          $(this).do_stuff(indx);
        });
      }
    }
  }
}(jQuery));

```

I would now like to create a second plugin, which loads a second javascript file. This second javascript file needs access to the custom method, `do_stuff`. Is there a way I could access the `do_stuff` code defined in the first javascript file, from within the second javascript file? For example, is there a way to move the custom method inside Drupal.behaviors, so that it could then be accessed from within any other javascript file?

# Answer
I use a slightly different JS pattern with Drupal, which is based on the Javascript Module Pattern.

```
var FOO = (function(me, $, Drupal, undefined) {
  me.name = "FOO";

  function do_something_awesome () {
  }

  me.do_stuff = function do_stuff () {
  }

  function init (context, settings) {
    me.do_stuff();
    do_something_awesome();
  };

  Drupal.behaviors[me.name] = {
    attach: init
  };

  return me;
}(FOO || {}, jQuery, Drupal));

```

Anything directly attached to `me` will be public on the `FOO`. The rest is private. Typically, I will pass in `FOO` into the closure in dependent libraries.
> 3 votes

---
Tags: 7, views, theming, javascript
---


# Question
Title: How can I grey out/disable certain fields?
I am using a Webform module for my multi page form. I would like certain form elements to be greyed out/disabled if an answer to one of the questions is "Yes" (dropdown list).

How would I go about doing this?

# Answer
> 1 votes
If you're using Webform 3.x, you're probably looking for the Webform Conditional module. If you're using 4.x, conditionals support is built in.

Adding conditionals to your webform will allow you to show or hide webform fields based on answers to other fields. Using the above module or built-in support in 4.x, you could completely hide a certain field if the answer to another field was "Yes."

---
Tags: 7, webforms
---


# Question
Title: Managing featured content the drupal way
I currently have a homepage layout similar to the illustration below:
The featured nodes are all Views in separate block regions displaying a teaser. I'm using a taxonomy term to filter in the specific node that I want appearing there.

As I'm new to Drupal, I'm wondering if:

a) My choice of using 4 separate block regions was wise. Would it have been wiser to use a view that shows a grid of 4 teasers?

b) If there is a better way of displaying featured content in the region below the slider (such as a 4 column panel)

Any insights into an effective workflow here would be greatly appreciated, thank you!

# Answer
> 2 votes
If your goal is to make a simple workflow for your clients, you have to take into account your clients' general ability to use the Web. What is easy for one client may be very difficult for another, so it's hard to say which workflow is superior. For example, when I set up a Drupal website for a CS professor, very little customization was required; on the other hand, when I set up Drupal for my grandfather, I had to do a lot of workflow customization to remove options and simplify things.

As far as easily allowing content to be "Featured," I usually set it up with Flags. This is a pain to set up but is very simple for end users. Basically, you have a flag for each section you want to feature. This flag should allow you to flag nodes of the content type you want to feature. Then you create a rule using the Rules module that trims the flag to 1; this means that only one piece of content can have the flag at any given time (assuming you only want to flag one piece of content per section). Then users with the appropriate permissions can simply flag the content that they wish to feature and it will automatically be featured. Advanced users probably don't need this, but for users with limited computer skills it may be helpful.

As for your concerns about excessive markup, Drupal in general generates lots of wasteful markup. There are solutions like the Fences module and Semantic Views to try to slim it down, but in general I would not worry about this; you would have to have a huge amount of traffic before the time you spent trying to slim down the markup paid off.

---
Tags: workflows
---


# Question
Title: "Add an item to a list" using rule just works for plain text
I created a rule with an action which "Add an item to a list". The value of the item to add is this (also see my picture bellow)

```
Voucher: [node:title].
The code for this voucher is [codigo-otorgado:value].
View the voucher: [node:url]

```

This item will be added to a field of the user which I created at `admin/config/people/accounts/fields` The details of this field are:

```
Name: My voucher codes
Type: Long text
Widget: Text area (multiple rows)
Text processing: Plain Text
Number of values: Unlimited

```

So far so good. When the rule is fired all is working right, but The problem is that the text is shown as plain text. As you can see there is a url and breaks lines that I need to print out.

I guess the first suggestion will be to change the **Text processing** of the field to **Filtered Html or Full Html**, and so I did.

But then the tokens (\[node:url\], \[node:title\]..) inside the value doesn't work. The tokens are printed as it, instead of their values.

I know that **Rules** is very mature module and I'm sure there must be a way to do this. What am I missing here?

# Answer
> 1 votes
You have saved your textarea field as Plain text, change it to Filtered Text (in Text formats admin settings you should check allowed tags):

---
Tags: 7, rules, tokens
---


# Question
Title: How to assign a dynamically updating date to a user based on a related field on their profile
I have a site where Users who can expect a delivery to their address every week depending on their delivery route. I also have a Content Type of "Delivery Route" and a Content Type of "Delivery" with a Date field and an entity reference field that adds related delivery routes for each delivery. With this I have a couple issues:

1: How to automatically assign a user a delivery route based on the ZIP code of their delivery address entered upon registration (Using the Address Field module).

2: How to display the next upcoming delivery date for a particular user on their profile based on deliveries collected for their delivery route.

# Answer
For this I discovered that it can be handled using Views with Entity Reference.

For the first part, assigning a delivery route based on the zip code, I used Entity Reference Prepopulate and created a link from a custom landing page that populated the user's route. Although I think rooby's answer might still be a good path.

For the second part I used a Views block on the user's account page to display a message about the next upcoming delivery date for the route assigned to that user. Here's what I did:

1. Create a Content Type of "Delivery" with a Delivery Date Date field and a Entity Reference field to reference the Delivery Route entity.
2. Create a block view of Delivery nodes:

• Add the Delivery Date field

• Add a relationship to entity referenced from field\_delivery\_routes

• Add a relationship to the User referencing field\_user\_delivery\_route using the relationship from above (field\_delivery\_routes). Check "Require this relationship."

• Add a contextual filter for User: Uid (User referencing Content from field\_user\_delivery\_route). Choose When the filter value is NOT available, Provide default value: User ID from URL.

• Now the view can be sorted by Content:Delivery Date (asc), specifying only 1 item displayed in the view or by using Filter Criteria with Date Views (submodule of Date) to only show dates within a certain range.
3. Display the Views Block on the User profile page.

I'm also hopeful that this view can be used with EVA or Display Suite to create an actual field to display on the user's account.
> 0 votes

# Answer
You should be able to do those things without coding.

You can use the entity reference module to add a field to the user's profile that references the relevant delivery route node.

Then you can use the rules module, along with the rules conditional module to do the rest.

Have a rule that on user registration, uses the "Fetch entity by property" action to load the node that has the matching post code.

Then use the "Set a data value" action to set the value of the entity reference field for that user, based on the fetched entity.

Have another rule for when a user profile is viewed that uses the "Fetch entity by ID" action to load the delivery route node for that user.

Then add an if conditional that checks the entity type and content type, or use "Entity has field" and check that the date field is present. This step is required for you to be able to use all the fields on the fetched node in later actions.

Then you can use the "Show a message on the site" action to show a message to the user, in which you can use tokens to show the value of the date field attached to that delivery route node.
> 1 votes

---
Tags: views, datetime, entities
---


# Question
Title: "Jirafe credentials are not set" warning from Commerce
After install Commerce Kickstart 2.7, there is a warning:

> Jirafe credentials are not set. Get your credentials at Jirafe

What is `Jirafe` and `Jirafe credentials`?

# Answer
> 1 votes
Jirafe is an analytics, alerting, and automation platform that is deeply integrated into ecommerce, marketing, and other platforms.

The Jirafe module integrates Jirafe with Drupal Commerce, and allows the following features:

> View your visits, orders, revenue, conversion %, AOV (average order value), and RPV (revenue per visit). This information can give you a great summary of your business at a glance. See how your visitors become customers at 5 critical points in your application. Easily see when visitors leave your site, so that you know what areas of your site to improve.

As you are using Commerce Kickstart, the module is already enabled. To configure You just need to:

* Click on the Reports tab of your administration menu, or access admin/commerce/jirafe
* Enter your credentials (Application ID and Token) that you get from jirafe and click Save

# Answer
> 0 votes
Jirafe is a web service providing customer analytics. You have to subscribe (free) to the service, hence the requirement for credentials.

---
Tags: 7, commerce
---


# Question
Title: Unable to create a view of type solr search
I have installed the apachesolr , views and apachesolr\_views modules but I am unable to create a view of type solr search. Is there something i am missing? Because the apachesolr\_views provides views integration of apachesolr.

Any Help?

# Answer
> 0 votes
Steps:

1. Install the modules that you have mentioned
2. Install and configure Apache Solr in your server
3. Configure Apache Solr server in the apachesolr module settings
4. Add a view. Select Apache Solr localhost server (or the name that you have given to your Apache Solr server configuration in apachesolr settings) in the Show dropdown menu when creating the view.

Steps for installing and configuring Solr:

1. Download the .zip file from http://lucene.apache.org/solr/ (you might want to try with version 3, although it has worked for me with 4
2. Unzip in a folder in your machine
3. Copy all the contents from sites/all/modules/apachesolr/solr-config/solr-3.x/ to apache-solr/example/solr/conf/ in the folder you created in step 2
4. Start the server with running java -jar start.jar

Check in the admin section of your Drupal site if the server is found and working.

---
Tags: views, 6, search
---


# Question
Title: Translation "Global: Text area" in views footer
I use Internationalization module for multilingual site. Is there a way to translate custom text in views footer except of creating a new view for a second laguage?

# Answer
> 1 votes
Use PHP instead of text area, make the strings translatable by using t('MyString').

**Update**: usign PHP is not a recommended practice... Probably you could have a template for that view. and inside a string inside t('My String')... Then you can use the translation interface.

---
Tags: views, i18n-l10n
---


# Question
Title: Image-link to content works only on preview
I have a view showing content of a specific content type. In the view, I show 2 links, linking back to the specific content. The first one is an image field and the second is the title field. Both links work on the preview but on the actual display only the title links to the content. The view is shown through a panel.

# Answer
Views preview does not use templates from your theme. Expand Advanced on the right, and in Other section click Theme: Information. Find .tpl.php files that are bolded and may apply to your fields (are applied to them directly, or to their parents). Look for them in your theme's directory and search them for errors.

If that will not help, offending template comes from Panels, not Views themselves.
> 1 votes

---
Tags: views, media
---


# Question
Title: Where to put Commerce Kickstart translation po file?
After installing a blank Commerce Kickstart site, I'd like install another language as default for the site.

I can see the language `.po` file to download -\> here

Where should I put the `.po` files and how can I enable the new language as default?

# Answer
> 3 votes
The internationalization process is not unique to Commerce Kickstart; it is the same for all Drupal sites and handled by the *Locale* module. The Drupal.org documentation can be found here. (Start with Install a language.)

# Answer
> 0 votes

# Answer
> 0 votes
After downloading a commerce\_kickstart `.po` file from here, import it via:

```
/admin/config/regional/translate/import

```

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


# Question
Title: Regarding flag actions and rules integration
I am using flags by the Flag module. I added two action on that flag through Flag actions:

* The first one is to send an email to the site admin whenever the node is flagged.
* The second is to do a Page Redirect. This action does not works and gives me an ajax error.

In my search I found this was an issue for flag module for Drupal 6. However, it still does not work. My version of Flag is 7.x-2.0 and I am using Drupal 7.

After trying out with action, I went for the better option, i.e, using Rules. I added a reaction rule with the action: `A node is flagged` under "my\_flag" and the event : `Page redirect`. And I also checked the forced redirect. Its still not working.

Would really appreciate any help or suggestions regarding this.

# Answer
I realise this is a long time ago but for anyone else who arrives here: you can't redirect when doing AJAX flagging, because the redirect applies to the AJAX call not the current page.

It's theoretically possible, with D7, to return a page redirect using AJAX commands but I'm not sure off the top of my head how you would achieve that in this case, or whether you'd need some modification to the Flag module code to allow it to occur.
> 1 votes

---
Tags: 7, rules, flags, actions
---


# Question
Title: Views to display events with single date events and events with date range
I have a views view that displays a list of events. These events have a start-date and an end-date. I have two exposed filters, one for the start-date and one for the end-date, so that users can select a date range to view events. The page can be seen here:

KODE Calendar page

The filters check that start-date \<= selected start-date and that end-date is \>= selected end-date. This works if the event spans several days and start- and end-date falls outside the selected dates.

The question is, how can I include events that have start-date and end-date on the same day?

I tried to have another set of filters and use the and/or functionality, but alas, I was not able to reuse the exposed filter.

# Answer
Since I was completely unable to make myself understood when asking the question, I thought maybe the solution could clear things up. In the views view I filter event dates like specified in the question. I then used the `hook_views_query_alter` to add an or group condition like so:

```
function MYMODULE_views_query_alter (&$view, &$query) {
  if ($view->name != 'events') { return; }

  global $language;
  $lang = $language->language;

  $start_date = isset ($_GET['field_from_date_value']['value']['date']) ? $_GET['field_from_date_value']['value']['date'] : date('Y-m-d');
  $end_date   = isset ($_GET['field_from_date_value2']['value']['date']) ? $_GET['field_from_date_value2']['value']['date'] : date('Y-m-d');

  $query->group_operator = 'OR';

  $status_condition = array (
    'field' => 'node.status',
    'value' => 1,
    'operator' => '='
  );

  $node_type_condition = array (
    'field' => 'node.type',
    'value' => array ('event'),
    'operator' => 'in'
  );

  $language_condition = array (
    'field' => 'node.language',
    'value' => array ($lang),
    'operator' => 'in'
  );

  $date_condition_value = array (
    'field' => "DATE_FORMAT(field_data_field_from_date.field_from_date_value, '%Y-%m-%d') >= :field_data_field_from_date_field_from_date_value",
    'value' => array (':field_data_field_from_date_field_from_date_value' => $start_date),
    'operator' => 'formula'
  );

  $date_condition_value2 = array (
    'field' => "DATE_FORMAT(field_data_field_from_date.field_from_date_value2, '%Y-%m-%d') <= :field_data_field_from_date_field_from_date_value2",
    'value' => array (':field_data_field_from_date_field_from_date_value2' => $end_date),
    'operator' => 'formula'
  );

  $condition_type = 'AND';

  $query->where[10]['conditions'] = array (
    $status_condition,
    $node_type_condition,
    $language_condition,
    $date_condition_value,
    $date_condition_value2
  );

  $query->where[10]['type'] = $condition_type;

}

```
> 1 votes

---
Tags: 7, datetime, views
---


# Question
Title: give node author ability to position the image when uploading content
I have a field of type image "COVER IMAGE" in my blog entry content type. The users should have the power to place it wherever they like...top, down,right or left, if not more and re size it. right now it appears at the bottom of the content and of the same size as that uploaded.

Can this be done?

Regards

# Answer
> 3 votes
Of course it can! Was covered in docs and in even more docs and is supported by Wysiwyg, with helpful modules like Insert to make it even easier.

# Answer
> 3 votes
You can use the Formatter Field module for the second part

> The formatter field module provides a mechanism for specifying a formatter and formatter settings to be used for displaying a field, on a per-entity basis. By default, Drupal provides formatters and settings per entity bundle, but in certain situations it is necessary to choose the formatter at the entity level.
>
> For example, say you have a page node with an image field. Normally, you would select an image style as the formatter, and all page nodes would use that same image style. With this module, you can add a formatter field to page nodes, which is hooked up to the image field. Then when the node is created or edited, the image style can be selected per-node.

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


title: How do I theme a webform?

text:
# Question
Title: How do I theme a webform?
I am in need to theme webform in D7.

How can I do that ?

In the search I've come to know that by using web-form-nid.tpl.php we are able to theme a drupal individual form.

Could any one guide me in this case to theme a webform.

# Answer
You can theme a individual webform using `webform-form-nid.tpl.php`.

For example if our webform node id is 7 , create a template file namely `webform-form-7.tpl.php` and place it in your theme folder. Clear site cache.

Do a `print_r($form);` to see all the elements. Then render each elements in file within your html elements.

```
<li>
    <?php print drupal_render($form['submitted']['name']); ?>
</li>

```

As @Patrick Kenny said read the theming.txt, it explain all aspects of theming a webform
> 27 votes

# Answer
If you know the .tpl.php filename, here is what you do:

* Create empty file with that name in your theme. Element it was supposed to template disappeared? Good.
* Put simple html tag and see if it is displayed in place of your element. It is? Great, you have correct template file.
* See all variables you can use: place `<pre><?php print_r(get_defined_vars()); ?></pre>` in your template.
* Now when you have a file and data structure, just do it!
> 4 votes

---
Tags: 7, webforms, theming
---


# Question
Title: How to preserve a “target” attribute on links in overlays?
How can I preserve `target` attribute functionality in Drupal 7 overlays? They appear to always be overwritten with `target="_parent"`.

I have added a link to the help text of a field. I would like to open the link in a new browser tab/window so that the user’s input in the form is not lost when following the link. However, the `target` attribute appears to be overwritten and the link opens in the same overlay.

Here’s the relevant portion of the help text:

```
 I agree to the site’s <a href="../../node/5" target="_blank">Terms of Use</a>.

```

# Answer
> 2 votes
In general, all links can be excluded from being processed by the Overlay module. Just add a CSS class named `overlay-exclude` to the `class` attribute of the link.

That has also solved my `target` attribute issue:

```
 I agree to the site’s <a class="overlay-exclude" href="../../node/5" target="_blank">Terms of Use</a>.

```

---
Tags: 7, modal-dialogs
---


# Question
Title: How do i fix Invalid arguments passed in DefaultMailSystem->format() (line 23 system.mail.inc
I'm getting this error while developing a module:

> Warning: Invalid arguments passed in DefaultMailSystem-\>format() (line 23 /modules/system/system.mail.inc)

here's my code:

```
function mymod_mail($key, &$message, $params) {
    switch ($key) {
        case 'job_mail':
            $message['subject'] = 'mysubject';
            $message['body'][] = 'test';
            break;
    }
}

```

I googled it normaly this happens when `$message['body']` is defined like this: `$message['body'] = 'test';` instead of `$message['body'][] = 'test';`

And then I've got the following code to call the above hook\_mail()

```
function mymod_send_mail($vacancies, $user) {
    // specify module name and template key for hook_mail
    $module = 'mymod';
    $key = 'job_mail';

    // Specify to and from addressses.
    $to = 'my@email.com'; // user email TODO get user email based on $uid
    $language = language_default();
    $params = array(
        'username' => $user->name,
        'sitename' => variable_get('site_name', 'Drupal'),
    $from = variable_get('site_mail', 'default@email.com');
    $send = TRUE; // defaul = TRUE can be set to FALSE to not actually send the mail and only generate it.
    drupal_mail($module, $key, $to, $language, $params, $from, $send );
}

```

I've put a `debug()` in system.mail.inc above the implode function but that showed my message `$message['body']` was not an array ( `$message['body'][]` ) anymore.

Also when I put a debug on the result of the drupal\_mail function I see that my subject is set but the body is empty.

# Answer
> 3 votes
I fixed it by using:

```
$language = user_preferred_language($user);

```

---
Tags: 7, emails
---


# Question
Title: What items in the DB do I need to edit when switching from a multisite to a single site?
I've copied a single site from a live multisite setup to my local (MAMP) server. The content is showing from the site however it is unstyled (and also the home page is showing the 404 page). I assume there's some changes I need to make to the DB to fix this and allow the site to function correctly.

I'm running version 6.22

# Answer
> 1 votes
Since your content is showing, your DB connection is OK.

Even if you don't have DB access to the multisite, you should have DB access to your local (MAMP) server. And even if that site's styling is broken, you should still be able to back up its *contents* using Backup and Migrate.

The fact that the content is unstyled and 404 shows on the home page indicates that your basic site setup is not correct. IIRC, Drupal 6 did indeed appear unstyled if you migrated content between sites without resetting to the default (Garland) before migrating.

There may be a more direct way to repair this (I think Mołot's link in his first comment points to such a recipe), but the way I got around this problem was by setting up an *empty* single Drupal 6 site with the default D6 theme (Garland). While it was still empty, I configured it and installed and enabled all the modules I was going to need. Then I used Backup and Migrate to backup my content, and migrated that content (using Backup and Migrate) to the newly created and empty Drupal 6 monosite.

After the content was in place, I installed the the theme I wanted to use, and made it the default.

(I.e. the idea is to use Garland *until* everything else is OK.)

# Answer
> 0 votes
Change you DB details in your `settings.php` file in `sites/all/default directory`

---
Tags: database, 6, multi-sites
---


# Question
Title: What is the best workflow to migrate a site using domain access?
i have a site with 20 subdomains using the domain access module on a dev server and i want to migrate them to a production server.

There is only a change from

> subdomain.maindomain.eu

to

> subdomain.maindomain.de

What is the best to do it ?

# Answer
Can you be a little more specific, are you just wanting to migrate the whole database to a new installation or are you migrating content into an existing installation

In the first case it should be fairly simple,

* Put your site in maintenance mode and then flush all the caches.
* Take a backup of your sites directory.
* Copy the database to the new server.
* Upload the drupal installation and then the sites directory to your new server
* Modify the settings.php to connect to the database on the new server.
* Using a DB admin tool such as phpmyadmin modify the "domain" table in the database on the new server, there is a field in this table called "subdomain" this relates to the url of your domains so just modify this to suit your needs.
> 1 votes

---
Tags: migrations, domain-access
---


title: Change Page Title on Add Node Page

text:
# Question
Title: Change Page Title on Add Node Page
Which hook/filter do I need to use to modify the 'add node' page title (This Title)? For example, when viewing "/node/add/" I want to change the title from 'Create ' to 'Add New '

# Answer
> 16 votes
There are a few different ways you could do this, but the way you asked for would utilize hook\_form\_alter():

```
<?php
function custom_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'mynodetype_node_form') {
    drupal_set_title('My new title');
  }
}
?>

```

This would be in a custom module named custom.module... drupal\_set\_title(), when called anywhere in the page load, will set the title appropriately. You're basically hooking into the node form rendering process, and saying 'set the title to what I want' at that point.

If you'd like to further differentiate what the title would be depending on whether the user's creating a new node or editing an existing node, use Devel module's dpm() function to print out the $form\_state array, and check to see if there's a node ID already or not—if there is, you are editing a node; if not, you're creating a new node. Set the title appropriately.

While hook\_form\_alter() would probably be the most robust page (in case someone was viewing the node add form from somewhere other than node/add/\[type\]), you could also check the path in hook\_init() and set the title there, or from a variety of other places (in Drupal 7, hook\_page\_alter() perhaps).

# Answer
> 4 votes
I had the same problem and I had to write a module for that.

You can find my contributed my module Node Add Title for Drupal 7

> Node Add Title will let you change the title of the node creation pages and the node editing pages.

Hope it can help.

---
Tags: hooks, 7
---


# Question
Title: How to use ajax_command_invoke() with an argument that's a JavaScript object?
I'd like to use `ajax_command_invoke()` to enable jQuery UI Droppable when returning from an AJAX request.

If I run the following command from the JavaScript console, jQuery UI Droppable is properly enabled:

```
jQuery('.elements-to-make-droppable').droppable({
  drop: function( event, ui ) {
    jQuery( this )
      .addClass( "ui-state-highlight" )
  }
});

```

However, when I try to return this command from my AJAX callback:

```
$commands = array();
$commands[] = ajax_command_invoke('.elements-to-make-droppable', 'droppable', array('{
  drop: function( event, ui ) {
    jQuery( this )
      .addClass( "ui-state-highlight" )
  }
}'));
return array('#type' => 'ajax', '#commands' => $commands);

```

...it doesn't work.

How should I be doing this?

# Answer
> 2 votes
I solved this by creating a little jQuery Plugin that calls `droppable()`, and using `ajax_command_invoke()` to call my plugin.

In the PHP code that builds the page, I added:

```
drupal_add_js(drupal_get_path('module', 'my_module') . '/my_module.js');

```

In `my_module.js`, I added:

```
jQuery.fn.my_module_make_droppable = function() {
  jQuery(this).droppable({
    drop: function(event, ui) {
      jQuery(this).addClass( "ui-state-highlight" );
    }
  });
}

```

And my AJAX callback is now:

```
$commands = array();
$commands[] = ajax_command_invoke('.elements-to-make-droppable', 'my_module_make_droppable');
return array('#type' => 'ajax', '#commands' => $commands);

```

# Answer
> 1 votes
See also: https://drupal.stackexchange.com/a/73738/17676 -- instead of writing new jQuery functions, you can also use events and triggers.

---
Tags: 7, ajax, javascript
---


# Question
Title: Image not found --> creates a path that doesn't exists
I'm trying to make a gallery with the Galleria module. I did everything that the install guide said (module readme) and got the module to work, one time, but then when I went to my front page and back to the gallery I got the following.

I looked in my field setting and didn't create a sub directory. Then, I checked my "File system" configuration and the public path is said to be sites/default/files.

I have no clue why it needs the other directories or where it gets that path from.

Is there someone who could explain this?

# Answer
> 2 votes
When you install Galleria, it creates the image style presets it requires, which you can find under **/admin/config/media/image-styles**.

If you view the images, imagecache will create the image types and store them in the file system under the appropriate direcory so they will not have to be re-created. If your file system does not have the correct permissions, the directories and files cannot be created, and the images cannot be found.

Check your logs for error messages (**/admin/reports/dblog**). If this is the case you need to make sure that the directory tree has the correct ownership (usually apache.apache) and the correct read.write permissions (664). If you have access to the server, use the `chown -R apache.apache *` and `chmod -R 664 *` commands to accomplish this.

Once you have verified the permission, galleria should work correctly.

---
Tags: 7, uri, media
---


# Question
Title: Boosted Varnish for Drupal - what to do with "Control: no-cache" headers?
Per the following article http://www.trellon.com/content/blog/boosted-varnish-high-performance-caching-made-easy#comment-8150 we're attempting to use Boost and Varnish on our Drupal 7 site.

As for why we want to use Boost and Varnish, it is to limit the impact of restarting/clearing the Varnish cache.

Anyway, when we install Boost and go to the status report page (/admin/reports/status), there is a message which states:

> Boost will not function properly while Drupal core cache is enabled. Disable Boost or the core cache.

So we disable the core cache. When we do that the following HTTP header gets set:

> Cache Control: no-cache, must-revalidate, post-check=0, pre-check=0

We re-enable the core cache and the headers read as:

> Cache Control: public, max-age=900

As I understand, a cache control header of no-cache tells upstream proxies like varnish "you aren't allowed to cache this."

So essentially we have a dilemma: Boost requires core cache to be disabled, but disabling core cache makes the site un-cacheable by Varnish.
Leave core-cache enabled and Boost won't work.

How do we get them to play nice together? In other words, how can we disable the core cache to make Boost happy but not have the no-cache header set?

# Answer
> 1 votes
drupal\_add\_http\_header() in your own module will allow you to override Drupal's headers.

Not that it's needed - your headers will only be set to no-cache when you hit Drupal directly. Not for boosted statics. It is a good thing. You want to keep HTML from boost in varnish, after all, not the one generated directly.

I'm proposing to leave it be. Files from Boost cache will not generate these headers, so will be cacheable for varnish. You will only skip caching pages generated on direct Drupal hits. But you want to skip them. They may contain messages, for example. Boost does not cache when there are errors and messages, so leaving no-cache in Drupal will let you to use this behavior and make varnish respect it.

---
Tags: caching, proxies
---


# Question
Title: What is the purpose of the Version Control API module?
We are relatively new to Drupal development and are investigating various tools that can assist us with some upcoming projects.

The Version Control API module seems interesting, especially since it's semi-official. I think we have some confusion regarding it's actual purpose, however.

See the link here: http://drupal.org/project/versioncontrol

Assuming we get this configured properly with a git backend, how does this change our workflow while developing with Drupal? Will resources that we add to the website (such as graphics and html) be added to git source control automatically? Does this git source control replace the existing Drupal "revision" feature?

Any additional information or real-world examples of how to use this module would be appreciated.

# Answer
> 0 votes
Documentation, as Clive pointed out, provides good technical explanation. For those who need more "human-readable ones": Every time you download module from Drupal.org or any Drupal page, use issue queue or in any other way interacts with module or theme version, you are using Version Control API or other module with the same purpose.

---
Tags: version-control
---


# Question
Title: Where are the pages for the Statistics module shown?
I've installed the Statistics module (version 7.18) in my Commerce Kickstart 2 store, but I can't find it anywhere in menu.

What should I do to access this module?

# Answer
> 3 votes
After enabling the statistics module, be sure to configure the module (admin/config/system/statistics).

The documentation for the statistics module indicates that:

> To enable collection of statistics, the Enable access log checkbox on the Statistics settings page must be checked. This access log is used to store data about every page accessed, such as the remote host's IP address, where they came from (referrer), what node they've viewed, and their user name. Enabling the log adds one database call per page displayed by Drupal.
>
> The Discard access logs older than setting on the settings page specifies the length of time entries are kept in the log before they are deleted. This setting requires a correctly configured cron maintenance task to run.
>
> Enable Count content views to turn on and off the node-counting functionality of this module. If it is turned on, an extra database query is added for each node displayed, which increments a counter.

After configuration, data will begin to be collected for the four reports that statistics provides:

* Recent hits (admin/reports/hits)
* Top Pages (admin/reports/pages)
* Top Visitors (admin/reports/visitors)
* Top Referrers (admin/reports/referrers)

*NOTE:* This applies to all Drupal 7 installations. Statistics is a core module and is not specific to Commerce Kickstart 2.

---
Tags: nodes
---


# Question
Title: How do I set variables for variable_get()?
I am trying to understand `variable_get()`. I read so far that you can set variables in the settings.php using the `$conf` array and retrieve them later in code by using `variable_get()`. I have read that you can also use `variable_get()` to retrieve values from the database.

How does this work?
Is there a table that is automatically built?
How would you set variables if this feature is possible?

# Answer
Maybe you hope to learn that variable\_set is the magical way to store all kinds of structured data in your database, and that variable\_get is the way to get it out again. Unfortunately, it is not.

The "persistent variables", as they are often called, are meant for relatively simple key-value pairs that should persist across requests, users and sessions, often until a site admin changes the value. A good example is the site name.

*So how does it work?*

When Drupal is bootstrapped, all variables are read from the cache (if available) or from the variables table. (See variable\_initialize for the exact code.) The variables and stored in the global `$conf` variable, a huge array. Drupal does this because it's more efficient than doing a database query every time a variable is needed. (It's also the reason why variable\_set is not suitable for large blobs of data: they would be loaded on every request!)

Whenever you use `variable_get('variable_name', 'default_value')`, the variable name is looked up in the $conf array. If it exists, the value is returned; else, the default value is returned.

Finally, there is a third member of the family: variable\_del. As the name implies, this deletes a variable from the variables table. This function is often used in hook\_uninstall implementations, deleting variables when a module is uninstalled.

If you are looking for ways to store more complex custom data structures in the database, check out hook\_schema and drupal\_write\_record, or use the Drupal entity system and Entity API.
> 25 votes

# Answer
If you are using Drush (strongly recommended), you can issue `drush vget > variables.txt` from the command line to create a text file with a list of all current variables and their values. Similarly, you can use `drush vset` to change set any variable to a different value.

See GitHub for more details about `variable-get`, `variable-set`, and other useful commands.
> 6 votes

# Answer
To set variables, you would use variable\_set(). Then you can retrieve them using variable\_get(). You should become familiar with the Drupal API site.

The variables, if stored, can be found in the variables table.
> 3 votes

# Answer
You can:
> 2 votes

---
Tags: configuration
---


title: Drush make and svn:externals

text:
# Question
Title: Drush make and svn:externals
I'm planning to use drush "make" function for my new D7 projects.

I would like to know if there is a way to detect, in my project, the repertories managed by "svn externals".

I mean, is "drush generate makefile" command, able to launch "svn propget svn:externals" function (by example), and store these properties in the generated .make file.

So it will "svn propset svn:externals" properties on "drush make" function call ?

Is there an option for that ? Thanks.

# Answer
> 0 votes
Make files allow you to connect to SVN repositories as sources for install profiles, modules, themes, and libraries. They do not, however, have built-in support for propget or propset.

Drupal repositories are all git based so I'm afraid SVN support is bulwarked to a bare minimum. See the drush\_make documentation for the supported SVN parameters.

As an aside, take a look at update Drupal using Drush with svn support for some other ways to incorporate Drush + SVN into your workflow.

*NOTE:* It sounds like you're using Drush 4.x and the drush\_make extension, so my answer is assuming that is true.

---
Tags: 7, drush
---