# Question
Title: Would PHPLint's advice be beneficial to our community?
I recently found this static PHP code analyzer called PHPLint. One of the things it can do, is look at code like this:

```
/**
 * @return string
 */
function getText() {
  return 5;
}

```

And complain that a 5, is not a string. It seems to me like this could potentially reduce bugs, and perhaps even security issues in our code. One nice thing is that I see it could give is that for return values from function, all you ever need to check is (=== null). If it's not null, then you have the data you expected.

At the surface, this seems like a possibly great addition to our codebases, core and contrib alike. But perhaps there are problems with this that I don't see?

I started applying appropriate doc-blocks to own of my own modules, and one of the issue I hit myself is that because core frequently uses arrays with mixed data in them, there are limits to what kinds of checks PHPLint can do, which causes a lot of warnings.

**Edit:** One concrete example of an issue that this could prevent is this notice from php 5.4. This code has *always* failed, it's just that no one noticed until PHP 5.4 made the implicit casting a notice. In this case the bug is relatively harmless, but more subtle errors and security problems could creep in this way.

# Answer
In theory, there sure are benefits. There are however some issues with doing it, as you partially found out yourself already.

* There will be like a million false warnings, might just be as hard to find the real issues as when simply reading the code.
* Drupal has a quite a few custom coding standards. For example, we're currently not using type declarations in docblocks except for @return $class.

I don't know how configurable PHPLint is, maybe there are a few checks that would make sense to run on our code.

For coding style issues, it might make more sense to use http://drupal.org/project/drupalcs
> 4 votes

---
Tags: coding-standards
---


# Question
Title: User registration form validate and submit hooks not called
I try to add custom validation or submit function to the user registration form, but nothing works.

Here is the code in /sites/all/themes/mytheme/template.php:

```
function mytheme_user_register_form_validate (&$form, &$form_state) {}
function mytheme_form_user_register_form_validate (&$form, &$form_state) {}
function mytheme_user_register_validate (&$form, &$form_state) {}
function mytheme_user_register_form_submit (&$form, &$form_state) {}
function mytheme_profile_user_form_validate (&$form, &$form_state) {}

```

I also put similar code to /sites/all/modules/custom/mymodule/mymodule.module:

```
function mymodule_user_register_form_validate (&$form, &$form_state) {}
function mymodule_form_user_register_form_validate (&$form, &$form_state) {}
function mymodule_user_register_validate (&$form, &$form_state) {}
function mymodule_user_register_form_submit (&$form, &$form_state) {}
function mymodule_profile_user_form_validate (&$form, &$form_state) {}

```

None of the above functions are called and I have ran out of ideas. As a proof that something works on this form, here is something that does work:

```
function mytheme_form_user_register_form_alter(&$form, &$form_state, $form_id) {}

```

This gets called!! But I need to validate...

By the way, the debugger shows (among other) this when debugging the hook\_form\_alter:

```
$form['#validate'][0] = 'user_account_form_validate'
$form['#validate'][1] = 'user_validate_picture'
$form['#validate'][2] = 'user_register_validate'
$form['#validate'][3] = 'profile_user_form_validate'

```

# Answer
Add this in your hook\_form\_alter:

`$form['#validate'][] = 'your_validation_function';`

This way you can define an additional validation functions. Make sure you report all validation errors using the `form_set_error()` function.
> 8 votes

---
Tags: 7, forms
---


title: Field validation: check for uniqness

text:
# Question
Title: Field validation: check for uniqness
There is this content type and it has a field (decimal). I want to apply a uniqueness validation on it (no two nodes with the same "National Code" value). Apparently Field Validation module is the way to go. How do I achieve this ?

# Answer
> 2 votes
You can achieve this with Unique Field module. Set the scope to Content Type and you should be good to go.

# Answer
> 0 votes
I did it using the Field Validation module (`Unique Value` rule). It is pretty simple and gives you many other validation options that might come in handy.

---
Tags: entities
---


# Question
Title: Recognize js files in the library folder
If i put my .js files in sites-\>all-\>libraries folder. Will drupal recognize it ? Because i did not see the file in the source. Can i make it recognize ?

# Answer
Just putting the files in a directory won't do any good.

You have to either put a reference to your file in your module.info file, or use drupal\_add\_js somewhere, depending on what you're trying to achieve.
> 6 votes

---
Tags: 7
---


title: date time countdown module?

text:
# Question
Title: date time countdown module?
trying to create a groupon-deal style 'time left to buy' field, a dynamic countdown field.

Any modules can do this?

# Answer
The http://drupal.org/project/countdown module does this on a block level, but since all the 'heavy lifting' is done on the client side with javascript, I wouldn't imagine it would be all that difficult to rejigger it to look at an appropriately css'ed field...
> 0 votes

---
Tags: datetime
---


title: hook_form being called twice

text:
# Question
Title: hook_form being called twice
I have a simple form inside a block:

```
function mymodule_block_view($delta = '') {
      switch($delta) {
        case 'some_name':

          $block['subject'] = t('title');
          $block['content'] = drupal_get_form('mymodule_form');
      }
      return $block;
    }

```

When I submit the form, the mymodule\_form() method gets called twice. In the first run the values I have put into the textfields are correctly stored in $form\_state. In the second run, they are not there anymore. Does anyone have an idea why this is the case?

What I would like to do is very simple: I'd like to retain the values I have put into the textfields, so when the form gets submitted, the page gets reloaded, and the values I gave are the new default\_values of the form. I know how to do this in the code, but as I said, the form\_state is empty in the second run, thus the form takes the 'default' default\_values.

Why does mymodule\_form() get called twice?

# Answer
Drupal redirects after form submissions. So you are effectively making two requests, one for the form submission and one as a consequence of the redirect.

See Wikipedia: Post/Redirect/Get for details about why Drupal redirects after form submissions.

Set `$form_state['redirect'] = false` to prevent redirection.
> 9 votes

---
Tags: 7, blocks, forms
---


# Question
Title: How to include js file in a module which depend on jquery?
I have a module called **catalog\_menu**

I included a js file within this module in this way:

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

```

Now in the browser I get this error message:

```
Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function

```

I think that the problem is that catalogo\_menu.js is loaded before jquery.js (the jquery library)

What is the right way to load a js file which depends on jquery library?

# Answer
I actually think it is pretty unlikely that you have a weight problem, unless you redefined your module to have a extremely low weight. Make sure you have JS optimization turned off, and then do a view source and make sure jQuery is the first script loaded (nearly always is).

My two *guesses* are

1. You have a JS error somewhere else, and this is a weird side effect.
2. You have a JS error in your `catalog_menu.js` (or another file) that is nuking the `$` object by accident.

Also, you should you use an anonymous closure or JS module pattern for code, because Drupa 7 defaults jQuery no-conflict mode.

```
(function ($, Drupal) {
  function init () {
    $("body").addClass("catalog-menu");
  }

  Drupal.behaviors.catalog_menu = {
    attach: init
  };
}(jQuery, Drupal));

```
> 3 votes

# Answer
You can change your module's weight to ensure it gets loaded after everything else.

Several ways :

* SQL the system table (`update system set weight=9999 where name = 'mymodule'`)
* use the Module Weight submodule from the Util module.
> 0 votes

---
Tags: javascript
---


# Question
Title: Is there a way to pass a PHP value to JavaScript?
I have a link generated within a JavaScript file that contains the following code:

```
jQuery(".url").append('<a href='+ path +'/extra/home><img src='+ pathimage +'></a>');

```

I would like to alter the path variables when user is not logged. In Drupal terms this would look like: `global $user; if (user->uid == 0) {..redirect page.}` or `global $user; return !(bool) $user->uid;`

How can I use the `$user->uid` property with JavaScript code?

# Answer
You're looking for drupal\_add\_js(). You can use it to pass data from PHP to JavaScript. Something like the following should suffice:

```
/**
 * Implementation of hook_init().
 */
function modulename_init() {
  if (!user_is_logged_in()) {
    drupal_add_js(array(
      'modulename' => array(
        'path' => $logged_out_path
      )
    ), 'setting');
  }
}

```

Note that I am calling this from within an implementation of hook\_init(), but really you can do this anywhere, be it from a module or a theme. Also note that I have provided a sufficient namespace for the value to live (i.e. within 'modulename' =\> 'path'). This will make it clear from JavaScript's point of view exactly who owns the variable (i.e. which module it came from), but more importantly will help to prevent collisions with settings in other modules.

From JavaScript you can access the value of $logged\_out\_path like this:

```
var path = Drupal.settings.modulename.path;

```
> 14 votes

---
Tags: users, javascript
---


# Question
Title: Where to a place a custom php file in the directory
I have a hard coded form that i need to send to a php page that i have built. With drupal i am a bit confused on where i would place this php page so it doesnt cause any problems.

I was thinking here but i wanted to check first. /httpdocs/newsite/PHP-HERE (Same directory as index.php)

Where would i place this php page?

# Answer
> 1 votes
Everything including forms can be integrated nicely within drupal. i would recommend reviewing FAPI. it will save you time/effort in the end.

however, if you absolutely need this not to be built around/within/whatever using drupal's FAPI, what i would do is put the page either directly in your theme folder or make a subfolder and drop it in there. so lets make many assumptions here (awful i know). say your form is called newform.php. rename it to `page-newform.tpl.php` and drop it into one of those folders. create a page just to give you a node place holder and a path like /newform. then in your template.php file under the `THEMENAME_preprocess_page()` function, check the URL with either `$_GET['q']` or `arg()` (arg is preferred). if the url is going to /newform simply adjust your `$variables['template_file']` to be something like `$variables['template_file'] = 'page-newform'`. this will pick up your page specifically.

so with a lot of assumptions and very little go on with what you are doing. this could be done.

```
function themename_preprocess_page(&$variables, $hook) {
 if (arg(0) == 'newform') {
   $variables['template_file'] = 'page-newform'
 }
}

```

# Answer
> 0 votes
It depends on how much you want your form to be tied to Drupal. If it must insert data in the database, you'd better use FAPI to generate and manage it.

If you're sure your data is totally independant from Drupal, you can manage your form with custom functions in a module, but it will be work and you wont get any benefit from drupal's power.

An alternative would be to use Webform.

# Answer
> 0 votes
I would put it into a pseudo-module and place it in

```
DRUPALROOT/sites/all/modules/custom/YOURMODULEHERE

```

in your helper module you can also specify a menu hook, if the resulting URL would be too long or not attractive for your needs.

---
Tags: forms
---


# Question
Title: Unique Value validation rule does not show the indicated message
I have a `Unique Value` rule for a field. The rule applies correctly and the offending field gets highlighted in red but it doesn't show any messages !

I have other validation rules on the *same field* (must be a number, minimum, maximum etc) and they behave correctly i.e field is highlighted in red and the indicated error message appears.

# Answer
You wouldn't believe this but it was the theme. We had forgotten to include the markup that contains the flash messages sent by core to the user so basically it any flash message (including the validation errors) wouldn't show up.

The reason why other validation errors showed up was the `Client-side Validation` module that causes some certain form of validation violations to be detected in the client and displays them via it's own device.
> 3 votes

---
Tags: forms
---


title: Views : Rewrite results - Edit content

text:
# Question
Title: Views : Rewrite results - Edit content
Is there a way to rewrite the **content** of a field displayed in a view?

E.g. If my title is long, like "\[Product ID:5739\] Ninja Stars" and I want it to display just "Ninja Stars" in the view, how can I do it?

# Answer
You can in views rewrite the result of any field, or trim most fields, but if there is some logic to what you want to remove you would need to do with with a preprocess hook in your theme. In this case it sounds like you need to do the latter. Something like this should do the trick:

```
function theme_preprocess_views_view_fields(&$vars) {
  if ($do_your_checks) {
    $vars['fields']['field_name'] = preg_replace(...) // Use regular expression to change title.
  }
}

```
> 5 votes

---
Tags: views
---


# Question
Title: Changes in test version applied in live version as well
On a D6 multisite setup, under the sites folder, there are a bunch of sites. Two of which are the sites testsite.domainname.com and domainname.com. They have the folder structure I put at the bottom of this post.

So the problem is that changes made in the test version also seem applied to the live version, obviously with very undesired results for the end users. I checked the settings.php file to see if the same database would be connected to but the data in both files are for different databases.

Changes applied to the test server that unintendedly have an effect on the live site are not only limited to changes in the domain\_custom.module file. I noticed that changes made on the testsite in the page.tpl.php did the same thing;

**testsite.domain.com**
-modules
--domainname\_custom
--nice\_menus
-themes
--custom\_theme
-settings.php

**domain.com**
-modules
--domainname\_custom
--nice\_menus
-themes
--custom\_theme
-settings.php

# Answer
> 0 votes
Of course i have to ask the obvious here, did you check out multi-site install

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


# Question
Title: Views grid output is top-to-bottom, not left-to-right?
I have a view outputting a grid of fields sorted by title, however the sorting is not what I expected:

What i'm getting:

```
A  D  G

B  E  H

C  F  I

```

What I want:

```
A  B  C

D  E  F

G  H  I

```

# Answer
> 2 votes
I am pretty sure you need to change the display of your grid from horizontal to vertical or vice-versa. You may also have to play with the "fill up single line setting".

---
Tags: views
---


# Question
Title: How to theme markers bubble with Gmap module?
I've installed Gmap and location modules. I have a view with gmap display and i'd like to be able to display more than one field in the marker bubble, but the module doesn't allow more than one field in the bubble. How do i achieve that ? Is there a template or a theme function that'll allow me to do that?

Thanks.

# Answer
There's a actually a way to do this in Views UI.

1. Add all your fields in Views as per usual
2. On the bottom most field (ideally the one that's the bubble), edit it and click on "Rewrite results". (Note you can drag / reorder fields to get the right one at the bottom.)
3. Check the box, "`Rewrite the output of this field`"
4. Below that once expanded, you will see "Replacement patterns"
5. Now add in all the tokens into the rewrite text box. e.g. `[title] == Content: Title, [some_other-field] == Content: Some other field`, etc...
6. Click apply.
7. Now go in and edit the other fields that you added in to the bottom field and check the box "`Exclude from display`"
8. Now go to "`Format`" probably something like "Gmap" and click on "settings". You will see a "`grouping setting`
9. select to group on that bottom most field that you added in all the tokens to.
10. Save this and now all those fields should be in the bubble.

Obviously without seeing your view, I was guessing at some of this so you will have to try to make sense of it as it in terms of your view.
> 5 votes

# Answer
Sorry, but I didn't got what are you trying to achieve, if you are asking for this kind of map http://www.hospitalsreview.com/smile-care?qt-tabs=3#qt-tabs then its possible since it is created in Drupal 7 with Gmap and location module, only thing you have to do is to make some changes in fields of your views and and there is a css bug of GMap module, that you have to clear it up manually. If you need some more help then you're welcome :)
> 0 votes

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


# Question
Title: Should I put my site on maintenance mode before using "drush sql-dump"?
When performing `drush sql-dump`, should I set the site in maintenance mode or will this command makes sure a coherent dump will be generated even if users are busy using Drupal? I can't find confirmation in the documentation.

# Answer
According to Moshe's answer in advantages of drush bam vs. drush sql-dump / drush sql-connect, the answer is no. `drush sql-dump` does the right thing and will result in a consistent backup.
> 8 votes

---
Tags: 7, drush, maintenance-mode
---


# Question
Title: How to set up drush aliases for a local server for rsync?
I'd like to use `drush` to sync files from local server to production server. I have edited the `aliases.drushrc.php` file and placed inside `/drush/aliases` in both local and remote machines. Everything seems to work fine except that drush understands that both sites are in the same server since I do not know how to tell drush that local is in another machine in my local server. I guess it's something to do with uri but I do not know what should I write there.

I've tried with this:

```
$aliases['local'] = array(
  'uri'  => 'mysite.localhost',
  'root' => '/home/user/www/mysite',
);

```

and this:

```
$aliases['local'] = array(
  'uri'  => 'localhost/mysite',
  'root' => '/home/user/www/mysite',
);

```

being `mysite` the name of the folder placed in `/home/user/www` in my local server, but none of them seem to work.

Anyone can tell me what am I doing wrong?

EDIT:

I have placed `mysite.aliases.drushrc.php` in my local sites folder. However I didn't succeed with the following code in my local site:

```
drush rsync @mysite.live:%files @mysite.local:%files

```

This is what I get:

> You will destroy data from @mysite.local:/home/user/www/mysite/%files and replace with data from @carloscamara.live:/home/user/www/mysite/%files
> Do you really want to continue? (y/n): y
> The source and destination cannot both be remote.
> rsync error: syntax or usage error (code 1) at main.c(1166) \[Receiver=3.0.8\]

This is `mysite.aliases.drushrc.php` content:

```
$aliases['local'] = array(
    'uri'  => 'localhost/mysite',
    'root' => '/home/user/www/mysite',
    'path-aliases' => array(
      '%files' => 'sites/default/files',
     ),
     'command-specific' => array (
       'sql-sync' => array (
         'no-cache' => TRUE,
       ),

$aliases['live'] = array(
    'uri' => 'mysite.com',
    'root' => '/home/user/mysite';
    'remote-machine' => 'mysite.com';
    'remote-user' => 'myusername',
    'remote-host' => 'mysite.com',
    'path-aliases' => array(
      '%files' => '/home/myusername/mysite.com/sites/default/files',
     ),
  );

```

# Answer
> 5 votes
To set up to do a drush rsync or drush sql-sync to a remote machine, set up aliases for both sites on the local machine. The alias for the local site should be as you have shown in your question. For the remote machine:

```
$aliases['stage'] = array(
    'uri'  => 'staging.mysite.com',
    'root' => '/home/user/www/mysite',
    'remote-host' => 'stagingfqdn.myisp.com',
    'remote-user' => 'wwwadmin',
  );

```

'remote-machine' should be the fully qualified domain name of the machine that hosts the remote site. This may or may not be the same as the 'uri' parameter. You *might* need to edit /etc/hosts, but only if the remote machine is not resolvable in DNS (unusual). The 'remote-user' should be the name of the user that owns the files at the Drupal root; usually this is **not** the user that the web server runs as.

It sometimes makes sense to sql-sync from local to remote -- for example, when bringing a site live for the first time. Usually, though, you are going to want to rsync your code from local to remote (or check it out from a vcs), and sql-sync your database from remote to local (and never the reverse). This will insure that you do not overwrite user-generated content. See the features module for one common solution for pushing configuration to the remote machine via copying files.

**Edit:** Made a typo: said 'remote-machine', but it should have been 'remote-host'. Corrected above.

**Edit 2:** Originally I said "rsync your files from local to remote (and never the reverse), but I meant code. Corrected above. It is, of course, reasonable and customary to rsync %files from remote to local, as shown in your updated question.

---
Tags: drush, deployment
---


# Question
Title: About the template for poll recent block in drupal 7
I need a template for the poll recent block in drupal 7. I have tried with block--poll.tpl.php and block--poll--recent.tpl.php and poll--recent--block.tpl.php and I can't see any changes. What's my wrong?

# Answer
> 5 votes
`block--poll--recent.tpl.php` will work if you clear your system cache (configuration \> development \> performance \> clear all caches).

Worked for me.

See complete template suggestion list for Drupal 7 here : http://drupal.org/node/1089656

---
Tags: theming
---


title: Print watcher link in a block

text:
# Question
Title: Print watcher link in a block
I found the code below to print a watcher link in a block, but it is for Drupal 6.

```
<?php
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $node = node_load(arg(1));
    $node = node_build_content($node, false, true);
    print $node->content['watcher']['#value'];
  }
?>

```

Does anyone know how to get the same thing done for Drupal 7?

# Answer
This depends on if you are trying to get the value of the field or the rendered output of the field.

If you just want the value of the field you can do this in the same way in Drupal 7. Instead of

```
 $node->content['field_name']['#value'];

```

you need to specify a language and the a number for the field value you want (even if the field doesn't accept multiple values).

```
 $node->field_name[$node->language][0]['value'];

```

If you have the entity api module installed you can use the entity\_metadata\_wrapper function which is a little cleaner: http://drupal.org/node/1021556

If you want the rendered output, use node\_view:

```
 if (arg(0) == 'node' && is_numeric(arg(1))) {
    $node = node_view(node_load(arg(1));
    print drupal_render($node['field_name']);
  }

```

The rendered output will give you the properly themed output, something closer to:

```
"<div class="field field-name-field-field-name field-type-list-text field-label-hidden"><div class="field-items"><div class="field-item even">field value</div></div></div>"

```
> 0 votes

---
Tags: navigation
---


title: Drupal Views Filter for Slideshow

text:
# Question
Title: Drupal Views Filter for Slideshow
I have created a content type for slide show name as slider in which i have 3 fields

Image, Image Description, and Image Postion(left or right). I added multiple images and text for this.

Now i want to show slide show according to postion set of each image.

if image is left then it shows to left and text shows to right. and vice versa.

Anybody have idea how to do this

Thanks

# Answer
This is pretty much a Views theming task. Hopefully you are familiar with either Firebug or Web Inspector for Chrome. Your "`Image Postion Right`" and "`Image Postion Left`" will have their own respective div classes so you can leverage / theme those CSS classes to get the image in the correct postion.

If you need something more powerful beyond this, you may also need to create a Custom Views Template. (In your View, you should see a link for "`Theme:Information`" -- it might be under "`Advanced`" if you are using Views 3 for Drupal 7.) Clicking on this will give you template suggestions. You may also need to use the Devel module's "Theme developer" to quickly find the field variable names.-- see this

You also did not say which version of Drupal you are using so there may be some specific things relative to your Drupal version that you will need to be aware of.

So basically as you can see there are multiple ways to do what you need but this should be a good overview and resource. Theming a View is an artform and can take a while to get the hang of but once you do, it's pretty cool.
> 2 votes

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


# Question
Title: Why has not Pressflow been upgraded to 6.24?
Two weeks ago, Drupal released 6.23 to fix a security vulnerabilities, which was followed from Drupal 6.24. However, Pressflow is still in 6.22 (although, there are some files have been changed at the last week).

I am wondering whether Pressflow 6.22 has not been affected by the vulnerabilities in Drupal 6.22, or it does but it takes time for the team to upgrade it. If so, how insecure is Pressflow 6.22?

# Answer
> 6 votes
They only merged in the parts of Drupal that changed for the security update. See https://github.com/pressflow/6/blob/master/modules/system/system.module.

```
/**
 * The current system version.
 */
define('VERSION', '6.23');

```

# Answer
> 7 votes
I'm a developer at Four Kitchens.

Drupal 6.24 introduced changes to the bootstrap process, and those created a merge conflict with Pressflow. See David Strauss' comments here on Github.

The forks of Pressflow on Github may have the latest 6.24 but these changes have not been reviewed by Pressflow maintainers and no pull requests have been sent.

The forks also include patches from the Drupal issue queue to fix some serious issues that appeared in 6.24, and they are not the most recent patches in the actual issue nodes:

* drupal.org/node/1425868
* drupal.org/node/1425260

So beware: Using a fork means you're using Pressflow upgraded to 6.x-dev essentially, except it's not even -dev as these issues are not yet adequately resolved; at least, not sufficiently enough to be accepted into Drupal 6.x-dev.

We're working on getting a full 6.24 stable version of Pressflow out. In the meantime, Pressflow 6.23 contains the security fix and was available when Drupal 6.23 was released.

You can also follow Pressflow at https://twitter.com/#!/pressflow.

# Answer
> 4 votes
https://github.com/pressflow/6

If you want 6.24 try https://github.com/omega8cc/pressflow6. See http://groups.drupal.org/node/187209 for some of the extras included in this fork of pressflow.

---
Tags: updating, 6
---


title: create custom template for lightbox2

text:
# Question
Title: create custom template for lightbox2
I have created an override template for the poll content type called "page--type--poll.tpl.php" using a preprocess hook, but now I need to create extra effect on this template so that when people click on the title from the front page the node will show in a lightbox. I got the lightbox effect to work, but it still shows the whole node, How I can tell drupal that this content type has two templates and that the difference is which link they clicked from the view.

# Answer
> 1 votes
The way I've handled this is by adding a extra `$_GET` parameter to the end of the lightbox link url-s. For example if the url is `http://www.example.com/somepage` then you could turn it into `http://www.example.com/somepage?lightbox=true`. This can be done via javascript if it's troublesome modifying the view - might even be more suitable so that users with javascript turned off will get a better template. Then you can tell Drupal to use a different template for lightbox content this way:

```
function mytheme_preprocess_page(&$variables) {
  if (isset($_GET['lightbox']) && $_GET['lightbox'] == TRUE) {
    $variables['theme_hook_suggestions'][] = 'page__lightbox'; // page--lightbox.tpl.php
  }
}

```

# Answer
> 0 votes
Lightbox show node, so you should theme only node "`node--poll.tpl.php`", instead of whole page "`page--type--poll.tpl.php`".

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


# Question
Title: Allow users to choose from multiple avatars while registration in drupal 7
Currently I am working on a website registration page and I want a new user to select a default avatar from a given list if they have not uploaded a profile image while they are registering. I am using drupal 7 so avatar selection module is not compatible with this version so can you kindly suggest me some other way out

# Answer
Have you tried Avatar Selection for custom images ?
Also you can try the Gravatar module to use with this service.
> 1 votes

# Answer
Using the Media module you can allow users to select images from a library or upload there own which sounds like what you want. I assume that functionality would apply to the user image, but I have not tried that. I know it works for image fields you create so you'll have to take a look, but either way seems like media module has the basis of what you want.
> 0 votes

---
Tags: 7
---


title: Embed two blocks in a block

text:
# Question
Title: Embed two blocks in a block
I have three blocks A, B and C and I need to embed the blocks A and B into the template of a block C. Is it possible?

# Answer
> 7 votes
Yes, when you create a block programatically you can add any content inclusive another blocks.

In your block function you can do something like:

```
$blockA = module_invoke('block', 'block_view', 1);
$blockB = module_invoke('block', 'block_view', 2);
return $blockA['content'].$blockB['content'];

```

# Answer
> 3 votes
Alternately, create a View that contains A, B, and C in some combination, and expose it as a block.

# Answer
> 1 votes
I believe you can embed several blocks within another mini-panel block, with the Panels module.

---
Tags: blocks, theming
---


# Question
Title: 7 - Posting www links without http prefix
I have a simple body field that uses an input format with only "Limit allowed HTML tags".

If I enter a link ... say `<a href="www.google.com">Test</a>` The node will transform the link's href to read `http://www.mydomain.com/www.google.com`

If I enter `<a href="http://www.google.com">Test</a>`, it will work as expected.

Is there a reason why not including http:// causes this? Is there a way around it?

I was hoping Pathologic would solve this but it doesn't seem to have.

Thanks!

# Answer
> 0 votes
The issue is `href="www.google.com"` really **is** `http://yourdomainandpath/www.google.com` just as `href="hello.htm"` would be as well.

---
Tags: 7
---


# Question
Title: Drupal 7 Single Sign On possibilities with the Domain Access Module
**The background:** We (currently) have 2000 domain names pointed at a single IP. Drupal inherently has the ability to use multisite, but for our particular Drupal 7 install we use a module named Domain Access to delegate sites. The gist is though that Domain Access will not allow cross site logins, but yeah, we would like our editors to log in once, and have access to all sites.

**The question:** Has anyone made any headway with coming up with a single sign on solution with Domain access to date for Drupal 7? I've been looking closely at two old modules, one no longer maintained (SSO for D6) and one still maintained (CAS). I'm worried about using CAS I am not sure if it will work the way I intend it since Domain Access seems to change quite a bit of Drupal(ly) stuff.

We could potentially use facebook, openid, twitter option, but i thing not having able to offer visitors or customers a unique id across a network of sites is too me a big loss of identity and privacy.

Are there any solutions that are known to date, or information on what to start looking into? Has anyone in the Drupal community managed to make a solution that I have not been able to find? The only possiblitiy that I've found was this thread on Domain Access SSO but am uncertain to what version it pertains to (Drupal. DA, SSO or otherwise). I tried contacting the author multiple times but never received a response. It looks like the "Solution" was to create a master table set with users and permissions, then share those across the domains. Unfortunetly (again) SSO on Drupal 7 is not an option.

Any opinions out there on the who what or why would be greatly appreciated, I honestly just need a start point to get the ball rolling. Thanks everyone

# Answer
> 2 votes
See: Comparison of Single Sign On (SSO) Modules

Bakery supports SSO for sites with the same domain (site1.example.com, site2.example.com). Have not tried CAS as you noted above it is an option. You could also use an oauth server to authenticate across domains.

---
Tags: 7, multi-sites, domain-access, authentication-authorization
---


title: Custom validation for a form?

text:
# Question
Title: Custom validation for a form?
I need to add custom validation to a form, lets says add article form.

I was expecting something like `hook_FORM_ID_validate()` to handle this, but cannot find anything relavant in the API documentation.

What is the way to add custom validation to a form?

# Answer
> 63 votes
You can add any number of validation functions to any form in `hook_form_FORM_ID_alter()` like so:

```
function mymodule_form_article_node_form_alter(&$form, &$form_state, $form_id) {
  // There will already be some validate handlers added so you need to add to the
  // array rather than overwrite it.
  $form['#validate'][] = 'mymodule_article_form_validate';

  // As mentioned above you can add as many as you want
  $form['#validate'][] = 'mymodule_article_form_validate_2';
}

function mymodule_article_form_validate($form, &$form_state) {
  // Random example, if the title is 'test' throw an error
  if ($form_state['values']['title'] == 'test') {
    form_set_error('title', 'Title cannot be "test"');
  }
}

```

# Answer
> 6 votes
You should use `hook_form_alter` and add your function to the `#validate` property.

---
Tags: 7, forms
---


title: Add an HTML file in a custom module

text:
# Question
Title: Add an HTML file in a custom module
I have an external application I have to add in my custom feature of Open Atrium. There is some JavaScript files I have already added to the module, and some CSS files.

To implement the application, I need to include an HTML file in the module's output. In which way can I do this?

# Answer
You can simply add `<?php print file_get_contents('my_file.html'); ?>` in your module's template file, or even do that inside your module's callback function, and return it as output.

It's a little bit messy, but including off-site files or scripts is always a little messy.
> 1 votes

---
Tags: distributions
---


# Question
Title: Linking content of one field to content of another
I have a content type with an image field and a file field, being outputted in views. How do I want the image to link to the file.

How do I approach this? Make a template for the image field? And if so, how do I get the file field link from that template?

I'm using Drupal 7.

# Answer
There are several ways to achieve this. I think the following one may be one of the easiest:

Assuming you have two fields outputted in views: "Image" and "File" make sure to display them in the following order:

1. Image
2. File

1. Edit image field and mark "exclude from display"
    2. Edit file field and mark "rewrite output".
    3. You'll see you can use the image field as replacement patterns so you can print the previous field \[image\] and link it to the file by writing a bit of html code such as this one: `<a href="[file]">[image]</a>`.
> 4 votes

---
Tags: views, entities
---


# Question
Title: Drupal Commerce - Line Item 'display path' from views
How is the 'display path' is built when the Cart view is rendered?
Why would it not be rendering some display path URLs?

I'm using a modified version commerce\_add\_to\_cart\_extras module whereby I'm trying to link the line item to the product display node by customizing the `display path`. I can see it being added correctly when I inspect the `$line_item` object in save function of `CommerceLineItemEntityController`. But the line items in my cart still aren't linked and when I output the display path as a field in the view, it's empty.

If it would help, I can add the debug print I captured via devel's `dd()` function of the `$line_item` or my code but they will make the post rather long so I've left them out for now.

# Answer
Turns out this was my mistake. I thought the `display_path` was being populated and I was wondering why the line items in the cart were not being linked. But it turns out the display path is incomplete in the line item. Here's a comparison of the `$line_item` as saved via commerce core's add to cart form:

```
stdClass Object (
    [type] => product
    [order_id] => 7
    [quantity] => 1
    [data] => Array
        (
            [context] => Array
                (
                    [product_ids] => Array
                        (
                            [0] => 4369
                        )

                    [add_to_cart_combine] => 1
                    [display_path] => node/1839
                    [entity] => Array
                        (
                            [entity_type] => node
                            [entity_id] => 1839
                            [product_reference_field_name] => field_product_reference
                        )

                )

        )
...
    [commerce_display_path] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [value] => node/1839
                        )

                )

        )
...

```

vs. the commerce\_add\_to\_cart\_extras `$line_item` object:

```
stdClass Object
(
    [type] => product
    [order_id] => 12
    [quantity] => 1
    [data] => Array
        (
            [context] => Array
                (
                    [product_ids] => Array
                        (
                            [0] => 4375
                        )

                    [add_to_cart_combine] => 1
                    [display_path] => node/1845  //<--I modified to try and link to the display node
                    [view] => Array
                        (
                            [view_name] => products_by_category
                            [display_name] => page
                            [human_name] => Products by Category
                            [page] =>
                        )

                )
...

    [commerce_display_path] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [value] =>  // <--Turns out this is empty. Now, to figure out why/where to populate this...
                        )

                )

        )
...

```
> 0 votes

# Answer
Edit the view, click the "Quantity input field", are you sure the "Link products added to the cart from this View to this View's path if displayed as a page." checkbox is checked? That's what makes it populate the display path.
> 2 votes

---
Tags: 7, commerce
---


# Question
Title: Add bootstrap.inc to file to programatically save nodes
In Drupal 6 I would add these two lines to my code so that I could programatically import fields without having to create a module for it

```
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

```

However, trying to do this in D7, I am getting all types of errors from defined constants not being defined. What is the proper way to do this in d7?

I have my script ready, and I do not want to spend another several hours writing code just so this can fit nicely into drupal as a module. Thoughts? thanks!

# Answer
I am working on a MAC, and apparently there is an issue with how mysql sockets are handled.

If you are on a Mac and having issues with PDO exceptions as well as REMOTE\_ADDR not found, do this:

1. Execute the following commands:

```
    sudo mkdir /var/mysql
    sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

```
1. Put this at the top of your PHP script:

```
$_SERVER['HTTP_HOST'] = 'example.org';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';

chdir('/root/drupal/folder/'); // Change this to your root Drupal address for local.
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

```
> 0 votes

# Answer
Drupal 7 uses the `DRUPAL_ROOT` constant that is set to the Drupal root directory path. If you look at the code of the index.php file, you will notice the following code.

```
/**
 * Root directory of Drupal installation.
 */
define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();

```

The constant is also used from Drupal functions, such as `module_load_include()`.

```
  if (function_exists('drupal_get_path')) {
    $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
    if (is_file($file)) {
      require_once $file;
      return $file;
    }
  }

```

If you have to write, for any reason, a function similar to `module_load_include()` you should use `DRUPAL_ROOT` to get the Drupal root directory.

Supposing that in your case Drupal is not in the current directory, you can use the following code.

```
define('DRUPAL_ROOT', 'the directory containing Drupal');

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

```
> 4 votes

---
Tags: 7
---


title: Content links are breaking

text:
# Question
Title: Content links are breaking
I've been hired by a firm as an entry level developer/seo/content marketing person and part of my responsibility includes their Drupal (6.X) CMS. I'm working my way through the 'The Definitive Guide to Drupal 7' and I've been making only small iterative changes so far while I'm getting the hang of everything. Today though, I have a bit of an issue which I could use some help on.

Some of the content links are breaking and it is due (I believe) to the way they have Drupal configured as well as my own green-ness. For example, the site's content area (the `<front>`) is called www.drupal.com/blog but the name of the server that hosts Drupal is server.drupal.com. Newer content and some of the older content is being automatically aliased to server.drupal.com and so is only viewable when a user (admin) is logged in. So, when a video node is posted, it is aliased as, for example, server.drupal.com/videos/awesome-video but when www.drupal.com/videos/awesome-video is entered into the URL as an anon user it throws a 404. No bueno.

The URL Alias module automattically sets server.drupal.com as the default base pathway and only allows me to set the /videos/awesome-video part of the alias.

# Answer
> 0 votes
Your woes are most likely coming from apache (or whichever web server you are using) unless you are using the domain module. Either your .htacces file or virtual host (depending on whether you have "AllowOverride" on in apache) should be setup to route requests through 'example.com' and not 'server.example.com'.

Are you on a VPS or shared host? What flavor of Linux are you using?

# Answer
> 0 votes
As acouch noted check your settings.php (at sites/default/ folder) and make sure that `$base_url` is not pointing to server.drupal.com. Even if it's commented out, try uncommenting it and put drupal.com as the `$base_url`. That way you will be forcing the url of your site.

---
Tags: uri
---


# Question
Title: Multi-site setup outside public_html and add on domains
So I have a Drupal site http://experiment-resources.com running on HostGator dedicated server. It's document root is the default public\_html directory.

Now I need to setup a multisite environment outside public\_html because I dont want to mess with existing website's functionality.

I already added http://arkivtjenesten.no as an Add-On domain and pointed it to /home/myaccount/arkivtjenesten as its document root. All works fine.

Now I need to add another domain , http://assistertselvhjelp.no . I added this as an add on domain and pointed its doc root to /home/myaccount/arkivtjenesten , same as the previous site. I also added its own settings.php so that it will have its own database. The problem now is if I type in http://assistertselvhjelp.no in the browser it only shows the Apache page.

Please help!

Thanks!

# Answer
> 1 votes
By the definition of multi-site: you use one Drupal installation (core) to host several sites. But according to your problem, you want a separate instance of Drupal installation and hence it's considered a "multi-site".

You need edit your virtual host file and point http://assitertselvh.no to the specific folder you're hosting to:

Please use the following guide to edit your virtual host.

http://drupal.org/node/111238

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


title: How to use the Signup module

text:
# Question
Title: How to use the Signup module
Can anyone show me how to use the Signup Module? I don't see anything in Structure or Add Content. I'm sure I just missed the link somewhere but I just can't figure out where.

# Answer
`admin/config/people/signup` is where the settings page is located.

`admin/content/signup` displays "all signup-enabled posts, and open or close signups on them"
> 2 votes

# Answer
I had the same problem, I only recently figured out that you have to go into the content type that you want to enable it for, and specifically enable it under the Signup tab. In terms of using it, you mentioned add content. Well, the sign up module is not meant to be added. It will automatically display a form to sign up as long as you enable it for the content type.
> 1 votes

---
Tags: 7, users
---


title: Theming a slider view using templates

text:
# Question
Title: Theming a slider view using templates
I am creating theming view using row style theme named as

> views-view-fields--slider-block.tpl.php

and here is code for it:

```
<?php
$string='<div id="slider"><ul>';

foreach($fields['field_slider_image_fid']->handler->view->style_plugin->rendered_fields as $row) : ?>
<?php $i=1; ?>
<?php $i=$i+1;?>

<?php

if($row['field_image_position_value'] == 'left') {
    $string.="<li>
".$row['field_slider_image_fid']."".$row['field_image_text_value']."</li>";
}
else {
    $string.="<li>".$row['field_image_text_value']."".$row['field_slider_image_fid']."</li>";

}
?>
<?php endforeach;  ?>

<?php
$string.="</ul></div>";

echo $string;
?>

```

Now it is working fine when there is exactly one node in the view. But a problem occurs when the view contains more than one node, e.g. if the view contains 5 nodes, this template renders 5 times causing duplication.

Anyone have ideas on how to resolve this?

# Answer
> 1 votes
Apart from your template needed some serious code cleanup (to follow the coding standards for PHP Template), I would say your issue lies with the fact that you have overridden the wrong views template.

It seems like your views template is doing the iterations around the nodes itself (from the foreach), and I bet your view is also doing the same (hence the double up).

My suggestions:

* Read https://drupal.org/coding-standards \- thoroughly
* Also look at the default implementations in the views templates, these will give your excellent examples on how your code should look

As for your problem, either:

* override a higher level views template (i.e. one that only gets rendered once per view)
* or alternatively, use the same template, and leave out the foreach loop (as the view is essentially doing this. I would say this is the 'cleaner' option. All the fields you have pulled out in your view will be available to be used without having to access the global `$view` object.

Consider installing the devel module to help with outputting variables, so you know what is available to be themed (using the dsm() function)

---
Tags: 6, theming, views
---


# Question
Title: filter homepage content based on term id
I have two pages "homepage" and "countries", the default behavior is that when a visitor first visit my homepage all content is gathered regardless of the country.

But if the user went to the countries page, which is a view that's getting term ids from a taxonomy list, and selects a country, he/she will get redirected to the homepage and the homepage content will get filtered to the term id the person chose from the countries page.

I think I should be using contextual filters, but I'm confused right now.

my question is how can I do this filter on homepage based on a term clicked from another view.

any help will be greatly appreciated with hot cookies.

# Answer
> 2 votes
Okay, now i understand your problem!

When a user clicks on a link in the "countries" page, he will see the standard taxonomy term "view". But i guess you want him to see your normal "homepage" BUT with filtered content.

You have two options:

1. Alter the taxonomy term page.
2. Use contextual filter on the "homepage" and change the links on the "countries" page according to use the filter.

In my opinion you should clearly prefer option two. Also have a look at the view "Glossary", which should be included, but not activated out of the box, this should help you a lot in configuration!

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


# Question
Title: How does Drupal not rely on Foreign Indexes for matching table row information?
I am so confused right now in creating a custom table within Drupal 7. My db schema builds a table with three fields one of which is a uid field. I don't have much experience with databases and I was confused as to how to match, relationally, the uid field of my table with the users-\>uid field. I am told that the foreign key operation within the D7 appear to do this but that they are only there as documentation, **the foreign key operation doesn't actually do anything.** Is there a way, within the D7 schema, to link two table row items such as uid -- if so how?

# Answer
Due to mostly historical but also database portability reasons does Drupal currently not use foreign keys.

That however doesn't stop you in any way to relate to other tables. All you need to do is insert the user id into your table and then to a JOIN to the users table if you want to query it. Or do a `user_load_multiple()` on the uid's separately. If you have a large amount of data, that might actually be better for performance (The default node list in Drupal does that because a LEFT JOIN can get very slow if you have millions of nodes).

You would have to do this in any way, foreign keys don't do this automatically. They do validate your data (e.g. you can't insert a non-existing uid) and you can define how to act when users are deleted (either prevent delete or delete the referenced records too, basically). In the case of users, this wouldn't help you anyway, due to the advanced and configurable User cancellation that Drupal does (e.g. you can configure it to re-assign all public data like comments to the anonymous user).
> 1 votes

---
Tags: 7, database
---


# Question
Title: Can't modify Content Access in Media Gallery Module
I've got the Media Gallery module installed and want to control the access to it using the Content Access module but can't find how to do that. I get an "Access Control" button on all my other regular pages but don't on the Media Gallery pages.

It sounded like there was an issue with permissions with Drupal 7.2 http://drupal.org/node/1147906 but it was fixed in 7.3. I'm running 7.8 right now. Thanks.

# Answer
Check the admin/structure/types/manage/media\_gallery/access settings page on your site and ensure that the *Enable per content node access control settings* checkbox is checked and then save.
> 0 votes

---
Tags: users, media
---


title: How to trace PHP errors

text:
# Question
Title: How to trace PHP errors
I am getting the following errors from Googlebot; I am getting about 5 of them per minute, and I want to find out what is causing them.

> Type php
> Date Friday, February 3, 2012 - 08:16
> User Anonymous (not verified)
> Location http://www.*******/biblio?f%5Bkeyword%5D=70&f%5Bag%5D=C&s=...
> Notice: Trying to get property of non-object in eval() (line 3 of /home/sltruweb/public\_html/modules/php/php.module(74) : eval()'d code).
> Severity notice
> Hostname 66.249.71.165

# Answer
> Notice: Trying to get property of non-object in eval() (line 3 of /home/sltruweb/public\_html/modules/php/php.module(74) : eval()'d code).

If we break this down, we get:

1. Severity: Notice. From PHP's perspective, not a big deal.
2. Actual problem: "Trying to get property of non-object". You have something like this: $foo-\>bar, where $foo is not an object, and as such, -\>bar does not apply
3. line 3 of /home/sltruweb/public\_html/modules/php/php.module, where the problem is happening.
4. eval()'d code: Your actual problem.

PHP Supports something called eval(). Eval() has some, but *very few* legitimate uses, and in most cases should be spelled "Evil", instead. Unfortunately, it's used liberally in the Drupal world because there's a module in Core that makes it easy to use. To support my argument, "Don't use it", I quote from PHP's own documentation:

> The eval() language construct is ***very dangerous***

Now *somewhere* in your site, you have an eval(). And that's one of the many issues with it, based upon your error message, I can't tell you any thing more meaningful than that. To track this down better, you need to update your question with a stacktrace. This however, is not necessarily easy to produce, and you may need the help of a skilled developer.
> 1 votes

# Answer
You are getting this because you have the PHP module turned on and somewhere in your site, either in a node, block, in a views filter, someone has added php code and it is failing. This will be difficult to find because it is in the database. It is also very dangerous because since you have the PHP module turned on someone could have added something you don't want.

You could solve this problem immediately by turning off the PHP module. You can search through your database for the `'<?php'` tag and troubleshoot the php statements you have on your site.

EDIT: It looks like somewhere in your biblio module configuration you are using inline PHP and it isn't using is\_object() or isset() for whatever parameters it is processing.
> 1 votes

# Answer
The PHP module is the module implementing the PHP input filter that is used to execute PHP code to create the content of a node. The process function for that input filter is php\_eval(), which is normally used from modules that needs to execute PHP code entered from a user; the Views module is one of them, and it allows the administrator user to enter PHP code in some of its settings. As the page referred from the warning error is produced by a view, if you look at the settings for that view you will find the code which is causing the error by trying to access an object property from something that is not an object. For example, if `$array` is an array, or a variable that has not been initialized, the following code will cause the warning you saw:

```
if ($array->nid) {
  echo "Node ID: {$array->nid}";
}

```

The `->` operator can only used with objects; using it for anything that is not an object raises a warning from PHP.
> 1 votes

---
Tags: debugging
---


title: SQL Error on main forum list page

text:
# Question
Title: SQL Error on main forum list page
I've just activated the Forum module and installed Advanced Forum. My 3 forums and 2 containers work when I browse straight to the forums and containers. The main list doesn't work though. When I go to /forum I get a SQL Error

> General Error
> SQL ERROR \[ mysqli \]
>
> Access denied for user 'username'@'hostname.com' (using password: YES) \[1045\]
>
> An sql error occurred while fetching this page. Please contact an administrator if this problem persists.

Isn't the main forum page supposed to list all the containers and forums like this http://drupal.org/forum? Do I have to enable anything or make a main container to make it do that?

# Answer
The error message is saying that the user you set in your settings.php file doesn't have access to the database, which could happen because the password you wrote in that file is not the correct one.

Any Drupal module that accesses the database is using the database API, which doesn't require any username or password, as those are taken from a file that Drupal reads during its bootstrap.
The Forum and the Advanced forum modules are not an exception. If you are getting that error, it means there is an error with the settings.php file, or a problem with the database server.
> 1 votes

---
Tags: 7, nodes
---


# Question
Title: Drupal 6 - specific template if node contains specific form element
I am trying to do a check for if some node contains an input element of type = hidden and with value = 'something'. If this is the case, some specific template should be used for the template.

I am trying to do this check in `template.php` using the `template_preprocess_node()` method where I have access to the `$vars` (`$vars['node']`) variable. However the only solution I can come up with is to loop through `$vars['node']->webform['components']` and to check for the input type and after that the value.

However I dont find this approach elegant, what are my options?

# Answer
> 0 votes
The relationship between nodes and webform components is maintained in the `webform_component` table so you should be able to get the data directly from there:

```
$sql = "
  SELECT COUNT(*)
  FROM {webform_component}
  WHERE nid = %d
  AND value = '%s'
  AND type = 'hidden'";

$args = array($vars['node']->nid, $field_value);

$count = db_result(db_query($sql, $args));

if ($count > 1) {
  // The webform has a hidden field with the correct value
}

```

---
Tags: 6, theming
---


# Question
Title: Can't restore profile-installed site after D7.12 core upgrade
I have just attempted to do another minor core upgrade from 7.9 to 7.12. While the former went rather smooth, the latter is giving me a headache. I constantly get fatal errors like these below:

```
Notice: Undefined index: schema_fields_sql in /includes/entity.inc on line 265

Catchable fatal error: Argument 2 passed to SelectQuery::fields() must be an array, null given, called in /includes/entity.inc on line 284 and defined in /includes/database/select.inc on line 1300

```

I am now in the middle of yet another attempt to restore the site

The difference in that website, compared to that which successfully passed the core upgrade, is that this was originally installed using commerce kickstart profile. And my questions are:

1. Has anyone successfully performed core upgrade within a profile-originated site?
2. What are safety rules to observe when doing such upgrades (apart from obvious backing up the files and database?)?
3. What approach you prefer for upgrading live sites? Do you usually create a new directory, which you test, and when ready, you redirect root catalog to that directory?

I hope your insights will bring back my confidence as per having chosen Drupal for commercial sites.

# Answer
> 1 votes
Did you remember to run update.php?

Also, Drupal 7.11 and 7.12 are both security updates. 7.12 includes bug fixes, while 7.11 only addresses the security problems. You might try 7.11 and see how it goes.

Also 2: Here's an issue thread about it.

---
Tags: commerce, distributions, upgrading
---


# Question
Title: Twitter Widget profile script outputting white screen?
Does anyone know why I'm receiving a white screen when I added the following code into a page panel?

```
<script charset="utf-8" src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 4,
  interval: 30000,
  width: 250,
  height: 300,
  theme: {
    shell: {
      background: '#333333',
      color: '#ffffff'
    },
    tweets: {
      background: '#000000',
      color: '#ffffff',
      links: '#4aed05'
    }
  },
  features: {
    scrollbar: false,
    loop: false,
    live: false,
    behavior: 'all'
  }
}).render().setUser('Twitter').start();
</script>

```

# Answer
> 1 votes
I've used the twitter widgets in blocks almost exactly (eg, different theme settings and users) like the above, and shoving a cut and paste of your code above works fine in a static .htm, so, I'd check your php and other console/error logs to see what drupal is upset about. First idea is an input filter is bolloxing it up.

---
Tags: panels, social-network
---


# Question
Title: Is it possible to have 2 different thumbnail image styles for the same field?
I'm importing videos and video thumbnails from a legacy site. A lot of video thumbnail have black boxes at the top and bottom due to the aspect ratio of the videos, for example:

I would like to crop all video thumbnails to remove those bars. I haven't done it yet but assume it's pretty easy to just modify the image style for "thumbnail".

Now, any new videos that will be uploaded (using the video module) or any of the images that use the thumbnail style don't need to be cropped that way. If I would change the image style for "thumbnail" after all videos are imported then I would lose the crop effect, right?

How can I solve this problem? I'm displaying all video thumbnails using views. Do I need to do a template override where I manually apply a different image style to those "legacy" videos?

# Answer
You can put more than one filter on a preset, so it is possible, depending on the aspect ratio of the new and the old, that you can add a first filter that will remove the black bands and a second that will change the size.

Otherwise, you might try programmatically making image style change the aspect ratio of all your old images, deleting your old images, then copying the images in your changed image style directory to your root file directory. Image styles doesn't change the name of the file.

If either of those options doesn't work for you, you can create a custom field formatter that looks at the file id and decides which image style preset to use (as you suggested above except don't so this in the theme system as the new formatter would be available to any node view as well as in the views module). See: http://www.computerminds.co.uk/articles/creating-new-field-formatters-drupal-7
> 1 votes

---
Tags: 7, files, media
---


title: Developing a mobile website

text:
# Question
Title: Developing a mobile website
I am using mobile tools module. It asks for path of mobile website. Does it mean that i need to develop mobile based pages again? i.e one for mobile and another for desktop ?

# Answer
Mobile tools will let you differentiate between what you consider to be your 'desktop' version and your 'mobile' version via the theme you choose. For example, www.example.org as your desktop and m.example.org as your mobile.

Mobile tools will try to redirect based on device detection, if you configure it that way. If you want the desktop version to show on all devices, computer and mobile, you can configure it that way as well, or include the desktop version for 'desktop and mobile.'

But, if you do want a separate mobile theme, there are several existing mobile themes out for drupal. To make that work you would have to install and enable the mobile theme, and then mobile tools will automatically select that theme when it detects the mobile based site.

Whatever version of the site you want to display on any device is very possible. It's just according to your goals for each device.
> 1 votes

---
Tags: 7, theming
---


title: Integer field type missing

text:
# Question
Title: Integer field type missing
I am using Drupal 7.12 and are missing the field type "integer". I only have the fields

```
Boolean
List (Text)
List (Float)
LIst (Integer)
Long Text
Long Text and Summary
Node Reference
Text

```

Maybe I am overseeing here something very basic, but it should be there AFAIK.

Thx for help,

n3rd

# Answer
Check and see if the core module "Number" is enabled. It requires the Field and Field SQL storage modules to be enabled as well.
> 10 votes

---
Tags: entities
---


# Question
Title: Building custom entities, but using existing modules?
I've noticed a lot of useful modules already created such as workflow, ACL, diff, and more. But these only seem to work with "content types". In our project, we have decided that "content types" aren't really well suited for what we need (Entities make more since). Very complex relationships must be modeled. Our entities are just that, entities, not content.

The problem is that when building an entity using hook\_schema() and hook\_entity\_info(), these entities are not available to be used with different modules such as workflow. Is there any way to make them available? Or will we have to code similar workflow functionality by hand?

Workflow does exactly what we need, except only on content types. We need it to work on entities as well.

# Answer
Especially in Drupal core, Nodes are still something like a Super-Entity with a number of features only supported by them, like revisions and the whole node\_access thing. The entity.module tries to implement these features generically for all entities, I'm not sure if everything is covered yet.

Many modules only support nodes both due to these missing features (You can't configure ACL's or workflows if there is no way to limit access in the API, diffing is pointless without revisions) and historical reasons (all of your listed modules are ports initially Drupal 6 versions or even older and have been ported to Drupal 7). The whole concept of entities represents a major shift in Drupal and not all modules have made that step (yet).

I guess that's one of the reasons why e.g. Commerce uses Nodes as the default way to display products.

Work is ongoing in Drupal 8 to unify these features and provide them for all kinds of entities.

This is not really an answer to your question, more an explanation of the status quo. As Alex already mentioned, many of those modules are working on supporting entities or an entity-aware successor is being worked on, like http://drupal.org/project/state\_machine.
> 2 votes

# Answer
Unfortunately you are out of luck. Had the same problem with Flag module recently but lucked out and found the Mark module which is similar but for entities.

That said, it might not as hard as it seems to hack the workflow module to use Entities instead. Check out this issue, it seems the module is going this way but it might take a while to get it accomplished.

*Disclaimer*: I don't encourage hacking contrib modules but in certain cases you could create a branch for your project needs and preferrably submit back patches if you are succesfull!
> 1 votes

---
Tags: nodes, entities
---


# Question
Title: Different Image on each Mainmenu entry in Drupal 7
there is a Logo and a variable picture in the header of my design. This picture depends on the current page.

Is there a plugin or even a build in setting, where i can configure this behavior?

# Answer
> 1 votes
You may try this module, which seems to do exactly that.

---
Tags: 7, theming
---


# Question
Title: Drupal 7: Article with Multiple Image Thumbnails Embedded in it
I'm using Drupal 7. Whats the best way to create an article with multiple images embedded at various places in the article.

The way I wish to do is that insert image thumbnails and then click it to open the full version in the lightbox or something. How do I achieve this.

Thanks,

# Answer
The colorbox and insert modules, as mentioned already, would solve your problem. First you want to create different image styles based on the sizes you would like to have, if they are standard. Then, the insert module would allow you to place those anywhere in the text of that specified style, one of which, for example, would be 'Colorbox: thumbnail.' When you click it, it would show up in a lightbox.

Another way to do this, which is the way I do sometimes, is using CKEditor with CKFile which will allow you to manually upload, resize, and insert any image at anysize you would like anywhere in your content.

Then, I use lightbox2 module and wrap that image in an A tag, href=# with rel="lightbox2"

with lightbox2 installed, this will force that tag to be opened in a lightbox. Be sure to read the lightbox2 help file as it will explain thorougly how to configure your A tags based on what you want to do with the images in your post.
> 4 votes

# Answer
With Colorbox and Insert, it should be a breeze.
> 6 votes

---
Tags: media
---


# Question
Title: drupal 7.12 : multiple taxonomy vocabularies in a single view exposed filter
One of my colleagues is working on a project for a departmental store. she wants to create a single views taxonomy drop down filter with multiple (7) vocabularies. The Vocabulary name should appear in the drop down menu but should not be selectable. Some of the vocabularies and their terms are as follows.

Footwear - sandals, shoes, boots, pumps etc

Trousers - chinos, jeans, bottoms

T-shirts - polo shirts, polo neck tops etc

Dresses - maxi, ballgown, one shoulder, tunic etc

Accessories - bags, watches etc

Questions is, is it best to use multiple vocabularies or one vocabulary with multiple parent terms and children. If she uses multiple vocabularies (e.g.. footwear, trousers, tshirts) how can she make the terms in each vocabulary appear in one filter as well as the vocabulary name (but should not be selectable).

On the other hand, if she uses one vocabulary with multiple parent terms and their children, hood can she make the parent terms appear in the drop down menu but not selectable. she tried this method but the drop down is too long and the parent terms are selectable.

alternatively, is it possible to make the vocabulary names appear in one filter and have another filter conditionally showing the terms in the vocabulary selected in the first filter. To add to the complexity, the second filter should show the terms with products and hide those without (this is not a priority). This method will be beneficial but she has no idea how to implement this.

Any suggestions will be greatly appreciated. Thanks in advance.

# Answer
I recently did the exact same thing for a client. The website is http://www.buyagainbaby.com.

You will notice there are 9 primary categories each with subcategories. I achieved this by creating 9 different taxonomies. After researching this for weeks, I found this was the best solution. Here is how I did it.

9 taxonomies, each named for the product category you want, Footwear, Trousers, etc, then add as many terms as needed to each vocabulary. Now create one content type for each corresponding category and then assign that vocabulary to that managed fields area. At least this is how I did it. It was a bit of a chore to get setup, but, bit was worth it. All the search functionality is done with views filters and having it architectured like that lets me do some very complicated things with filters and views. Let me know if you have questions. Oh one more thing, keep the content type name the same as the vocabulary name, and that will help tremendously in simplified complicated views to return products, etc.
> 1 votes

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


# Question
Title: Getting the value submitted from form with FAPI radios in template.php
I have a form with radios on it. I do submit on the same page (there's no $form\['#action'\] assigned in the below code). What I want to do is to get submitted year in template.php so that I can define my logic based on received value.

To check that's all work fine I wanted print\_r the contents of form\['values'\]. I did that in submit function but it didn't work. Actually, I can't print anything from both validate and submit functions.

So my question is how I can get the submitted value to template.php.

I work with the following code in my module:

```
function my_module_menu() {
  $items['formexample'] = array(
    'title' => 'View the sample form',
    'page callback' => 'mymodule_page',
    'page arguments' => array('frontpage_form'),
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM
  );
  return $items;
}

function mymodule_page() {
  $output = print_r($_POST, true);
  $output .= drupal_get_form('mymodule_form');
  return $output;
}

/**
* Define a form.
*/
function frontpage_form() {
  $form['years'] = array(
    '#title' => t('Please, choose appropriate year'),
    '#type' => 'radios',
    '#options' => array(
      t('2011'),
      t('2012'),
      t('2013')
     ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit')
  );
  return $form;
}

/**
* Validate the form.
*/
function frontpage_form_validate($form, &$form_state) {
  if ($form_state['values']['user_name'] == 'King Kong') {
    // We notify the form API that this field has failed validation.
    form_set_error('user_name',
    t('King Kong is not allowed to use this form.'));
  }
}

/**
* Handle post-validation form submission.
*/
function frontpage_form_submit($form, &$form_state) {
  $name = $form_state['values']['years'];
  drupal_set_message(t('Thanks for filling out the form, %name',
  array('%name' => $name)));
}

```

# Answer
In fact I was needed smth like this:

a way to get the submitted value into `template.php`:

In a module file

```
function frontpage_form_submit($form, &$form_state) {
  frontpage_submitted_value($form_state['values']['some_value']);
}

function frontpage_submitted_value($new_value = NULL) {
  if ($new_value) {
     cache_set('years',$new_value,'cache');
  }else{
     return cache_get('years');
  }
}

```

And then in a function in `template.php`

```
if ($submitted_value = frontpage_submitted_value()) {
  $vars['some_val'] = $submitted_value;
}
cache_clear_all('years','cache');

```

Clive's solution with `&drupal_static(__FUNCTION__, FALSE);` didn't work since, according to this, '... static variable technique only stores data for the duration of a single page load.'
> 2 votes

# Answer
I think the problem is that your `#options` array for the radios isn't keyed (which it should be). PHP will automatically assign the keys as `0`,`1`,`2` etc but `0` is not valid as Drupal ignores such a value which may be causing you a problem, and I guess you're expecting a value of `2011`, `2012` or `2013` which currently you won't get.

Drupal does provide a handy function, `drupal_map_assoc` to create a keyed array from a flat one. This code:

```
$array = drupal_map_assoc(array(1, 2, 3));

```

will produce an array of

```
array (
  1 => 1,
  2 => 2,
  3 => 3
)

```

So if your form element looks like this:

```
$form['years'] = array(
  '#title' => t('Please, choose appropriate year'),
  '#type' => 'radios',
  '#options' => drupal_map_assoc(array(2011, 2012, 2013))
);

```

In your submit function you would grab the selected value with:

```
$form_state['values']['years'];

```

I think you might have a slight confusion in your logic, this bit of code:

```
$name = $form_state['values']['years'];

```

is fine to grab values from the `$form_state` array but `years` is not a name, it's a year. That might also be adding to the confusion.

**EDIT**

I've just noticed a few other problems in your code that may be causing unexpected results.

The first one is in `mymodule_page()`. `drupal_get_form()` returns an array in Drupal 7 so concatenating it to a string (the return from `print_r()`) will not produce the results you're expecting.

Secondly, you're calling `drupal_get_form('mymodule_form');` and your form is actually named `frontpage_form()`.

Lastly, you don't actually need the `mymodule_page()` function at all...you can change the `page callback` of your menu item to `drupal_get_form()` and the form will automatically be built for you on that page. Remember to clear Drupal's cache once you've made this change.

The last thing I'd say is that relying on `print_r` for debugging can be very tedious. Instead, I'd advise installing the Devel Module which has a wonderful function called `dpm()`. This will print a nicely formatted representation of any variable to the standard messages area when you call it. It's a must for Drupal development really.

You'd use it like this, for example in your form submit handler:

```
dpm($form_state['values']);

```

**EDIT 2**

Quick dirty way to get the submitted value into `template.php`:

In your module file

```
function frontpage_form_submit($form, &$form_state) {
  frontpage_submitted_value($form_state['values']['some_value']);
}

function frontpage_submitted_value($new_value = NULL) {
  $value = &drupal_static(__FUNCTION__, FALSE);

  if ($new_value) {
    $value = $new_value;
  }

  return $value;
}

```

And then in a function in `template.php`

```
if ($submitted_value = frontpage_submitted_value()) {
  $vars['some_val'] = $submitted_value;
}

```
> 5 votes

# Answer
Answering the actual question:

> The user input from the form are available in $form\_state\['values'\].

The way you formulated the question however doesn't make sense. You clearly already now the answer, since your code has

```
$name = $form_state['values']['years'];

```

but you say you've tried print\_r($form\[values\]); which obviously isn't going to work, since you're looking in the wrong variable. Then, why you would expect to find 'user\_name' in the form I don't understand, since all you declare is 'years'.
> 3 votes

---
Tags: 7, forms
---


# Question
Title: Changing Drupal's default email notification on password reset
I need to change the text the user gets in the email with the one time login url. How can I do that? By the way, say I want to generate a login url from my module, is that possible? I'm using drupal 6

# Answer
Pop to http://www.mysite.com/admin/user/settings, you can edit the subject and body for the email under the "Password Recovery Email" fieldset.

To do this programatically you can call `_user_mail_notify()` with the `password_reset` op parameter:

```
_user_mail_notify('password_reset', $account);

```

You can generate a one-time login link using the `user_pass_reset_url()` function:

```
$url = user_pass_reset_url($account);

```
> 3 votes

---
Tags: users
---


# Question
Title: Avoid new user notification on user_save
I'm currently importing a whole bunch of users to a site programmically through user\_save. How can I make sure that no registration mails are sent to the users?

```
// Create new user
$newUser = array(
    'name' => $member->name,
    'pass' => $member->password,
    'mail' => $email,
    'field_user_fullname' => array('und' => array(array('value' => $member->navn))),
    'status' => 1,
    );
user_save(null, $newUser);

```

# Answer
I can't find a way to do that. user\_save doesn't take such an argument. I believe you have two options.

1. Emulate the user\_register\_submit() call by passing your data in as a form instead, this is preferably done with drupal\_form\_submit(). It just so happens that the example deals with user-registration.
2. Just kill outgoing e-mails while you import your users.
> 3 votes

# Answer
The simple answer is you can't I'm afraid, it's hard-coded into the `user_save()` function with this bit of code:

```
// Send emails after we have the new user object.
if ($account->status != $account->original->status) {
  // The user's status is changing; conditionally send notification email.
  $op = $account->status == 1 ? 'status_activated' : 'status_blocked';
  _user_mail_notify($op, $account);
}

```

That checks the original account object (which is loaded up there and then so it can't be altered) against the new account object and if there's a difference in the status it sends an email.

The only way I can think to do it would be to simulate a submission of the `user_register_form` which has a checkbox denoting whether or not to notify the user of changes.
> 3 votes

---
Tags: users
---


# Question
Title: How to display select query results using ajax in a form in drupal7
Please give me some solution for this. I want to display the Database select query results in a form using ajax in drupal 7.

# Answer
> 1 votes
Without specifics it's tricky to answer your question but here's a very basic example:

```
function MYMODULE_some_form($form, &$form_state) {
  $form['select'] = array(
    '#title' => 'Option',
    '#type' => 'select',
    '#options' => drupal_map_assoc(array(1,2,3)),
    '#ajax' => array(
      'wrapper' => 'some-form-results-wrapper',
      'callback' => 'MYMODULE_some_form_ajax'
    )
  );

  $form['results'] = array(
    '#prefix' => '<div id="some-form-results-wrapper">',
    '#suffix' => '</div>'
  );

  // If the form has been submitted, build up your results and display them
  if (isset($form_state['values']['select'])) {
    $rows = db_select('some_table', 't')
      ->fields('t')
      ->condition('some_field', $form_state['values']['select'])
      ->execute()
      ->fetchAll();

    $header = array();

    $form['results']['#markup'] = theme('table', array('header' => $header, 'rows' => $rows));
  }
  else {
    $form['results']['#markup'] = '<p>The results will appear here when you change the dropdown option.</p>';
  }

  return $form;
}

function MYMODULE_some_form_ajax($form, &$form_state) {
  return $form['results'];
}

```

You might want to check out the `ajax_example` module included as part of the Examples module, it has a lot of code and comments that will help you understand what every piece of the above example does.

---
Tags: ajax
---


# Question
Title: Display Ubercart sell price in Apache Solr search results
I manage an ubercart store that is indexed by Apache Solr. The search indexes the sell price and it's one of the facets. However, the price is nowhere in search-result.tpl.php. It's also not available in the search results preprocess hook in template.php. Is there somewhere else I can inject it into the search results without performing a separate database query for each search result.

# Answer
> 1 votes
You can index it using solr's dynamic fields (see your schema.xml in the solr conf directory) and a custom module hook, namely `hook_apachesolr_update_index()`.

Then you can, at search time, add the field you have indexed into the fields being fetched. For this you have three hooks or 'hooks' to choose from: `hook_apachesolr_prepare_query()`, `hook_apachesolr_modify_query()` and `CALLER_finalize_query()`.

For further information on the hooks, see the **README.txt** in the apachesolr module directory.

Then in your **search-result.tpl.php** you'll have available the custom indexed field as `$result['fields']['your_field_name']`.

---
Tags: 6, search
---


title: Menu Call Back for Ajax not working

text:
# Question
Title: Menu Call Back for Ajax not working
Below is the code in my module. I want to do an ajax posting to path test\_call. But when am doing that am getting a 404 error message.

```
<?php

function callback_permission() {
  return array(
    'access simple page' => array(
      'title' => t('Access callback'),
      'description' => t('Allow users to access callback'),
    )
  );
}

function callback_menu() {

   $items = array();
   $items['test_call'] = array(

    'page callback' => 'callback_test',
    'access arguments' => array('access simple page'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function callback_test()
{

 return "success";

}

```

I am

# Answer
> 1 votes
Your menu item looks fine so make sure you've done the usual things, make sure the module is installed and enabled, and make sure you clear Drupal's caches so the menu is rebuilt and your new item can be picked up.

On another note, if this callback is meant for AJAX you probably want to be printing something rather than returning it in your callback function. Something like this:

```
function callback_test() {
  print 'success';
  drupal_exit();
}

```

---
Tags: 7, routes, ajax
---


# Question
Title: Redirect to previous non drupal page after login
I have installed Drupal 7 on azeem.com, and I have installed a forum software on azeem.com/qa. I am trying to use Drupal as single sign on site.

When I am at azeem.com/qa, and I click on login page, it takes me to the Drupal login page with a URL like http://azeem.com/user/login?redirect=qa%2Findex.php%3Fq%3Dnode.

After giving the username and password, I successfully logged in, but instead of redirecting me back to http://azeem.com/qa, it takes me to http://azeem.com/user/1.

How can I redirect back to the page where I was before logging in?

# Answer
Drupal doesn't react by default to a URL parameter called `redirect`; it does however react to the parameter `destination`. The `destination` parameter pretty much trumps any other internal redirect so this should override the default redirect.

When you send your users through to the Drupal login form try using a URL like this:

```
http://azeem.com/user/login?destination=qa

```
> 3 votes

---
Tags: redirection, users
---


title: Mysql queries help

text:
# Question
Title: Mysql queries help
I have a mysql table as below..

The data in the table is as follows,

I want to get the total calorie by a user on a particular day (let's say Feb 20). I execute the below query to get the result.

```
SELECT sum( calorie ) AS sum
FROM test
WHERE extract(DAY FROM date ) = 20 AND extract(MONTH FROM date ) = 02
AND extract(year FROM date) = 2012
AND user_name = 'akshaynhegde';

```

The result I get is...1500 (as sum), which is exactly what I want. How do I execute this query in Drupal 7? I know how to execute it in Drupal 6, but I just upgraded to Drupal 7 and I am having many difficulty in executing queries.

//////////////////////**MY ANSWER**//////////////////////////////////

Here is a working Drupal & style code for the above query...

```
<?php
$query = db_select('test', 't')
->condition('t.user_name', 'akshaynhegde', '=');
$query->addExpression('SUM(calorie)', 'sum');
$query->where('EXTRACT(DAY FROM date) = :day', array('day' => '20');
$query->where('EXTRACT(MONTH FROM date) = :month', array('month' => '02');
$query->where('EXTRACT(year FROM date) = :year', array('year' => '2012');
$result = $query->execute()->fetchAll();
?>

```

# Answer
> 7 votes
You could use `db_query()` in your template file:

```
function theme_get_calories($user, $year, $month, $day) {
   $result = db_query("SELECT sum( calorie ) AS sum
                      FROM test
                      WHERE extract(DAY FROM date) = :day
                      AND extract(MONTH FROM date) = :month
                      AND extract(year FROM date) = :year
                      AND user_name = :user",
                      array(
                        ':day' => $day,
                        ':month' => $month,
                        ':year' => $year,
                        ':user' => $user
                      )
   )->fetch();
   return $result;
}

```

---
Tags: 7, database
---


title: Admin menu layout for my nodes

text:
# Question
Title: Admin menu layout for my nodes
I have a simple question: i need to use the layout and structure of drupal admin menu for my own nodes. I need to replicate the structure and the feeling of admin menu and the page design for my nodes, how can i do that? I need to replicate exactly the way the admin menu acts and feel on the body part of the site, so with two columns, groups of subtopic for each main topic, links listing for each level and my nodes as leafs of this structure. Since this is already done on the admin menu, it should be possible to do it also with my own nodes, but how? I am using Drupal 6

# Answer
> 1 votes
My thoughts are that you could use views to list various categories of nodes. And to have a similar layout structure, I haven't used it but I think Panels might help.

An alternative to Panels which I have used in the wonderful homebox module

---
Tags: routes, theming
---


# Question
Title: Custom Key Value fields in a content type
I am searching for functionality similar to the Double Field module only for Drupal 6.

Does anyone know of a suitable module or if not, could you outline an approach to creating this functionality?

Thanks, apologies if this is poorly explained.

# Answer
> 0 votes
I realise I'm answering my own question here but I've done some digging and come across the TableField module.

Does anyone have any experience with this?

It appears to do something along the lines of DoubleField.

---
Tags: 6, entities
---


# Question
Title: Rewrite output in a view using CCK fields
I'm trying to rewrite the output of a field. I have 4 fields and in the last one, I have rewrite output enabled:

```
<h2 class="speaker-name">[title]<h2>
<h3><span class="speaker-job-title">[entity_id_3]</span>, <span class="speaker-company">[entity_id_1]</span></h3>
<div class="speaker-body">[entity_id]</div>

```

The fields that are included in this output have "Exclude from display" checked so that's not a problem.

The problem is that the output turns into this:

```
<span class="views-field views-field-entity-id-4">
<span class="field-content"/></span>
<h2 class="speaker-name"><a href="/?q=speaker/mr-speaker">Mr Speaker</a></h2>
<h2></h2>
<h3>
    <span class="speaker-job-title">
        <div class="field field-name-field-job-title field-type-text field-label-hidden">
         <div class="field-items">
         <div class="field-item even">Manager, Hotels</div></div></div></span>, <span class="speaker-company"><div class="field field-name-field-company field-type-text field-label-hidden"><div class="field-items"><div class="field-item even">Hotel Inc.</div></div></div>
    </span>
</h3>
<div class="speaker-body">
<div class="field field-name-body field-type-text-with-summary field-label-hidden">
<div class="field-items"><div property="content:encoded" class="field-item even">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et libero vel mi fringilla commodo ac ac felis. Proin fringilla tempor diam, ut semper dui vestibulum in. Vestibulum arcu tellus, elementum ac consectetur ac, tincidunt non eros. Nunc tempor ipsum eget erat fringilla tempus ut a enim. Donec posuere luctus mauris id ornare. Fusce at est lorem, et consectetur sapien. Pellentesque ac purus ac augue dignissim aliquet a rutrum turpis.</p>
</div>
</div>
</div>
</div>

```

The fields that are part of the rewritten output are still wrapped in an HTML wrapper or label wrapper. I have no idea how to remove this and display just the field value.

# Answer
> 0 votes
I found a workaround, not sure if it's the correct solution...

If you go to all the fields that are being rewritten into another field and click "Strip HTML Tags", it will display properly. I think it strips out the tags around the field just before it's rewritten into the other field.

# Answer
> 0 votes
In D6, you would look for the HTML Element, Label HTML Element and Wrapper HTML Element dropdowns in the Style Settings of the fields and set them to none. I am assuming (there I go again) that something similar is there in D7.

# Answer
> 0 votes
You can! In the field settings, there is a "Style settings" fieldset that allows you to customize the field's HTML.

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


# Question
Title: how do i set the first page of my site in drupal 6?
I am new to drupal.

I started ctreaing site but facing problem in

how do set my first page in drupal

eg:

when user type

www.mysite.com

he should redirect to first page....

# Answer
Go to: admin/settings/site-information. In the section of "DEFAULT FRONT PAGE" you can set a default page for you site. (The page for default is node.)

If you have another page that you want to become in the default page, only copy the url of the page and put this in "DEFAULT FRONT PAGE."
> 0 votes

# Answer
Have you been to /admin/settings/site-information and set the homepage from there? At the bottom put the node address into Default Front Page field, something like node/1 (or whatever node number you want the front page to be)
> 1 votes

---
Tags: views
---


# Question
Title: Tree with linked structure and node leafs
I am working with Drupal 6 and i need to create a 3 level tree with 2 levels of links(topic and subtopic) and a third level of faqs. Example:

```
Topic1
--Subtopic1
----FaqA
----FaqB
--Subtopic2
----FaqC
----FaqD
----FaqE
--Subtopic3
----FaqF
----FaqG
Topic2
--Subtopic4
----FaqH
----FaqI
----FaqJ
--Subtopic5
----FaqK
----FaqL
--Subtopic6
----FaqM
----FaqN
----FaqO

```

The thing important to me is that:
I am in the root(home)-\> I need to see all the topics and subtopics;
I click on a topic -\> I need to see all the subtopics of that topic;
I click on a subtopic -\> I need to see all titles of the faqs of that subtopic;
I click on a faq title -\> I need to see the full faq node;

Each page need to have a breadcrumb that shows where the user is. The topic and subtopic pages have just a list of links to childrens, so i don't know if they have to be nodes, so maybe i just need the Faqs to be node, but i don't know how to build the topic and subtopic structure and from my tests i didn't find anything fitting (i have checked "book" content, cck, custom breadcrumb, node hierarchy and many other) Can anyone help me?

# Answer
> 0 votes
Solved!

I have used this piece of code, palced on the "header" of the view, to obtain my goal:

```
$term = taxonomy_get_term(arg(1));
$parent = current(taxonomy_get_parents(arg(1)));
$name = $term->name;
echo "<h5>".$parent->name."</h5>"; //topic
echo "<h2>".$name."</h2>"; //subtopic
$breadcrumb = array();
$breadcrumb[] = l('Home', '<front>');
$breadcrumb[] = l('Topic', 'Topicview');
$breadcrumb[] = l(drupal_get_title(), base_path() . request_uri());
drupal_set_breadcrumb($breadcrumb);

```

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


# Question
Title: My site was hacked, how can I use chmod permissions to avoid this?
To be honest, only the home page was switched (even the text that was modified bragged about this, grrrr!), but still... not pleasant at all.

So the important question, and something that was on my mind for a long time but never got around to ask:

which files MUST be read-only or what kind of permissions should I had to enforce in which files to make this at least a bit more difficult?

Thanks in advance.

# Answer
See: Securing file permissions and ownership

You also might want to try adding the Security Review module to help make sure your site is following the correct file permission settings.
> 10 votes

---
Tags: 6, security
---


# Question
Title: How to hide a block entirely if it's empty
I've added a series of blocks to my template file for a specific content type. These blocks are built in Views and they show Downloads filtered by the specific content you are viewing. For example, on the Product A page, the Product Literature block shows all downloads categorised as Product Literature specifically associated with Product A.

There is a block for Product Literature, a block for Videos (set up in a similar way) and a block for Publications (again, set up in a similar way).

At the moment, if there aren't any videos for Product X, the heading Product X still displays for Video Gallery, is there a way I can detect if there is any content under the Video Gallery heading and if there isn't, choose not to display it?

Each block is printed as below:

```
$block = module_invoke('views', 'block_view', '712046d635e195e59dd93bd378e45423');
print "<h2>Product Literature</h2>";
print render($block);

```

# Answer
If you create blocks from the views interface itself it will not print the block if there are no results. I would recommend this method since it saves time and complexity. If you need to change the template for the block being created by the view you can do so. There is a lot of documentation on how to do that. Here is an example: Create template file for views block

In the case of what you have written below you could do something like:

```
$block = module_invoke('views', 'block_view', '712046d635e195e59dd93bd378e45423');
if (isset($block)) {
print "<h2>Product Literature</h2>";
print render($block);
}

```

but I would highly recommend the approach above.
> 2 votes

---
Tags: blocks, theming
---


# Question
Title: How do I display Search API Facets and Openlayers Proximity search in one view?
I am trying to add search facets to a specific views page that uses the openlayer proximity filter. So far I can only show facets in a view if I create a new view showing the search index I created in the search api.

If I chose to show 'node' or anything else other than a search api index, no facets will show up.

Now I am using openlayers proximity filter. This option again is only available if I chose show 'node' when creating a new view.

How do I get to display both my facets as well as the proximity filter in a view?

# Answer
> 1 votes
The "facets block" type that drunken monkey mentions on the issue you link to, is simply a type of views "Display", you can see below where you add one: I haven't used the proximity filter, nor much of Search API, so I can't really give you an answer with better details. It seems to be like drunken monkey has actually answered the question in the issue queue, and perhaps you need to specify more precisely where you have a problem, to get better help.

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