title: Get Menu Items in Custom Module

text:
# Question
Title: Get Menu Items in Custom Module
I'm creating a custom module block that will sit in the sidebar on certain levels of my site template.

The site structure is: Home \> Level 1 \> Level 2 \> Article.

I want Level 2 to echo out all of the child links (basically a menu tree).

I want to achieve this with `hook_block_view()`. How can I get the page's child links in the main menu, and put them in an array?

# Answer
Have you tried using Menu Block?

> provides configurable blocks of menu trees starting with any level of any menu.

It does exactly what you're looking for. If you still want to write a custom module I reckon looking through the code for that module would be the best place to start.
> 1 votes

---
Tags: routes, blocks
---


# Question
Title: Wysiwyg, ckeditor disappers when click "Add another item" button
I use Field collection modules to group image + textarea for multiple field group inputs. When I click "Add another item" button, ckeditor bar disappeared from the textarea.

I think there would be some errors occured on Ajax request for an iframe tag appeared at the bottom of the script.

This thing only happened when field collection group contains both image and textarea. Field collection with only textarea are fine.

The modules I use:
wysiwyg 7.x-2.1
ckEditor 3.6.4.7575
IMCE 7.x-1.5
File Field Sources 7.x-1.4
field collection 7.x-1.0-beta4

# Answer
I had this problem as well. This was fixed in http://drupal.org/node/1155678#comment-5358290 by adding a detach function to the WYSIWYG behaviors. You can apply the patch at the above link (that's what I did) or you should be able to download the 7.x-2.x-dev version (I haven't tested that) since it's been committed already.
> 1 votes

---
Tags: wysiwyg, files, entities
---


title: SImple Query Drupal 7

text:
# Question
Title: SImple Query Drupal 7
I am trying to create a simple static query just to see if the data exsits but I keep getting an error:

```
$result = db_query('SELECT * FROM field_data_field_product_id WHERE field_product_id_value = "mnbvcxz"');

if ($result->rowCount() > 0) {
  Do something
}

```

I get this error:

> PDOException: SQLSTATE\[42S22\]: Column not found: 1054 Unknown column 'mnbvcxz' in 'where clause': SELECT * FROM field\_data\_field\_product\_id WHERE field\_product\_id\_value = "mnbvcxz"; Array ( ) in validate\_product\_id\_form\_alter() (line 9 of sites/all/modules/validate\_product\_id/validate\_product\_id.module).

# Answer
> 1 votes
I'm not sure exactly why but it's got something to do with the double quotes in the query. Replacing them with single quotes makes queries of that nature run just fine.

You should really be using parameters rather than putting values straight into the query string though. `db_query()` accepts an array as its second argument to perform parameter replacement, and doing things this way means you don't even need to worry about quotes; PDO will take care of that for you.

Plus if you extend your query to accept that argument from a variable rather than a static string, you don't need to worry about SQL injection (again PDO will take care of it).

Your query would look like this:

```
$args = array(':product_id' => 'mnbvcxz');
$result = db_query('SELECT * FROM field_data_field_product_id WHERE field_product_id_value = :product_id', $args);

```

To offer another alternative, the preferred way of querying by field data is to use the `EntityFieldQuery` class. There are several benefits, possibly the most important being that it's storage engine agnostic - if you decide to move your field data to (say) MongoDB, the query will still work.

e.g.

```
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->fieldCondition('field_product_id', 'value', 'mnbvcxz');

$results = $query->execute();
if (!empty($results['node'])) {
  $matching_nodes = node_load_multiple(array_keys($results['node']));

  // Do something with those nodes
}

```

---
Tags: 7, database
---


title: Validation on textfield

text:
# Question
Title: Validation on textfield
I have gotten my validation module to kind of work, I have this:

function product\_id\_form\_validate($form, &$form\_state) {

```
if($form_state['node']->field_product_id['und']['0']['value'] == '123'){
    form_set_error('field_product_id', 'Product ID: is taken');
}

```

}

But when I change the value in field\_product\_id the value doesn't change upon save, it stays the same as when I first entered the form. Is there a function I need to call to say, when I click save look at this field again?

Thanks

# Answer
> 2 votes
Submitted values are stored in the `$form_state['values']` array so you need to test that instead:

```
if ($form_state['values']['field_product_id'][LANGUAGE_NONE][0]['value'] == '123') {
  ...
}

```

---
Tags: 7, forms
---


# Question
Title: CKEditor generates <br /> when leaving a textarea field empty
I'm using CKEditor module with satisfaction, but it behaves really frustrating in one case: **when leaving textareas empty, it generates `<br />` tags in them** after rendering CKEditor's interface.

This can be a problem for example when using *"Summary or trimmed"* display, and on the node creation form, the *Summary* field would be left empty, but in fact it's **not** empty, because it contains a `<br />` (so teaser will also contain a single `<br />`).

I can get round this problem with going to Source view and deleting the `<br />` tag all the time, but it's not a solution (other users will not know how to do it).

Do you have any ideas how to stop this behavior?

# Answer
There is an issue tracking this problem on drupal.org - http://drupal.org/node/550428. There is a patch in comment number 49 for it, hope it helps.
> 4 votes

# Answer
In `sites/all/modules/ckeditor/ckeditor.config.js`, add the following line at line 11, just below `CKEDITOR.editorConfig = function(config) {`:

```
config.fillEmptyBlocks = false;

```

You can have a look at CKsource's documentation for more advanced uses of this function. Why `config.ignoreEmptyParagraph = true;` is not sufficient is beyond my understanding, though.
> 2 votes

# Answer
Have you tried setting the `fillEmptyBlocks` CKEditor setting to `false`? In WYSIWYG you would do this with a hook:

```
function base_wysiwyg_extras_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['fillEmptyBlocks'] = FALSE;
  }
}

```

There's probably a CKEditor module way too. If there's not, you can always add settings directly with a custom CKEditor settings js file.
> 1 votes

# Answer
Perhaps a hook\_field\_presave can be used:

```
function mymodule_field_presave ($entity_type, $entity, $field, $instance, $langcode, &$items)
{
  if ($field[...] == ...) { // update for your case
    foreach ($items as $delta => $item) {
      if (isset($item['value'])) {
        $pattern = '/^\s*\<br\s*\/?\>\s*$/i';
        if (preg_match($pattern, $items[$delta]['value'] === 1) {
          $items[$delta]['value'] = '';
        }
      }
    }
  }
}

```

This is untested (esp the regex). You may also want to add in additional cases to handle just a `&nbsp`, just an empty paragraph, etc.
> 0 votes

---
Tags: 7, nodes, javascript, wysiwyg
---


title: Replace token by value in mail

text:
# Question
Title: Replace token by value in mail
I sent an email in a function.

My email body is like "Hello \[user:name\], blablablala -- Team \[site:name\]".

But the token aren't replace by their values in the email.

What's wrong ?

Cordially

# Answer
> 1 votes
You need to run token\_replace on the email body and pass in the user object for the target user. In your function: $global $user;

```
$emluser = user_load($user->uid);
$body = "Hello [user:name], blablablala -- Team [site:name]";
$body = token_replace($body, array('user' => $emluser));

```

You don't need to pass anything for the site tokens to be replaced.

---
Tags: emails, tokens
---


title: Multiple image sizes

text:
# Question
Title: Multiple image sizes
I have a very treaky question: how can I make an image to be downloadable in different sizes? This mechanism is required for my photogallery website.

Example:

image field

you can also download this image in:

2000x1000 - these are the links to a specific image size 3500x1500 4000x2000 resolutions

# Answer
You didn't mention which version of Drupal you are using, I'm assuming 7:

This is exactly what the image module in core does, it allows you to upload one image that it then can scale, crop and more. What it doesn't do is provide the links to download. I'd package this up into a small module (I couldn't find anything similar with a quick Google search) that defines the image styles using `hook_image_default_styles()`. You could then possibly create a field formatter that shows a thumbnail and then the links to different image sizes (you'd get the URL for each image style with `image_style_url()`.

Probably one of many ways of doing this but if you are comfortable writing code this could be a good way to go!
> 0 votes

---
Tags: media
---


# Question
Title: My page showing up with a title, but with the content div empty, but only for users
I've created a new content type that has the default 4 fields (Title, Body, Meta tags, URL path settings) and one List(integer) that I added. I called it "Basic page".

When I create a new Basic page node and put in some data, it will work as long as I'm logged in as admin. If I log in as any other user, the page title will show up, but the body will be blank.

The content div for a user is actually completely empty. The admin has content for it, but any other user does not.

```
<h1 class="page-title">New Test Page</h1>
<div class="region region-content">
  <div id="block-system-main" class="block block-system">
    <div class="content">
      <div id="node-2291627" class="node node-page clearfix">
        <div class="content"> </div>
      </div>
    </div>
  </div>
</div>

```

I've looked through the user permissions for this node type, and that doesn't seem to be affecting anything (though I could have easily missed something). The display isn't set to . I'm using Drupal 7.

# Answer
> 0 votes
It really sounds like a permissions problem. Do you (or did you) have field permissions installed?

If you do you will have to set field level permissions (which are separate) from node permissions. If you have field permissions viewing/editing a node does not mean a user can view/edit specific fields, you will have to specify these permissions in addition to the overall node permissions.

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


title: Setting Fields Using Rules

text:
# Question
Title: Setting Fields Using Rules
I couldn't find the answer at How to change a field value with a Rules Action?, so instead of necroing that I figured it would be better to ask here.

I have a Rule that, when a Taxonomy Term of a certain type is created, it creates a node of a specific type. I need the Rule to also have actions that edit a few fields of the node - there's a term reference field I need set to the Taxonomy term that triggered the event, and I would also like to set the body to some generic text (either the term name or "Lorem ipsum...").

I see no "Populate a Field" in the Populating a node reference field using PHP in Rules. I don't need the PHP filter, thankfully.

Is this possible?

# Answer
> 3 votes
The action you are looking for is "set a data value". You will find that some values are easy to set with this and some are not. Install devel (if you havent already) and use the page array functionality to get the exact details about fields you want to fill in. Also make sure to have tokens/entity tokens available as that will make your life a lot easier for setting values in rules. If the field is multi value then you will need to start using variables, lists and loops to fill the field with data.

---
Tags: taxonomy-terms, nodes, entities, rules
---


# Question
Title: How do you upload images to content other than articles
How do you upload images to content other than articles? I tried adding into the body of a block where I want a photo but it doesn't work. I've forgotten a lot of my html.

---

I'm doing something wrong. LEt's say, I want some sidebar blocks or even trtyptich blocks with an image in it. Do I start w/creating a view, a block, or an image that links to an article with the image and a caption showing in that block? That would help me immensely.

# Answer
Enter images into your content fields. On Add content type, go to "Manage fields," and under "Field type" select "Image." This will allow you to upload an image into that content type. If you want to add a referent to the image with `<img src="image URL">`, I suggest you switching from filtered HTML to full HTML as input format of the node body.
> 1 votes

---
Tags: media
---


# Question
Title: How to attach a list of fields to an entity
I have a node, and I'm looking to attach a list of fields to it. The number of fields should be dynamic. I realize I can create a new content type, and use entity reference module to build a list of related nodes, but I feel like that's overkill. I really just need to attach simple list (or list of fields). Is there a way to do this? or am I misunderstaning

# Answer
There are a few possible solutions to what I believe you are asking:

**Use a field collection.** http://drupal.org/project/field\_collection

It allows you to create a field containing a few fields of information and attach those to a node. I think it is most likely what you are after.

**A simple multi-value text field** The simplest option to attach a bunch of names to a node is just to set up a text field with unlimited values. Then you can add as many as you like. But I imagine that's simpler than what you need.

**Taxonomy terms** If the values need to relate to each other across the site, use a term reference field with unlimited values and allow your users to create new terms on the fly when they don't exist already.

**Content Type** If all of the names you need to add have additional data attached to them, you might need to go down the additional content type and node reference path you mention in your question.

I hope one of those ideas is what you after.
> 1 votes

---
Tags: 7, entities
---


# Question
Title: Contextual filter on Views Block file not found
I am trying to use a views block with a contextual filter for taxonomy terms to create an index that can filtered based on terms in the URL.

This works fine with a views page: so if the URL is /my-index then I see all the sub pages. And if the URL is /my-index/apples I see all the sub pages tagged with apples.

Now I when I make a block the same as the page view described, I understand that the block does not have a source for the contextual filter, so I have to provide a filter value. I have tried all the settings, but the problem seems to be that when using a views block and the URL is /my-index/apples I get a file not found error. With /my-index I get the full list as expected.

The filter works in preview mode, and if say I set the Default Value to Fixed Value=apples, is works at URL /my-index (filtered for apples as expected), but when URL is /my-index/apples then again I get file not found error. Then if I change the filter value to 'Display all results for specified field' I get the same result i.e. /my-index shows all and /my-index/apples gets file not found.

It seems to me that when the URL is /my-index/my-term it is not getting to the /my-index page to run the views script in the block. So I cannot connect the page URL to the block because I am not getting to the page at all when I add my-term to the URL.

I have set up a new alias for the page and tried new terms in case there is some sort of clash somewhere but to no avail.

The answers provided at Contextual filter with a block view did not seem to help. I tried every setting in every combination several times.

# Answer
I think you are just a bit confused about the structure of the page drupal creates so hopefully this might help to clarify it all.

When you create a page display in Views with a contextual filter, you basically are creating a menu item / path on your website. In this case, it's probably something along the lines of my-index/%, with the % being the contextual filter.

You then define that filter to be a tax term. So, you can then type in www.yourhost.com/my-index/foo and www.yourhost.com/my-index/bar and www.yourhost.com/my-index/baz and get the $content of those pages filled with the fields of the view you created filtered by foo, bar, or baz.

Or any other term a user puts in in place of the %.

This way you aren't creating umpteen individual views, eg, you don't have to create my-index/foo, my-index/bar, my-index/baz, etc etc page displays for each and every possible tax term.

Plus if you say show me everything if the contextual filter is missing, then you can also go to www.yourhost.com/my-index and get a list of everything.

Now to blocks. These aren't the main $content of your page, but rather little boxes of additional information off to the side. They can be placed pretty much on any page you want through the block admin pages, you just go in there and tell it what region you want and pages and off you go.

So, in this case, let's say you created a page display called my-index/% like the above. In this example, let's also say that this view lists the content on your system sorted by Title. So, in the main content area of this page you'd have that listing of your content tagged with that tax term sorted by title.

But let's say you wanted a block off to the side listing the very latest content tagged with that same tax term.

Here, you would create a block display of content sorted by creation date in descending order and limited to 1 item. Here you would also add a contextual filter, but in the supply the default argument, you would tell it to take it from the url and specify where it is, in this case the 2nd argument.

Then you'd save everything and go to the block admin page and down in the list of blocks available you'd see this View Block. Assign it to a region in your theme and then in the pages, restrict it to my-index/\* and then it will show up on that page along with your main content.
> 1 votes

---
Tags: 7, views
---


# Question
Title: How to show the content on ajax or Jquery lightbox
I have created views custom template file for one of my view and works fine. And how can i show fields content(second in the below code) on Lightbox popup box when the user clicks on title field.

```
 <?php dpm($fields); ?> <div id="cusom-template-flower-fields"
 class="title">   <?php print $fields["title"]->content; ?> </div> <div
 id="cusom-template-flower-field_availability"
 class="field_availability">   <?php print
 $fields["field_availability"]->content; ?> </div>

```

# Answer
You should describe the problem you are facing ... What 'lightbox-meme' are you trying to implement ?

If you are using the lightbox module for drupal, you should read the README.txt, that is pretty self-explanatory.

Hope this helps.
> 1 votes

---
Tags: ajax, javascript, theming
---


# Question
Title: Sort an entity query by a term reference field's term weight?
I've created an entity query to get an array of nodes based on a specific content type,see below:

```
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->entityCondition('bundle', 'article');
$query->propertyCondition('status', 1, '=');
$result = $query->execute();
$nodes = node_load_multiple(array_keys($result['node']));

```

The node content type `article` being queried has a Term Reference field (list of tags). Each taxonomy term is sorted via the `admin/structure/taxonomy/tags` administration screen.

I have the requirement to have the nodes sorted by term weight. For example the nodes that reference the highest weighted taxonomy term will be at the top.

Is there a way to add a relationship to the taxonomy table using EntityQuery, or is there another way to do this?

# Answer
Since the weight is kept in a different table than the one that stores the data related to your node, I'm afraid this is impossible using EntityFieldQuery. You'll have to do some custom coding after the query.

By the way, to use data from the reference field (field\_data\_your\_reference) you could use a fieldCondition or fieldOrderBy.
> 2 votes

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


title: Download all files from webform

text:
# Question
Title: Download all files from webform
I need to download a zip with all attached files from a webform.

Is it possible?

# Answer
> -1 votes
Webform stores all these files in sites/default/files/webform you can download them with FTP.

---
Tags: 7, webforms
---


title: Views php field table sorting error

text:
# Question
Title: Views php field table sorting error
I have a taxonomy view with table list and I insert my code into a global php field and use enable click sort: sort numerically, but when I click the label to sort numerically I always get the error below.

```
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /stocks/views/ajax
StatusText: OK
ResponseText:
Fatal error:  Function name must be a string in C:\xampp\htdocs\stocks\sites\all\modules\views_php\plugins\views\views_php_handler_field.inc on line 185

```

Whats causing this and is there a way to fix it? Im trying to have the field sort by highest number to lowest.

This is the code I am using in the php field.

```
<?php
$currentMonth = date('n');
    $currentMonth = $currentMonth - 1;
    $prevcurrentMonth = date('n');
    $prevcurrentMonth = $prevcurrentMonth - 2;
    $currentDay = date('j');
    $lastDay = $currentDay - 6;
    $currentYear = date('Y');

    $file = file_get_contents("http://ichart.finance.yahoo.com/table.csv?s=$row->name&a=$prevcurrentMonth&b=$lastDay&c=$currentYear&d=$currentMonth&e=$currentDay&f=$currentYear&g=d&ignore=.csv");

    $stockcontent = str_replace('Date,Open,High,Low,Close,Volume,Adj Close', '',  $file);
    $stockcontent = trim($stockcontent);

    $stockcontentex = str_getcsv($stockcontent, "\n");

    $stockex = explode(',',$stockcontentex[0]);

    print $stockex[2];
?>

```

# Answer
> 2 votes
Review this post

You will find there is a value box and a output box.

Your code above suggest you are doing the display from the value box and that won't work.

move most of your code to the value box and then end with:

```
value = $stockex[2];

```

then paste

`<?php
 print $value
 ?>`

in the output box.

Good Luck!

---
Tags: 7, views
---


# Question
Title: Should I disallow drupal path or alias by robots.txt?
I have 2 languages enabled on my site English and Japanese.

Japanese is the default and English has prefix "en".

I want search engines to crawl one View page only in Japanese.

So I decided to use `Disallow: /en/my-view/*` in robots.txt but my-view has alias.

Should I use `Disallow: /en/my-view/*` or `Disallow: /en/alias-my-view/*` ?

# Answer
> 1 votes
You should add both paths, as both of them are accessible.

However, I recommend installing Global Redirect plugin. It will permanently redirect your internal path to the alias (if any). This way you only have to add one path to your robots.txt.

---
Tags: views, 6, path-aliases
---


title: Custom module visible only for one user

text:
# Question
Title: Custom module visible only for one user
EDIT:

14:38 PM Amsterdam :P

Nice to see that good people help !...

What I trying to do:

This is the whole prototype code.

```
function oleg_menu() {

    $items=array();
    $items['user/%user/pgacademy/tests'] = array(
        'title' => 'OLEG',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('oleg_nameform',1),
        'access callback' => TRUE,
        'type' => MENU_CALLBACK,
    );
    return $items;
}

function oleg_nameform($form, &$form_state,$accoundID) {
     $form=array();
     dpm($accauntID);
     return $form;
}

```

The page even doesn't appear... Can someone explain me why it fails,or what could be the problem ? Oleg

# Answer
> 1 votes
What indrock says in the comments is right, you should be using a placeholder like `%user`.

But you'll also need to pass the argument through to the form callback like so:

```
function my_module_menu() {
  $items['user/%user/foo/bar'] = array(
    'title' => 'My Title',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('my_module_nameform', 1),
    'access callback' =>array('user_is_logged_in'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

```

The signature for `my_module_nameform()` would be:

```
function my_module_nameform($form, &$form_state, $account)

```

`user_is_logged_in()` doesn't accept any parameters so there's no need for the `access arguments`. Again as indrock says, clear the caches whenever you make a change to the hook implementation.

---
Tags: 7, users, caching
---


# Question
Title: Executing a Rule on a user(s) selected from a list
I have created a user reference field on a node which lists (via Views) all the users the node author is related to in some way. If there is a better way to list users on node forms then I'm open to suggestions. In my particular case the field uses the autocomplete widget with the Views list, but a select list widget could also be used.

I would like to be able to execute a Rule on the user that is selected in the autocomplete/list by the node author. At the moment I am using the Button Field to trigger the Rule execution but I'm not sure how to get the Rule to apply to the specific chosen user. Some ideas are flagging the user when they are selected or doing a textual comparison between the autocomplete text and existing usernames. I have also tried the Relation module but still can't figure out how to get the selection recognized in Rules.

# Answer
> 1 votes
It sounds to me like you need to fetch the user as an entity in Rules, if you have multiple users use a loop. After this you should be able to apply the relevant action. Here is a stab at the Rule (note, this is untested but should point you in the right direction):

Event
\- (Whatever trigger/s you want here)

Condition
\- Entity is of type: Node
\- Entity has field: (pick the user reference field here)

Action
\- Loop(for multiple users)
\- (Final action you want to take place. Add the new variable here)
Hope that makes sense. See how you go with this and let me know.

---
Tags: views, rules, users
---


# Question
Title: How do I add custom CSS to individual pages?
Im trying to create pages with a search bar in a specific non block area in Drupal 7. If I edit using Live CSS (or another module), it edits all my pages, and offsets the content I created. I need a way to edit the CSS styles for each individual page; in that way, I can edit the search form area, and have also a way to add my own button images.

I can disable Drupal regions/blocks, but that doesn't really help. May someone name some modules that could help, or suggest me some code?

# Answer
> 4 votes
Well the absolute simplest way is to look at the body class using firebug or developer tools with chrome.

You will see something like this:

```
<body class="html not-front logged-in no-sidebars page-node page-node- page-node-19 node-type-log-node admin-menu">

```

Which as you can see even has the node id for the page. Then its just a simple case of using

```
.page-node-19 {
background: #000000;
}

```

Or whatever!

And, if you want to get super in detail with adding stuff to certain pages, themes, regions, dependencies on which users etc etc then look into the context module and all its related modules.

# Answer
> 2 votes
The Context module, combined with the Panels module can be of great help.

You can hack also the master template a bit, inserting if/else statements, but hacking should be avoided as much as possible.

---
Tags: theming, search, 7
---


title: Notifications vs Subscriptions?

text:
# Question
Title: Notifications vs Subscriptions?
I have enabled both modules for D6 but I'm going to disable one to tidy up my Drupal stack. So wondering what are exactly the differences between the two modules, in terms of functionality. Are they interchangeable for basic task of allowing users to subscribe to posts and send notification updates? If so, which one is preferred?

P.S. there is relevant thread here some other people may find useful.

Thanks

# Answer
> 3 votes
I have successfully used notifications on 2 Drupal 6 sites. I like it. Subscriptions had a good reputation but Notifications looked to be more modular and extensible; however, what tipped me towards notifications was the fact that it seemed that the Organic Groups developers were keen to support it and I was looking at putting OG onto my sites (which I subsequently did)

I have the 6.x.2 version of notifications, which seems stable and does what I want. Very limited experience of the 6.x.4 version suggested it was not stable so I did not persist with that and it remains in beta after 2 years.

Now I have recently been involved in the development of a Drupal 7 site. Although it is over 18 months since D7 was released there is no full Notifications version yet and the module is flagged as Seeking new developer and has been for a significant length of time. Apparently a quick upgrade was done when Dr7 was released with some limited functionality (what though?) and there is an Alpha2 version which seems to have been receiving some considerable attention (but last updated June).

On this basis, you might be safer to go with Subscriptions which now has a full Dr7 release if you have any thoughts of migrating to Dr7 or developing other sites that might use Dr7. That is mainly to avoid the difficulties in mastering two admin UIs and to protect you in case Notifications really is moribund.

Subscriptions is in the hands of a very experienced developer who has been maintaining it for a long time.

Please note that I have not done a systematic comparison of Subscriptions and Notifications for Dr6 though I did spend quite a while investigating the two at one time several years ago. See my contribution here: http://groups.drupal.org/node/12645 (This contains contributions by many others and is useful for an insight into the position in 2008! But Subscriptions and Notifications will both have been enhanced since those posts were written).

---
Tags: notifications
---


title: How do I install a patch file?

text:
# Question
Title: How do I install a patch file?
I was trying to google the method to install a patch file, but the results keep returning as "issues encountered while patching", which isn't what I am looking for.

I was wondering how to use drush to install a patch file?

More specifically, I'm currently encountering a Drupal for Facebook module issue, about the q variable.

One of the answers suggests installing a patch file. How do i install this patch file from the command line?

# Answer
The instructions on how to apply a patch are given, for that module, on http://drupal.org/project/fb/git-instructions.

First off, git patches can be applied to a git repository you need to locally clone, which means you need to execute the following command:

```
git clone --recursive --branch master http://git.drupal.org/project/fb.git

```

Then you copy the patch in the fb directory created from the previous command, and execute the following one:

```
cd fb
git apply -v fb_stream.admin_.inc_.patch

```

Once the patch is applied, you delete it.

```
rm  fb_stream.admin_.inc_.patch

```

This assume the patch is applied to the development snapshot. If this is not the case, then somebody needs to provide a patch for the development snapshot.

Anyway, the patch doesn't apply. If you try applying it, you will get the following error:

> Checking patch Users/johnrobens/Downloads/fb/fb\_stream.admin.inc... error: Users/johnrobens/Downloads/fb/fb\_stream.admin.inc: No such file or directory

You need to change the patch to the following one, to avoid that error.

```
--- fb_stream.admin.inc
+++ fb_stream.admin.inc
@@ -1,5 +1,6 @@
 <?php

+
 /**
  * Form callback for general settings.
  */
@@ -19,7 +20,8 @@
             '%user_name' => $from['name'],
             '%token' => $token,
           )));
-    } catch (Exception $e) {
+    }
+    catch (Exception $e) {
       fb_log_exception($e, t('Unable to query graph with fb_stream token.'));
       drupal_set_message(t('There was an error using the current access token, %token.  Consider generating a new token.', array(
             '%token' => $token,
@@ -29,7 +31,7 @@

   if (!empty($_REQUEST['code']) && empty($_POST)) {
     // Send user to this URL after token is generated.
-    $redirect_uri = url(request_path(), array(
+    $redirect_uri = url($_REQUEST['q'], array(
       'absolute' => TRUE,
       'query' => array(
         'client_id' => $_REQUEST['client_id'],
@@ -59,7 +61,7 @@
   );
   foreach (fb_get_all_apps() as $fb_app) {
     // Send user to this URL after token is generated.
-    $redirect_uri = url(request_path(), array(
+    $redirect_uri = url($_REQUEST['q'], array(
       'absolute' => TRUE,
       'query' => array(
         'client_id' => $fb_app->id,
@@ -92,7 +94,7 @@
       'client_id' => $app_id,
       'client_secret' => $fb_app->secret,
       'code' => $code,
-      'redirect_uri' => $redirect_uri,
+                  'redirect_uri' =>$redirect_uri,
     ),
       ));
   $http = drupal_http_request($path);

```

Even if you do that, you would get the error, "patch doesn't apply." I tried applying it to the development snapshot 7.x-3.x (the master branch for git).
> 5 votes

# Answer
Here's really good explanation of applying patches with git. If you haven't got git installed there's some links to instructions for various different platforms here.

Beyond that, make sure you are patching the correct version of the code otherwise you may get errors when applying the patch.

Some more general info on git can be found in the Pro Git book.
> 1 votes

# Answer
Without details regarding your environment, patching details would be very difficult to give and would likely not be appropriate for drupal.stackexchange.com. Drupal has a bit of documentation though that my lead you in the right direction.

http://drupal.org/patch/apply

In the simplest form using patch `patch -p1 < path/file.patch` or if you use git `git apply path/file.patch`
> 0 votes

---
Tags: 7, drush
---


# Question
Title: Drush Segmentation fault when upgrading from Drupal 6 to Drupal 7
I am running `drush -vd updb --yes || exit 1` to upgrade D6 to D7 then I got this error several times atleast.

```
Bootstrap to phase 0. [0.01 sec, 4.79 MB]                            [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.01 sec, 5.08 MB] [bootstrap]
Cache HIT cid: 5.0-commandfiles-0-eae08ebb5299072299ae95f485024c57 [0.02 sec, 5.09 MB]                                                                                [debug]
Bootstrap to phase 0. [0.06 sec, 11.02 MB]                                                                                [bootstrap]
Bootstrap to phase 2. [0.08 sec, 11.03 MB]                                                                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.09 sec, 11.03 MB]                                                                                [bootstrap]
Initialized Drupal 7.14 root directory at /var/www/vhosts/git/html [0.12 sec, 15.06 MB]                                                                                [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.12 sec, 15.07 MB]                                                                                [bootstrap]
Initialized Drupal site default at sites/default [0.12 sec, 15.07 MB]                                                                                [notice]
Cache MISS cid: 5.0-commandfiles-2-d0694fde84f442a7d33c2119cff575f2 [0.13 sec, 15.07 MB]                                                                                [debug]
Cache SET cid: <em class="placeholder">5.0-commandfiles-2-d0694fde84f442a7d33c2119cff575f2</em> [0.27 sec, 15.09 MB]                                                                                [debug]
Found command: updatedb (commandfile=core) [0.28 sec, 16.05 MB]                                                                                [bootstrap]
Segmentation fault

```

Any idea what is segmentation fault is?

# Answer
> 5 votes
Drupal is *very* sensitive to the order you do things when doing a major system upgrade. You must follow the instructions in UPGRADE.txt exactly; in particular, if you run updatedb just once, after upgrading your core and all of your contrib code, then the upgrade is sure to go wrong. The symptoms can vary; I would expect that this is probably what is causing your segmentation fault.

If you look at the UPGRADE.txt instructions closely, you will see that you need to run updatedb on core only, with no contrib modules enabled; after that, you must upgrade your contrib modules one at a time, upgrading their code and then running updatedb for each one. If a module that has a schema in the database has update hooks that need to run, then updatedb will run them, even if the module is not enabled, so you must be extremely exacting in your code management, or the upgrade will fail. It is also critical that you upgrade your modules in the right order, because a module will clearly need to have its dependencies available in order to successfully complete its updatedb processes. If you have a lot of modules, this process can be extremely tedious.

The Drush Site Upgrade command can be used to automate this process to a large degree. There are still some things that you need to do manually, but it will walk you through the UPGRADE.txt instructions one step at a time, offering to do most of the steps for you automatically. It will even give you advice about replacement modules for some contrib projects not available in D7, and will run the content migrate code to insure that you CCK content gets upgraded too.

If you go through all of the steps faithfully, and you are still getting a segmentation fault, it could be that your system is running out of memory. Adjust your settings in php.ini to adjust. If this still doesn't work, you could be encountering a bug in a contrib module. When this happens, you can try asking for support in the issue queue of the particular module that is causing you problems. If this does not get you anywhere, your final resort is to build a new Drupal 7 site from scratch using similar modules, and migrate your data using Drupal to Drupal migration. In the futue, Drush Site Upgrade will also support the d2d upgrade path, but for now you'll need to do it manually.

**Postscript:** Understanding what a segmentation fault is is not really important to solving your problem, but there is a good definition on Wikipedia here: http://en.wikipedia.org/wiki/Segmentation\_fault.

---
Tags: 7, drush, upgrading
---


title: Query with multiple where clause

text:
# Question
Title: Query with multiple where clause
I have a query that works fine with one where clause however when I add AND it doesn't work, can someone please tell me what I'm doing wrong?

```
$args2 = array(':name' => $existingproductIDfield);
$args3 = array(':vid' => '6');
    $result2 = db_query('SELECT * FROM taxonomy_term_data WHERE name = :name', $args2 .'AND vid = :vid', $args3);

    if ($result2->rowCount() > 0) {
        foreach($result2 as $row) print_r($row);

    }

```

# Answer
Parameter replacement is done all in one go, and you just need to provide a single associative array of args to `db_query()` for those replacements:

```
$args = array(':name' => $existingproductIDfield, ':vid' => 6);

$result2 = db_query('SELECT * FROM taxonomy_term_data WHERE name = :name AND vid = :vid', $args);

```
> 6 votes

---
Tags: 7, database
---


# Question
Title: How do i specify a style for a single exposed filter?
I have a View where i show some exposed filters; i would like to apply a particular CSS class only to a specific exposed filter. I have seen that if i copy the views-exposed-form.tpl.php inside my theme directory and call it views-exposed-form--MYFORMNAME.tpl.php i can control the html code; i don't think it s a good thing to put code with

```
 if($widget->id==MYID) {}

```

inside the template ... which is the correct way to assign a style to an exposed filter?

# Answer
> 1 votes
Not sure if you need the template for other reasons, but you can style it directly with CSS, using the ID. See screenshot. I happen to be using Better Exposed Filters module, which provides some nice extras controls.

---
Tags: 7, views
---


title: Dynamic menu links using menu token

text:
# Question
Title: Dynamic menu links using menu token
I'm trying to build a menu which has *term id(tid)* token in it to the views pages I have created. Menu links work when on `taxonomy/term` page but when menu links are clicked and url is changed to the *views page*, menu token can't get *term id(tid)* from that page, so menu links don't work. Basically menu structure is like this;

*Menu on taxonomy page*:

```
   views page 1 (url: /project/%1/venues) menu path: /project/[term:tid]/venues
   views page 2 (url: /project/%1/program) menu path: /project/[term:tid]/program

```

Contextual filter used: taxonomy term id from url where `%1` is term id.

# Answer
> 1 votes
If I understand your scenario correctly, have a look at the Taxonomy Menu module. This is what I use to create dynamic views, where the display is dependent on the menu item clicked.
(The menu passes in that value -- e.g., city name -- as an `Argument/Contextual-Filter`.)

**Taxonomy Menu:**

* Custom Menu per vocabulary.
* Uses the default taxonomy term path or custom paths.
* Integrate with Views.
* Integrate with Pathauto: use URL/path aliases.
* Does not interfere with other menu modules.

---
Tags: routes, navigation, tokens
---


title: Create related nodes to specific node

text:
# Question
Title: Create related nodes to specific node
I am using Drupal 7.

In one of my requirements i need to create related node to specific node.

For ex. I have created a node of content type "article". For particular node of "article" node

say nid:9 then i would like to add related node to this node.

So when i view nid:9 at that time it should also display related nodes, and also when i view the newly created node, at that time nid:9 should be displayed in related node display

So both nodes should be displayed vice versa in each others detail view.

# Answer
Create a node reference field. See:
> 1 votes

# Answer
There's quite a few modules that relate two (or more) nodes together, Entity Reference and Relation are both popular.

I'd probably recommend the Entity Reference module as that comes with a couple of field formatters that display the referenced entity. If you used the Relation module you'd probably have to build a fairly complex view with contextual filters and relationships - this screencast series should help with that.
> 1 votes

---
Tags: nodes
---


# Question
Title: How can I do an OR operation on the values of a solr field?
Say I have a facet on countries, I'd like to be able to click on more than one country (say US and UK) and get results tagged "US" OR "UK".

Currently If I click on "UK" on the facet block, the other terms disappear if this was a "single solr field".

And if it was a multi-valued solr field, the other terms don't disappear but an AND operation is done.

How can I change the default behavior to allow OR operation on both "single" and "multi-valued" solr fields?

I'm using the Apache Solr Search Integration module version 1.6.

# Answer
Can't say for sure if this is in 1.6 but if you configure the country facet block you'll get the option to use AND or OR inside the facet.
> 0 votes

# Answer
Have you checked this documentation page

http://drupal.org/node/1159424

I have not tried it but just came across it.
> 0 votes

---
Tags: 6, search
---


title: Adding pagination to nodes

text:
# Question
Title: Adding pagination to nodes
I'm using Drupal 7, CKEditor (not wysiwyg module). By default the nodes are not paginated but the client wants to have nodes of certain content-type to be paginated. And wants control of this pagination i.e. set page breaks.

How can I make the nodes to paged? And how can I control it?

P.S. I cannot find any useful explanation (tutorial) of how drupal pager works, so if you know any, it's highly appreciated to post it here.

# Answer
> 1 votes
If you are using Drupal 7 you should check out the smart\_paging module. It can auto paginate or the user can sepecify the breaks. There is also integration with the WYSIWYG module, but unfortunately not the CKEditor module.

As mentioned by Greta the core book module may be of use, but it is really intended for content organized in a hierarchical manner. If the nodes are intended to be independent (e.g. articles), it would be overkill to have to make a new book for each article.

Good luck.

# Answer
> 1 votes
It is incredibly easy. Use BOOK content type. Just need to enable Books in core modules. If you already have lots of existing content (to much to copy/paste into book pages), you could add a field for Node Reference and link the pages that way. Book has all that "pagination" functionality -- as well as local menu/index -- built in. Great solution if you aren't too far along. At the very least, enable Book module and do a sample to demo for client -- to help you conceive the exact behavior that you want.

By the way, that approach is independent of your WYSIWYG (CKEditor).

---
Tags: paging
---


title: Error 500 only on permissions page

text:
# Question
Title: Error 500 only on permissions page
I know that there are a lot of topic concerning the famous *error 500* but i didn't find my answer in one of them.

Actually i have an error 500 when i load `admin/people/permissions` or when i'am trying to save new permissions. It's not all the time but i will say that it happens 80% of the time. This permission page is very slow to load and when i haven't this error, it takes my navigator between 30s to 1m to display it.

I used google developper tools for this page and the result of the audit was:

`36 requests ❘ 138.40KB transferred ❘ 27.57s (onload: 27.27s, DOMContentLoaded: 25.58s)`

**I edit my post and follow the trick that gave me H.NiK and i have impressive result for now**

`38 requests ❘ 17.09KB transferred ❘ 2.34s (onload: 1.76s, DOMContentLoaded: 1.42s`

I have a lot of fields on the permission page more than 150 i think (because of the module fields permissions).

I watch the log of my server and i just have the same information:

`Premature end of script headers: index.php, referer: http://blabla.com/admin/people/permissions`

I have 25 lines of this today on this page.

Have you any idea why i have this error only appears on this page?And maybe how i can track this error and resolve my problem? Is it possible that a module or a js file trigger this error?

ps: i'm on a shared hosting, so i can't touch any configuration on my server (php.ini,my.ini)

Thanks,

# Answer
> 2 votes
Because you are on shared hosting the PHP process may not be given enough memory. If you have a complex site or page the drupal bootstap may run out of memory and fail. I have had this problem trying to run a heavy site (one of the more Drupal complex distributions) on a shared host. I would take a quick peak at how much memory is given to a PHP process (and Drupal) by visiting `admin/reports/status` and look for the "PHP Memory Limit". I typically use 128M on a complex site.

You said also you can't edit you php.ini file - are you certain? Many shared hosts allow you to to override the global php.ini file with one in your account. Most will have a wiki explaining how configure such overrides. If not you may need to move to a different host.

# Answer
> 0 votes
Try the Filter permissions module.

> This module provides filters at the top of the Permissions page for easier management when your site has a large amount of roles and/or permissions.

---
Tags: 7, wsod
---


title: How can I validate required fields?

text:
# Question
Title: How can I validate required fields?
I don't care about having custom error message or anything, but I just want AN error message. Right now on my registration form I have a variety of supplemental fields listed as required but that has no affect on a user's ability to submit the form. How can I prevent them from submitting if the field is null? I don't care about crazy condiitionals or anything, simply if its null to not let them submit. I have been unsuccessfuly trying to code a validation module and I can't figure out the code. I really just need something to work ASAP. I have tried the validation module but it doesn't work for me - no clue why.

Maybe there is something wrong with my theme, does anybody know where that validation would normally be found so I could check? it seems other people do get the error message.

Any help would be SUPER appreciated.

# Answer
> 2 votes
There's definitely something wrong with your theme, or a custom/contrib module you've got installed. Required fields are **always** validated and checked for empty values; they just piggy-back off the FAPI `#required` property which I've never known not to work.

As far as debugging goes:

* Check the context the registration form is being displayed in. If you're manually adding the registration form in your theme, and doing so in a template file, the problem is simply that the messages produced by the form builder are being built after `$messages` has already been outputted in page.tpl.php (ignore this one if the problem is happening on the main registration page).
* Change the default theme back to Garland and see if the problem persists.
* If it does, start methodically disabling contributed and custom modules to isolate the culprit. Start with custom modules, then dev/alpha/beta contrib modules (in that order), then the stable modules. Check the registration form each time you disable one.
* To make sure there isn't some sort of conflict between your theme and a custom/contrib module, make sure you switch back to your custom theme before starting to disable modules.
* If all else fails, install a fresh copy of Drupal as a test site, add a couple of required fields to the user entity, and check the registration form again. If it works, you know there's something definitely wrong with your main installation. If it *doesn't* (which is extremely unlikely), you know the problem is more sinister (i.e. it's a crazy problem with PHP/MySQL/your OS)

---
Tags: users, forms
---


# Question
Title: Jcarousel Images loads in list then conform to horizontal block
I have a jcarousel of images on D7. On IE, the images will load in a list then once all the images are loaded. They conform to the horizontal scroll box. I've read on several articles about adding the `overflow:hidden` to the css and I have. It still appears to be loading in the list. How I can make the images not appear in a list prior to conforming to the horizontal box?

The site is www.jlucina.com and you can find the product scrolls on any of the product pages.

# Answer
> 1 votes
If you're setting `overflow:hidden` you also need to give the same element a static height, e.g.

```
#slideshow-wrapper{overflow:hidden;height:300px;}

```

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


# Question
Title: load balancing multiple horizontal drupal instances
I've developed a REST WebAPI using the Services module. It works fine. I have a client of that API with projected usage requiring I horizontally scale my Drupal instance. Note that due to the nature of my API, requiring significant CPU and GPU resources, I can not use cloud servers. Also, due to the nature of my API, the Drupal instances have to run on Windows OS. (My application requires software only available on Win64.) I have a fairly beefy server in a co-location now, and for this ambitious client I am planning to horizontally scale my hardware in the following manner:

* One CentOS server running HaProxy as the front end load balancer,
* Two to start, with more added as needed, Windows Server 2008 R2 servers hosting Drupal,
* One CentOS database server providing a single database for the multiple Drupal instances,
* One CentOS database server running in replication mode in case DB server 1 dies.

My questions have to do with how the HaProxy load balancer works. I'm assuming that the sessionIds created by the Drupal instances will be unique from one another. Does the load balancer look at the sessionId and route all requests to the same server that produced that sessionId? How would a REST WebAPI communication work if load balancing caused each API request to go to a different server? Does any and all data referenced by the WebAPI have to be stored in the database because I can't insure that multiple API requests for the same resource will be routed to the same Drupal instance?

# Answer
Having multiple webservers behind a load balancer/reverse proxy is quite common for Drupal and well supported. Varnish is typically used in the Linux world because that thing is just insanely fast when being able to actually use it, meaning anonymous visitors. Which is obviously not the case for your site.

Sessions are stored in the database by default, so that's not a problem. The only other thing that needs to be shared across all servers is the public files directory and any other like the private files if you're using something like that). In most cases, a shared/distributed file system like NFS is used for this although there are some more advanced approaches. On one site where I'm involved is the file system provided by yet another server that is an NFS-mount on the Drupal servers (so access there is slow) and is being distributed under a different domain by Lighthttpd. But again, that is probably not so relevant for you as you're not going to server lots of images and css files, I guess.

As mentioned by rocketeerbkw, there are cache backends for Memcache, Redis and others. So far, Ive only used Memcache but I recently started to look into Redis and it looks very promising but I'm not sure if it is available for Windows. However, it would be possible to set up a separate Linux server to be used for the cache. Drupal 7 relies heavily on caches, being able to get them off the database is very important for two reasons:

1. Tools like Redis and Memcache are designed for fast key based lookups and they keep their data always in memory to make the lookup as fast as possible. They have also built in support for automatically cleaning up old cache data if the configured limit gets closer.
2. Maybe even more important, it helps to get database load down. Once you have the basic setup in place, adding additional webservers is easy. Once you start reaching the limits of a single database server, things get much more complicated and you need to look into things like master/master replication (Drupal 7 doesn't really gain much from master/slave environments).

So, it's basically just your own API that you need to take care of. If possibly, you need to make sure that everything is always available from all servers. You can use either the databse, the file system or something else (Drupal can also use MongoDB to store certain data, e.g. fields). If that is not an option, then you will need to use sticky sessions so that users always end up on the same instance. You should however really try to avoid that because if one of the server fails then all users which were on that server need to re-connect to another server, possibly losing data.
> 12 votes

# Answer
By default PHP stores sessions on disk. If a user logs into Server 1, then hits Server 2 they will be logged out. There are a few options for fixing this:

1. Don't store sessions on disk
2. Ensure users always hit the same server
3. Mount a shared filesystem on all servers

To implement #2 and answer your questions about HAProxy; In the most basic setup you can run it in TCP Mode and use the "source" balancing algorithm (http://cbonte.github.com/haproxy-dconv/configuration-1.4.html#4-balance) to make sure users hit the same server. You should read the docs to determine if there are any downsides for you using that approach.

For #1 you can use a key/value store like Redis or Memecached that all your servers would connect to and retrieve sessions. This makes sessions load/save very quickly and you could use either as a shared Drupal cache as well.
> 0 votes

---
Tags: services, performance
---


# Question
Title: How can I post webform block values to another form?
I have a capture form in a block on a panel, and I am trying to get it to post the values to another form, once it is submitted.

How can I achieve this?

First name, last name, and email get posted to example.com/page?fname=XXX&lname=YYY&email=ZZZ.

I am using Drupal 6, and the Webform module version 3.9.

# Answer
You should be able to use one of the webform hooks to pass $\_GET values via redirect.

```
function YOURMODULE_webform_submission_insert($node, $submission) {
  if ($node->nid == XXX){
    // Grab the values we need and create our get url parameter string.
    $queryString = 'f1=' . $submission['value']['myfield'] . '&f2=' . $submission['value']['myfield2'] . '&f3=' . $submission['value']['myfield2'];
    drupal_goto('PATH/TO/FORM', $queryString);
  }
}

```

Or you can use a hook\_form\_alter for that form, add a new submit callback, and in the new function set the form's #redirect with the same syntax.

```
$queryString = $form_state['value']['myfield'] . '&f2=' . $form_state['value']['myfield2'] . '&f3=' . $form_state['value']['myfield2'];
$form['#redirect'] = array('PATH/TO/FORM', $queryString);

```

Then in your custom form, check for the $\_GET values, and set them as the defaults to the appropriate fields, if they exist.
> 1 votes

# Answer
You could set the `#value` property of the relevant elements based on the `$_GET` values.
> 0 votes

---
Tags: webforms
---


# Question
Title: Calling a javascript function from a form item ajax callback?
I am working on a project and I think I am stuck on this. I have a form that I want to add points to a map as users edit it.

Here's a rundown on how the form works:

The user chooses a number (1-10) for how many stops they'd like to make from a select list. The select list defaults to 1 and below it there is a select list that lists all of the points of interest they can choose from. If they change the first select to 2 the ajax callback updates the form and adds an additional select box of POIs. That's working great.

What I'd like to be able to do is add the POI to a map on the page whenever they select it (with driving directions between them). I have an ajax callback on the POI select list in order to do this but I am having trouble figuring out where to go from here.

I have the following in my POI callback (for testing) and it works, but I am having trouble figuring out what ajax\_command\_ function to use to call a js function to add the point to the map.

```
$commands = array();
$commands[] = ajax_command_alert("Here!");
return array('#type' => 'ajax', '#commands' => $commands);

```

Basically I just need to pass the latitude and longitude of the POI (which I am gathering in the callback) and send it to a js function to then update the map. My first thought was using drupal\_add\_js but I couldn't get it working and discovered later that it was not the right way to go.

Any thoughts?

# Answer
> 5 votes
PHP:

```
$commands[] = ajax_command_alert("Here!");
$commands[] = array(
  "command" => 'your_custom_command',
  "latitude" => "45.23",
  "longitude" => "23.25"
);

```

Javascript:

```
Drupal.ajax.prototype.commands.your_custom_command = function(ajax, response, status) {
  if( response.latitude != "" ) {
    // do something
  }
};

```

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


# Question
Title: How can I disable jquery_update when my admin theme is in use?
I have installed jQuery Update but it breaks some core functionality that makes the admin UI a struggle to deal with. Is there a way to keep jQuery Update enabled but disable it when the admin theme is visible?

# Answer
> 4 votes
It should be noted the underline issue is really a core problem which is now fixed over at http://drupal.org/node/1480568

Anyways if people still need a fix for this this is what I have in place.

```
/**
 * Implements hook_module_implements_alter().
 */
function hook_module_implements_alter(&$implementations, $hook) {
  // Make sure to check if the module is enabled or this will cause fatal errors
  if ($hook == 'library_alter' && module_exists('jquery_update')) {
    // Move jquery update to the end. This will make sure our hook_library_alter
    // is always called before the jquery_update.
    $jquery_update = $implementations['jquery_update'];
    unset($implementations['jquery_update']);
    $implementations['jquery_update'] = $jquery_update;
  }
}

/**
 * Implements hook_library_alter().
 */
function hook_library_alter(&$libraries, $module) {
  // If it is an admin path all we want to do is change the global $conf
  // variable so when jquery_update runs right after us it will use 1.5.
  if (path_is_admin(current_path())) {
    // Modifying global $conf variable, can be dangerous. Be carefull.
    global $conf;
    $conf['jquery_update_jquery_version'] = '1.5';
  }
}

```

This changes the variable right before jquery\_udpate uses it when is an admin path. Also this doesn't hard-code to checking the url 'admin' because and admin path can also be /node/1/edit etc..

# Answer
> 2 votes
There is an open issue about this with a patch, but I have not tested it yet.

Keep in mind that you may also need to tweak the patch so that ctools paths get excluded, too, as the updates can cause problems with the ctools popups. You may also need to add in logic to detect the node add and edit pages.

# Answer
> 1 votes
Unfortunately this will be pretty difficult to do (unless there's a hack I'm not thinking of).

The jQuery Update module replaces jQuery/jQuery UI and other associated javascript files at the library level in the `jquery_update_library_alter()` function. The data from that hook is cached and used system-wide.

So, even if you cleared the caches on every page load, AND implemented your own `hook_library_alter()` that reset all of the libraries back to their original state for admin pages only, the changes would be made system wide; visitors to the front end of the site would also be using the original libraries.

Even if that is acceptable (which I can't imagine is the case), you would still need to reverse engineer the changes made by jQuery Update for your own `hook_library_alter()` implementation.

**UPDATE**

A sort-of hack did come to mind; you could implement `hook_js_alter()` (at the theme or module level) and manually replace the updated jQuery files with the old files. It would still require working out which of these files you needed to replace, but it would solve the problem without having to clear the caches on every page load.

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


title: Migration failed

text:
# Question
Title: Migration failed
I'm posting here after my post on Webmasters was flagged to be moved here.

First of all, I'm new to Drupal and the work I have to do is some kind of too hard.
My old colleague (webmaster) had a server with a multisite Drupal 6 installation.
Sites and their dirs were (e.g.)

```
Sites              Site directory
b.a.mycompany.com  /drupal_install_dir/sites/b.a.mycompany.com
c.a.mycompany.com  /drupal_install_dir/sites/c.a.mycompany.com
d.a.mycompany.com  /drupal_install_dir/sites/d.a.mycompany.com

```

Unluckily my colleague moved and server hdd aren't in my hands: all I have is a backup of **/drupal\_install\_dir** and three sql dumps (one for each site).
I had to restore three sites, but changing them as

```
z.mycompany.com/b
z.mycompany.com/c
z.mycompany.com/d

```

Beeing a sysadmin, I

1. Extracted tar.gz backup file under wwwroot (let's call full path to extracted directory **/new\_install\_dir**)
2. Restored three databases
3. Created mysql users and give them correct GRANTS on databases

Then (trying to restore at least first site) I changed /new\_install\_dir/sites/settings.php putting correct database connection data and new basepath.
But there is no way I can see my new site, simply it doesn't work.

Watching /var/log/apache2/error.log I saw Drupal searching for main drupal database; so I created that db too setting user and grants, but dump file is empty. Well, now I can run something like *install.php* or *update.php*, but my site is not shown.

Is there something I can do?
Do I have to walk another way? Consider I searched the web, but I'm not able to find a guide that can help me for my problem.

Ah, I forgot: before producing the backup, my colleague set site in maintenance mode.
When I try to run **z.mycompany.com/?q=user** (trying to login) nothing happens.

I'm really stuck...

**UPDATE**
Those are my tries (unsuccesful)

* Cleared anything and started from the beginning
* Extracted Drupal6 installation in *drupal6* directory
* Executed (in wwwroot) `ln -s drupal6 b`: with this every request for *z.mycompany.com/b* is managed by Drupal6
* Created *sites/z.mycompany.com.b*, restored old backup coming from old server here, edited *settings.php* with **$baseurl=https://z.mycompany.com/b** and correct database params

Now I tried two things:

1. Restore db from backup (without modifying entries in it)
2. Restore db from an edited version in which I changed various entries pointing to old site

Both don't work: either I get a Drupal "Page not found" or a partial site.
I also tried to look at *sites.php*, but I don't think this can solve my problem: my server, my ip, everything is changed!! IP for *b.a.mycompany.com* is different from the one for *z.mycompany.com* adn I cannot have a dns redirection.

**MY SOLUTION**:
I finally managed to make my new site live.
In addition to what I did in my **UPDATE** section, I had to:

1. Edit my database dump to change every reference to my old site.
Note that I had a lot of different kind of references (base urls, sites dir, etc.), so Notepad++ was my friend.
Another note: some of the entries are serialized (with php `serialize()`), so you have to manage arrays end edit string lengths too.
Remember that you don't need to restore *cache...* and *watchdog* tables
2. Restore my site dropping *sites/all* directory (with that on, I wasn't able to start Drupal correctly)
3. Restore files and dirs permission (e.g. `chown -R www-data:root sites/z.mycompany.com.b`)
4. Log in as admin and perform some maintenance and run cron.
5. Restore *sites/all* directory and restore files permission `chown -R www-data:root sites/all`
6. Modules and themes in database were automatically turned off: turn them on inside administation panel

I had to tell you that */var/log/apache2/error.log* was really needful to discover something I missed or did wrong.

# Answer
> 3 votes
You may have a typo but the path in your new installation `/new_install_dir/sites/settings.php` is incorrect for either a multi-site or single-site setup. From your description you old setup was a multi-site setup.

## Background

### Multi-sites

Multi-sites use one code base to serve up multiple sites, which are contained in the `sites` folder. All URLS resolve to the same root drupal folder on your server and drupal sorts out which database and files are needed.

If you were just recreating your previous multi-site se up the paths to the settings file would look like:

```
/new_install_dir/sites/b.z.mycompany.com/settings.php
/new_install_dir/sites/c.z.mycompany.com/settings.php
/new_install_dir/sites/d.z.mycompany.com/settings.php

```

### Single Site setup

However, from your brief description it looks like you want to move away from a multisite setup to three single site setups, where each of the three URL's resolve to a different server directory that contains an independent drupal setup. In this case your paths will look like:

```
/new_install_dir_a/sites/default/settings.php
/new_install_dir_b/sites/default/settings.php
/new_install_dir_c/sites/default/settings.php

```

## Problems with going from multi-site to single site setups

**The main problem** is that you technically can't switch between. This is because a number of database tables (for example: system and files) include references to "sites/www.mydomain.com." If you change paths to modules, themes and files may all have changed depending on the setup, and Drupal can fail during the bootstrap.

### Highly Dangerous Fix

That said, I have changed the URL of mutli-sites without server redirects by directly editing the database. I first turn off all caching, and disabled all the modules and theme before dumping the database. I then edited the database (dangerous) and changed the paths. This is somewhat problematic as variable lengths associated with the path will also have changed and should be properly updated. At the time I did it with a text editor and some impressive regular expression searches, but you should be able to do it with MySQL commands?

I then moved the files to the new URL, imported the edited database and appropriately modified the `settings.php` file. I then somehow got drupal to bootstrap. It appeared partially broken, but still allowed me to log in. I then immediately cleared the cache and got Drupal to rebuild the theme, module registries. After that everything seemed to work fine. I also remember doing a number of other crazy things in the middle of the night that I can't remember and I didn't feel like trying to recreate situation to narrow down all the steps.

# Answer
> 0 votes
As the multisite documentation states:

> Once a site is in production in a particular subdirectory under the sites directory, the subdirectory should not be renamed, even if the Web site URL changes.

Try restoring your site without renaming anything (If you can't change any DNS settings for your old domains, you can override them in your `hosts` file temporarily) and if that works then you can follow the instructions for domain name changes.

---
Tags: migrations
---


# Question
Title: How does Drupal check write permissions for a folder?
How does Drupal check the write permissions on a folder in Linux?

I am using php5-fpm and the web server is working as the user that owns the Drupal directory and I expect that even with a 700 the directories should be readable and writeable by the PHP process and there should be errors only when nginx itself needs access to files or folders.

Does Drupal just test the file permissions for the other user, or does it attempt to read and write as the PHP process itself? It appears to work only when o+rwx is set on the sites/default/files folder but r-x alone should work.

Can anyone point me to the exact routines that make that check?

# Answer
You're probably looking for the `file_prepare_directory()` function:

> Checks that the directory exists and is writable.
> 3 votes

---
Tags: files
---


# Question
Title: CCK Field Table in Database and Content Type
I am creating some fields in a Custom Created Content type. What I have already seen as per my experience is that their is a table for each field that I have currently in the Content Type. But now I am adding new fields to that content type from **'Admin -\> Content Management -\> Content Type -\> Edit Custom Content Type -\> Manage Fields'**. Here I am creating some fields but I dont get a table for them. Why is CCK not creating tables for these fields?

# Answer
Assuming you're using CCK with Drupal 6 here...

Unless a field is set to multiple cardinality, or is attached to more than one content type, there won't be a table created for it. Instead, a new column will be created for it in the CCK table for that content type.

For example, if you have a content type called 'page' with a number field called 'field\_number', with single cardinality and only attached to the 'page' type, there will be a column called `field_number_value` in the `content_type_page` table; that's where the data is stored.
> 1 votes

---
Tags: entities, nodes
---


# Question
Title: Inject new variables in html.tpl.php based on current node content type
I would like to add custom classes and id attribute to html.tpl.php (body tag) based on current viewed content type.

I know i can do like:

```
 function mytheme_preprocess_html(&$variables) {
            $variables['classes_array'][] = 'myClass';
        }

```

but how to make it conditional like

```
           $node = $variables['node'];
        if ($node->type == 'lighters') {
//assign value to $variables['classes_array'] somehow
}

```

Also, how can i define new custom\_array to inject variable based on content type to body tag ? Im on Drupal 7. Thanks!

# Answer
> 2 votes
If I'm reading it right you've pretty much answered your own question there; only caveat being that I'm not sure if `$variables['node']` will be set for that particular theme function.

If it's not you can use `menu_get_object()` to get it:

```
function mytheme_preprocess_html(&$variables) {
  if ($node = menu_get_object()) {
    if ($node->type == 'lighters') {
      $variables['classes_array'][] = 'myClass';
    }
  }
}

```

You can add anything you want to the `$variables` array and it will be available to you in the template file, as the variable is passed in to the preprocess function by reference. So if you set

```
$variables['my_var'] = 'something';

```

you will have access to `$my_var`, with the value you gave it, in the template file.

---
Tags: theming
---


title: Search API Panels Display and Contexts

text:
# Question
Title: Search API Panels Display and Contexts
I am trying to build a page with Search API and Panels. I have created my search views with contexts, but I am unable to view any facets in my panel page.

My facets show up in regular blocks, but they don't show up in panels regions.

I have been able to find information regarding this issue from this Search API Issue. Apparently the order of the way the view is placed in panels is the problem, and if I re-order my facets and views in Panels, the facets show up properly.

In comment #28 of this issue, there is a way to set up a context to be able to display the facets anywhere on a panel page, but the wording is very confusing.

> EclipseGc actually gave me a quick walkthrough on how to do this the "proper" way. It takes a bit more time and effort but its a lot more flexible and effective (plus it works without having to try and figure out the order of blocks like above). The basics of it are:
>
> 1. Create a context view for your display.
> 2. Go to contexts in your panel and add a view context with your view.
> 3. You will now have a new "view context" option when adding content to a region.
> 4. Choose view row (this is where it gets a bit more complexed as you have to manually build grids etc using regions and rows and so forth).
> 5. You can now add your facets using the miscellaneous content option in panels wherever you want in your panel!
> 6. I had to use to the default view exposed forms as the context view exposed forms didnt want to inherit the path. These can also go wherever and work!

What is a "context view" and how do I add it? It is a ctools context? Or is it a new context in views, or is is a context having to do with the contexts module?

Thanks for your help!

# Answer
It's about time this got a proper answer. Here's that explained as a step-by-step:

1. **Creating a Search API view**. None of this will work unless, when you initially create the view, you choose one of the Search API options like "Show \[Search Index\]" and the appropriate index instead of "Show \[Content\]" in the drop down at the very start of the views creation process.
2. **Giving it a Context view display**. A "Context view" is a type of View Display like a "View block" or a "View page" or an "Attachment view" etc. Create one with the "Add" button at the top of the View edit page.
3. **Load it as a Context in Panels or Page Manager**. The thing that is special about Context views, is that systems built on cTools contexts (like Panels and Page Manager) can load the view early on in the process, and also, analyse it so they know what types of data to expect. In the Contexts page for your Page Manager page or Panel, add a context, choose Views, then find the right view.
4. **Place each part of the view as Content**. Because cTools is loading the View as a context, and because cTools knows what Views are and how to make sense of them, it knows exactly what elements of the view it's going to get. If it was a views block, all it can do is just dump the whole output of the block somewhere, but since it's taking the time in the Context stage to analyse and make sense of the View, it can figure out that it's going to get seperate rows, headers, footers, exposed fitlers, etc. When you go to Content in the Panels / Page Manager interface, you'll find a 'Views Context' vertical tab with various bits of your view in it. This is the "bit more complexed" bit the guy refers to. If you want, you can go nuts and build a complex, sophisticated grid display placing the Views Row content type lots of times with different limits and offsets, with the first row highlighted, then a column showing rows 2-5, then a column showing rows 6-10... Or you can just stick the 'Views row' content in without limits or offsets (plus Views Header and Views Footer if you're using them) and it'll work as normal.
5. **Place the Facets, Current View block, etc**. This is the important bit for the question. Because the View is loaded at the start of rendering the page, the search is loaded at the start of rendering the page, so order doesn't matter. If it was a Views block, it wouldn't be done until that block was rendered. So your facets and current search blocks can go anywhere.

All of this is a bit rough around the edges and might not work first time. If you're using Search API Spellcheck, don't forget to put it in the View Header then place the View Header in Panels / Page Manager. If your view gets its search terms using Contextual Filters instead of Exposed Filters, sometimes it just works, but you might sometimes need to set the argument manually and occassionally check and patch supplementary modules like Current Search Links and Search API Spellcheck depending on how the search is set up.
> 11 votes

---
Tags: views, panels, 7, search
---


# Question
Title: How to show in different positions exposed filters in a View?
I would like to design my view in this way:

```
EXPOSED FILTER1             EXPOSED FILTER2

                            MyView resulting output...........
EXPOSED FILTER 3            ............................

EXPOSED FILTER 4

```

Which is the cleanest way to do it? I would like to avoid to absolute positioning items in css.

# Answer
> 3 votes
Another way to do this is using Panels or cTools **Page Manager** (comes with cTools, you'll find the Page Manager UI under `Structure > Pages` in D7). It takes a bit of learning but, like Views, it's very powerful and once you're used to it you won't want to go back. Here's the basic step by step:

* **Give your view a Context view display**. A "Context view" is a type of View Display like a "View block" or a "View page" or an "Attachment view" etc. Create one with the "Add" button at the top of the View edit page.
* **Load it as a Context in Panels or Page Manager**. These are systems for placing content that you can think of as like a smarter, more powerful version of Drupal's Blocks system. The thing that is special about Context views, is that systems built on cTools contexts (like Panels and Page Manager) can load the view early on in the process, analyse it so they know what types of data to expect, and do smart things with that fine-grained data. In the Contexts page for your Page Manager page or Panel, add a context, choose Views, then find the right view.
* **Choose a layout** on the Layouts page. In your case, a "2-column layout" should allow you to create the exact layout you are looking.
* **Place each part of the view as Content**. Because cTools is loading the View as a context, and because cTools knows what Views are and how to make sense of them, it knows exactly what elements of the view it's going to get (unlike a Views block where it can only dump down the whole rendered block as one unit). When you go to Content in the Panels / Page Manager interface, you'll find a 'Views Context' vertical tab with various bits of your view in it, including th exposed flters. You can place each of these anywhere in your view (multiple times if needed), and configure them where appropriate. Some things this allows you to do:

+ (as per the question) Place each individual exposed filter anywhere you want on the page, seperate to the 'View row' option which contains the View results. For your layout, if you chose a 2-column layout, you can add three exposed filters using the cog icon on the left column, add the fourth to the right column, then add "View row" (no limit or offset in settings page) to get the results of the view. All this is editable: you can drag and drop, disable and enable, edit, add CSS classes, etc
    + Place the Header or Footer of a view anywhere on the page seperate to the View content
    + Build sophisticated grids with your Views content, placing the Views Row content type lots of times with different limits and offsets. For example, you can have a column showing the first row with custom classes making it highlighted, then a column showing rows 2-5, then alongside that column a column showing rows 6-10...

# Answer
> 2 votes
You can write your own template file and place it in your theme.

Please refer this documentation for the proper approach to theme exposed fields.

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


title: Get profile2 fields based on user

text:
# Question
Title: Get profile2 fields based on user
I am trying to retrieve some fields from my Profile 2 profile but am not sure how I should connect the table dr\_field\_data\_field\_resources to its relevant user.

In profile it is possible to add a field term\_reference 'resources', then I want to be able to retrieve those values in an array based on a user I specify. I did see some other docs for profile2\_load, but I using an example turorial. I am getting called to undefined function for `profile2_load()`.

```
$userskillsresources = db_query("SELECT dr_users.name as 'username', dr_taxonomy_term_data.name  as 'userresourceterm'
    FROM dr_users
    JOIN dr_field_data_field_resources
    JOIN dr_profile ON dr_users.uid = dr_profile.uid
    JOIN dr_taxonomy_term_data ON dr_field_data_field_resources.field_resources_tid = dr_taxonomy_term_data.tid
    WHERE dr_users.uid = '10'")->fetchAssoc();

```

# Answer
> 2 votes
If you really do have Profile2 installed and enabled, then you shouldn't get getting undefined function errors. Double check that it is enabled.

Otherwise, you are going about this in the wrong way. You really don't need to do queries like this. Leverage the API:

```
$account = user_load(10);
$profile = profile2_load_by_user($account);

```

If you have a single profile for the user, $profile will be a node object. Otherwise, it will be an array of nodes. Then you can do something like:

```
$resources = field_get_items('node', $profile, 'field_resources', $profile->language);

```

Also take a look at this article for a handy helper function or read more about the Field API. If `$resources` are taxonomy terms, then take a look at taxonomy\_term\_load for loading the associated terms.

---
Tags: database, users
---


# Question
Title: Want to Install picasa gallery and best is PWI
I want to use http://code.google.com/p/pwi/ in drupal. it is a jquery library and with my knowledege as far as adding libraries need to code a little. need to use (hook library or add library) don't know which suits, I am not a PHP guy. but Drupal has been fun and want this badly. If little help or pointing will climb up. Tried other picasa modules like picasa node ,Brilliant gallery but none has features like this.

Thanks

# Answer
I copied the folder(js,css,images to the root ) and created a node using the demo code given. It works. Now need to find how to format it, this got me the answer but don't know whether this is right way or not.As I am new to drupal.
> 0 votes

---
Tags: javascript
---


title: How do I change the "Read More" text

text:
# Question
Title: How do I change the "Read More" text
I have to say I feel embarrassed but after several hours of unsuccessful trials and fruitless research I am resigned to ask for help to the community.

6 months ago I have changed the **Read More** text link to **More information**. Now I am asked to roll back to **Read More** and I can't find out how I made it the first time. I am sure I did not override any function in the theme and almost sure I did write any PHP code.

I believe I have done something with the internationalization module because I have now both strings **Read more** and **More information** in the `buit-in interface` textgroup.

So how can I map the Read more link text to a given entry in the `built-in interface`?

Thank you!

# Answer
> 3 votes
OK, if you did it with code you probably edited settings.php and did something like:

```
$conf['locale_custom_strings_en'][''] = array(
  'Read More' => 'More information',
);

```

You would have to remove that line from the array.

There are a billion ways to do it via code, though, To be safe, you should search for the string "More Information" in all of the sites/ files to be safe.

If you didn't do it with code, there is a decent chance you used the String Overrides module, and did it via the UI. If so, delete that entry.

If this is related to a view, then you should poke through the settings for that view (don't forget the master and all additional displays). Look for a link field, and check the "Text to display" option.

If not, poke around the field settings for your content types, eg admin/structure/types/manage/page/fields, and see if you set it there.

---
Tags: i18n-l10n
---


# Question
Title: How to remove number of reads under each node?
I'm using Drupal 7. After enabling the Statistics module, I see, under each node, how many times it has been read (e.g. "4 reads"). How can I remove this expression while I'm using it ("Content statistics: Total views") in my views?

# Answer
According the code of the statistics module, you can just remove the "view post access counter" permission from all roles.
> 5 votes

# Answer
I needed a simple page counter but did not want to see the "reads" on every node page even as the site admin. For my drupal 7 "fusion" sub theme I used this in my template.php

```
function yourfusionsubthemename_preprocess_node(&$vars) {

unset($vars['content']['links']['statistics']['#links']['statistics_counter']['title']);

}

```
> 8 votes

# Answer
If the permissions don't work, you can also unset it in your `THEME_preprocess_node()` function (in your template.php). Just add the following line:

```
  unset($content['links']['statistics']['#links']['statistics_counter']['title']);

```
> 1 votes

---
Tags: nodes
---


# Question
Title: Node taxonomy now appears vertically in Drupal 7
After migration to Drupal 7 the taxonomy terms now appear vertically with the vocabulary names, and it seems to be the result of Drupal 7 converting taxonomies into fields.

Is there a way to revert to Drupal 6 behaviour, ie just display the taxonomy terms horizontally as before?

# Answer
After bringing in Firebug these are the changes I made

```
# display blocks for present taxonomy inline
.field-type-taxonomy-term-reference {
    display:inline-block;
}

# display taxonomy terms inline
.field-type-taxonomy-term-reference .field-item {
    display: inline;
    margin-right: 11px;
}

# hide labels for Taxonomies, display terms only
.field-type-taxonomy-term-reference .field-label {
    display: none;
}

```

There is a page on Drupal.org that pretty much does the same thing, but the CSS is applied at node level - http://drupal.org/node/1684762
> 1 votes

# Answer
If you mean you want display terms in node view horizontally, then:

if your node-type is `xxxx` and you vocabulary name is `yyyy`, add this to your CSS files:

```
.node-xxxx .field-name-field-yyyy .field-item {
  display: inline;
}

```
> 1 votes

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


title: View filters are not updated

text:
# Question
Title: View filters are not updated
I have a View filter that contains a list of taxonomy terms; the problem is that when i add new terms to the vocabulary, the new terms are not automatically added to the filter view so i do not see the nodes related to the new terms. Is there a way to link the filter to the vocabulary by saying "all the terms"?

# Answer
> 2 votes
In the filter for the taxonomy term, try choosing no terms at all instead of choosing all.

---
Tags: 7, views
---


title: Upload an Image via a Link

text:
# Question
Title: Upload an Image via a Link
When I create a new article in Drupal 7, there's a field to upload an image that will be associated with the article. That image can only be uploaded directly from my computer. Is there a way to make it so that Image fields will accept a link instead of a direct file upload?

Thanks!

# Answer
Checkout FileField Sources for this problem. It lets you use remote file transer.
> 2 votes

---
Tags: 7, media
---


title: Change the name of a tab

text:
# Question
Title: Change the name of a tab
I have a group made from Organic groups, and it has these two tabs.

I want to change the name of "View", but can't figure out where to do that.

Even better would be if I could delete that little menu. Ideas?

# Answer
> 2 votes
The Tab Tamer module should do everything you need.

> Tab Tamer is an administration utility that provides easy re-ordering, hiding, and deactivation of tabs and subtabs. You can also rename tab labels.

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


# Question
Title: CSS is not aggregated anymore - how to debug?
On a rather complex Drupal 6 site (multi domain etc.) CSS files are not aggregated anymore and CSS style definitions appear directly inside the HTML pages. The output of ´drupal\_get\_css´ is ok, but when I installed the Advanced CSS/JS Aggregation module, I see that the module reports the aggregated css files as Missing files. But when these files are opened manually, they are ok. The problem itself is not related to the the advagg-module, I only enabled it for debug reasons.

I have not switched themes on the site affected, but I have been playing around with a new theme (mobile jquery) and a correcponding jquerymobile module on a different module from the same installation. I do not currently think, that the problem has been caused by this module.

I guess the problem is caused by some module weights, but I am having trouble debugging the theming process. I am looking for help, where I should start debugging, why the aggregated CSS files are not used.

**Update:** I have edited `drupal_add_css` to default to not preprocess files. The difference is, that each css-block is inserted in a seperate style statement, whereas right now, only a single aggregated CSS style statement is generated. So I am really tryng to find out, why I am ending up with the long css style definition, instead of a link to the aggregated stylesheet.

# Answer
> 1 votes
I am extremely sorry, but I have found out that the problem was not caused by Drupal. It seems that the a proxy has been installed by the ISP that automatically compresses pages and rewrites stylesheets to be included into the page directly.

The pages work correctly when being fetched via other networks.

---
Tags: 6, theming
---


# Question
Title: Is $site_name , $logo ,$site_slogan are part of render array $page?
is $site\_name , $logo ,$site\_slogan variables values are store in render array $page? or they are independent from $page? if they are independent.then list of variables that have same nature?

# Answer
The variables you use in templates aren't really part of the render arrays themselves. They are created by the various preprocess and process functions and added to the `$variables` array. By default, those you list are added in either a `template_preprocess_page()` or `template_preprocess_html()`, which your theme can have, too. Look at the source to see what is going on. For example, the stock `template_preprocess_page` sets `$site_slogan` like

```
$variables['site_slogan'] = (theme_get_setting('toggle_slogan') ?
                            filter_xss_admin(variable_get('site_slogan', '')) : '');

```

To aid in figuring this out, I suggest installing the Devel module, and looking at the functions that it provides. For example, you can do

```
dpr($variables);

```

to get a dump of everything in the `$variables` array, or you can do

```
kpr($page);

```

to poke through the `$page` object via Krumo, which is included in Devel.
> 1 votes

---
Tags: theming
---


# Question
Title: Rate content and attribute points to author
I am looking for a module that allows users to be rated points +1 -1 . Any suggestions? I would like individual users to be rated like stack exchange. I would also eventually like to have a rating for a node, e.g. project which also contributes to the user's points.

# Answer
> 1 votes
You're looking for the User Points module. For node ratings you can use the User points Nodes and Comments or/and the Fivestar modules. There are also plenty of other modules that integrate with the User Points module, there's a nice list in the User Points Contributed modules page.

---
Tags: 7, rating
---


# Question
Title: Drupal6 reference URL date in views filter?
I apologize if this is already explained somewhere, I haven't found it.

I have a view in drupal6 based on the date browser example. I want to show all items having a date greater or equal than the date from the path:

for example, **#somesite#.com/events/2012-08-01**

* with **arguments** it shows events that are equal to the date in the path; can it show greater or equal?
* with **filters** it can show greater or equal to a hard-coded date, but can it reference the date from the path somehow?

Is there some other module or best way to do this?

Update: perhaps this is the answer Date argument as view filter

# Answer
> 0 votes
UPDATE: I solved this by using the "Views PHP Filter" http://drupal.org/project/viewsphpfilter after that i was able to choose Node PHP filter and added code to select the nodes based on the passed date like this:

```
$my_req = $_SERVER["REQUEST_URI"];

preg_match('/my_page\/(.*)-(.*)-(.*)/', $my_req, $matches);

# Get the month from the URL or use the current month:
if(isset($matches[1])){
  $my_Y = $matches[1];
  $my_m = $matches[2];
  $my_date = $matches[3]+1;
} else {
  $my_Y = date("Y");
  $my_m = date("m");
  $my_date = date("d")+1;
}
$the_date = $my_Y . "-" . $my_m ."-". $my_date;
$nodeids = array();
$query = "SELECT nid FROM content_type_event WHERE field_start_value > \"$the_date\" AND field_start_value < DATE_ADD(\"$the_date\", INTERVAL + 16 DAY) ";

$my_result = db_query($query);
while ($my_row = db_fetch_array($my_result)) {
  $nodeids[] = $my_row['nid'];
}
return $nodeids;

```

---
Tags: 6
---


title: Change date format in comments

text:
# Question
Title: Change date format in comments
How can I change the date format in my comments?

Right now it looks like this:

> Sat, 09/01/2012 - 12:00

I want it to look like this:

> Saturday, September 1, 2012

I was able to achieve this in page.tpl.php in a section where I just display the date, but have no idea where to do this so it works for my comments too.

# Answer
> 7 votes
If you want to do it sitewide, you can edit the definitions at admin/config/regional/date-time/formats

You can also add your own formats there, and then use them in `format_date()` similar to what @Epok outlined.

# Answer
> 5 votes
When you watch your `comment.tpl.php` you see that you can override some variables with `template_preprocess_comment()`

I don't know if it's the best way but it works fine for me. You have to put this function in `template.php`

```
function mytheme_preprocess_comment(&$variables){
  $variables['created'] = date('l, F d, Y', $variables['elements']['#comment']->created);
  $variables['changed'] = date('l, F d, Y', $variables['elements']['#comment']->created);
}

```

There is a post about this on Drupal.org

# Answer
> 2 votes
You can also use format\_date() function: format\_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL)

Please note UNIX timestamp is timezone blind.

```
function YOURTHEME_preprocess_comment(&$variables) {
  $variables['created'] = format_date($variables['elements']['#comment']->created, 'custom', 'l, j F Y h:i A');
}

```

---
Tags: comments, datetime
---


title: Giving a Group it's own calendar

text:
# Question
Title: Giving a Group it's own calendar
I've learned how to create groups via Organic Groups, and I learned how to use the Calendar to create a site wide calendar.

I guess what I need help with now is how to integrate the two. I can't seem to figure it out. Any tips?

# Answer
Use a relationship with the group Id and set the default value of your contextual filter to group Id from content
> 1 votes

---
Tags: views, 7, organic-groups, datetime
---


title: How to wrap a View output with a link?

text:
# Question
Title: How to wrap a View output with a link?
I have a view with no fields but a special format (An openlayer map). I would like to wrap the whole output (a map) with a static link. Typically I would like something like:

```
<div class="view-content">
    <a href="some static url">
        /*the map*/
    </a>
</div>

```

Is this achievable?

**EDIT** My view doesn't use fields, so I can't use custom texts fields.

# Answer
There might be a couple of method to do this.

**Using Views:** you can add a "Custom Text" global field and add view content to it and wrap it on the link or you can "Rewrite results" on the same file and output the field as a link.

**Using a template file:** view let you have a custom template file for your view, so you can use it to wrap your view content with the link.

**Using jQuery:** you can do something like this:

```
$('div.VIEW-CLASS').click(function(){document.location.href='URL.COM';});

```

And that will wrap the view on a link.

See the images below to see how to add a "Custom text" field and how to make it a link:

**Select custom text field**

**Add views fields into the custom text field and make it all a link**
> 1 votes

---
Tags: views, javascript
---