# Question
Title: Drupal 7 adding rel to the href's of Login and Registration
I'm using Lightbox as a modal box solution and have been having an issue trying to get modal windows for the default Login and Registration links. I'm trying to access from inside a module that I"m currently using to make all the changes. I've tried several other "Box" solutions and Lightbox seems to be what I'm looking for, but I cannot figure out the hook to add rel='lightbox' to login and reg. Could someone point out what it is for me?

**EDIT** I tried using this in my base theme, which will give me a modal on both reg and login, but shows an empty form?

function spti\_base\_preprocess\_page(&$variables) {

```
/* .....stuff..... */

    // add the system user-menu into the page as its own thing
    $variables['platform_user_menu'] = menu_navigation_links('menu-platform-user-menu');

    foreach($variables['platform_user_menu'] as &$hijackLinks) { $hijackLinks['attributes']['rel'] = 'lightframe'; }

    $variables['page']['platform_user_menu'] = array(
      '#theme' => 'links__system_user_menu',
      '#links' =>   $variables['platform_user_menu'],
      '#attributes' => array(
        'id' => 'platform-user-menu',
        'class' => array('links', 'inline', 'clearfix'),
      ),
  );

/* .....stuff..... */

}

```

# Answer
Yes you could spend time tearing apart templates, and hacking in the required code, I would say the cleaner, 'more drupal' solution would be to use a combination of

From the project page:

> This simple module allows you to specify some additional attributes for menu items such as id, name, class, style, and rel.
> 1 votes

---
Tags: 7, users, javascript
---


# Question
Title: Rules: Set a data value for a taxonomy term reference on the user profile
I am trying to attach zodiac signs (stored as terms in a vocabulary) to user profiles.

I have a rule with a "Set data field" action that, upon updating a user profile, sets account:field-user-zodiac (a term reference to a vocabulary with 12 terms, one for each sign of the zodiac) to an arbitrary sign (Capricorn) using direct input mode (a select box of all of the terms appears).

However, upon doing so, when I update a user profile I experience a white screen of death. Disabling the rule makes the site work normally again, so obviously the rule is the problem, but I don't know how to go about fixing it.

Again, I'm trying to use "Set data value" to set a term reference field in a user profile to an arbitrary term. Any insights about how to set this up in rules?

UPDATE (Feb. 2) I figured out how to enable PHP error reporting. The error is shown below.

I'm confused as to why the fatal error is "cannot redeclare getStarSign()", because getStarSign() is a function in my computed field, yet the part of the rule causing the white screen of death is the "set data value" action, which does not refer to the computed field; "set data value" sets the taxonomy reference field. I know this is the cause because if I delete the "set data value" action the error disappears. Any ideas?

> Fatal error: Cannot redeclare getStarSign() (previously declared in /home/quickstart/websites/omj.dev/sites/all/modules/contrib/computed\_field/computed\_field.module(465) : eval()'d code:1) in /home/quickstart/websites/omj.dev/sites/all/modules/contrib/computed\_field/computed\_field.module(465) : eval()'d code on line 22
> Call Stack:
> 0.0001 668296 1. {main}() /home/quickstart/websites/omj.dev/index.php:0
> 0.1744 48404872 2. menu\_execute\_active\_handler() /home/quickstart/websites/omj.dev/index.php:21
> 0.1753 48642216 3. call\_user\_func\_array() /home/quickstart/websites/omj.dev/includes/menu.inc:517
> 0.1753 48642832 4. drupal\_get\_form() /home/quickstart/websites/omj.dev/includes/menu.inc:0
> 0.1754 48644232 5. drupal\_build\_form() /home/quickstart/websites/omj.dev/includes/form.inc:123
> 0.2481 51569552 6. drupal\_process\_form() /home/quickstart/websites/omj.dev/includes/form.inc:366
> 0.2766 52599888 7. form\_execute\_handlers() /home/quickstart/websites/omj.dev/includes/form.inc:846
> 0.2766 52607608 8. user\_profile\_form\_submit() /home/quickstart/websites/omj.dev/includes/form.inc:1432
> 0.2774 52625928 9. user\_save() /home/quickstart/websites/omj.dev/modules/user/user.pages.inc:317
> 0.3132 55387344 10. module\_invoke\_all() /home/quickstart/websites/omj.dev/modules/user/user.module:557
> 0.3134 55389880 11. call\_user\_func\_array() /home/quickstart/websites/omj.dev/includes/module.inc:819
> 0.3134 55390496 12. rules\_entity\_update() /home/quickstart/websites/omj.dev/includes/module.inc:0
> 0.3134 55392016 13. rules\_invoke\_event() /home/quickstart/websites/omj.dev/sites/all/modules/contrib/rules/modules/events.inc:77
> 0.3209 58050816 14. RulesEventSet-\>executeByArgs() /home/quickstart/websites/omj.dev/sites/all/modules/contrib/rules/rules.module:777
> 0.3351 60502680 15. RulesState-\>cleanUp() /home/quickstart/websites/omj.dev/sites/all/modules/contrib/rules/includes/rules.plugins.inc:685
> 0.3351 60503256 16. RulesState-\>saveNow() /home/quickstart/websites/omj.dev/sites/all/modules/contrib/rules/includes/rules.state.inc:74
> 0.3352 60503808 17. EntityDrupalWrapper-\>save() /home/quickstart/websites/omj.dev/sites/all/modules/contrib/rules/includes/rules.state.inc:229
> 0.3352 60503808 18. entity\_save() /home/quickstart/websites/omj.dev/sites/all/modules/contrib/entity/includes/entity.wrapper.inc:807
> 0.3352 60503808 19. entity\_metadata\_user\_save() /home/quickstart/websites/omj.dev/sites/all/modules/contrib/entity/entity.module:181
> 0.3352 60509520 20. user\_save() /home/quickstart/websites/omj.dev/sites/all/modules/contrib/entity/modules/callbacks.inc:707
> 0.3363 60525136 21. field\_attach\_update() /home/quickstart/websites/omj.dev/modules/user/user.module:541
> 0.3363 60525272 22. \_field\_invoke() /home/quickstart/websites/omj.dev/modules/field/field.attach.inc:958
> 0.3367 60535912 23. computed\_field\_field\_update() /home/quickstart/websites/omj.dev/modules/field/field.attach.inc:209
> 0.3367 60535912 24. \_computed\_field\_compute\_value() /home/quickstart/websites/omj.dev/sites/all/modules/contrib/computed\_field/computed\_field.module:239

# Answer
> 0 votes
I finally located the cause of this error. I was using a computed\_field which was getting called in such a way that it was being re-declared, causing the error. Rewriting the function solved the problem.

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


# Question
Title: How do I shorten the length of all form input text fields?
I'm using Drupal 7, for which the standard length of an input text field is 60. Is there any way to shorten this for ALL fields at once? I want all the forms on my site to be no wider than 40.

I know that `hook_form_alter()` can be used to do this one-by-one, but I have a rather large number of fields on my site, and I would like to edit their lengths all at once if possible.

# Answer
> 7 votes
Pretty much all textfields on a Drupal site should have a "form-text" class attached to them so you could set the size/width limitation via CSS: `input.form-text {max-width: 250px;}`. Adding a quote from w3schools to that:

> Since the size attribute is a visual design attribute, it is recommended to use CSS instead.

# Answer
> 8 votes
There are a couple of things you can do depending on whether you want to do this on a theme level or site-wide level (i.e. independent of theme).

On the theme level you can override `theme_textfield()` and set the size there:

```
function MYTHEME_textfield($variables) {
  $new_size = 40;
  $variables['element']['#attributes']['size'] = $new_size;

  // EDITED per kiamlaluno's comment regarding infinite loops
  return theme_textfield(array('element' => $variables['element']));
}

```

On a site-wide level you can write a small module and implement `hook_element_info_alter()` to change the default that's provided by `system_element_info()`:

```
function MYMODULE_element_info_alter(&$type) {
  $new_size = 40;
  $type['textfield']['#size'] = $new_size;
}

```

You'll want to clear Drupal's cache once you've implemented either of these methods to clear the relevant registry.

It's worth noting that if you use the first method any specific sizes for textfields set by other modules (e.g. size 10 for numeric fields) will be overwritten with your new size. If you use the second method that will become the *default* but other modules will still be able to provide a specific size for specific textfields.

**EDIT**

I've just had another thought on this, probably the best way is to do it is in your theme function and check the existing length. That would match your statement "I want all the forms on my site to be no wider than 40" a bit better:

```
function MYTHEME_textfield($variables) {
  $new_size = 40;
  if (isset($variables['element']['#attributes']['size']) && $variables['element']['#attributes']['size'] > $new_size) {
    $variables['element']['#attributes']['size'] = $new_size;
  }

  // EDITED per kiamlaluno's comment regarding infinite loops
  return theme_textfield(array('element' => $variables['element']));
}

```

---
Tags: theming, entities
---


# Question
Title: Is there a way to set up a default layout for a scholar site in Open Scholar?
I would like new scholar sites to have a specific widget found in the Open Scholar layout editor set in a certain region. Is it possible to set up/change the default template for the layout of scholar sites?

# Answer
Assuming you're using the web-based installer here, it is possible to update this but you're going to have to do it by editing the install profile script. In your sites directory, you're looking for the file:

```
/docroot/profiles/openscholar/openscholar.profile

```

You're going to want to add a function, openscholar\_profile\_final() here (following this guide: http://drupal.org/node/67921) and add a function to add your blocks in:

```
db_query("INSERT INTO {blocks} VALUES ('blockname', '0', 1, 0, 1, 0, 0, 1, 'my*', '')");

```
> 0 votes

# Answer
Implement `hook_vsite_widgets_alter()` and change the widget region to a specific region name. See http://openscholar.harvard.edu/help/vsite/widgets-create.
> 0 votes

---
Tags: 6, panels, distributions
---


title: All Pages Redirecting To Frontpage

text:
# Question
Title: All Pages Redirecting To Frontpage
I am hoping that someone could assist me with a Pressflow problem on here as i cant find anywhere at all to discuss Pressflow. I have just updated my site to the latest version of Pressflow which was updated with the recent Drupal update. I uploaded all the files and now i can only access the frontpage of my site.

http://onlinebanter.com

If you try to click any links it just displays the front page. Would it be something to do with the htaccess file possibly?

All help appreciated as my site is effectively down with this problem and i dont know where to turn nor have the technical know how.

Thanks

# Answer
> 0 votes
Thanks Malks. Yip it was the htaccess file i overwrote folks. I just edited that again with my website url in 2 spots and everything was hunky dory again.

---
Tags: updating, .htaccess
---


title: Repair Table After Server Upgrade

text:
# Question
Title: Repair Table After Server Upgrade
Hello i hope someone can help me with this on here as i posted on drupal.org and folks told me it wasnt a drupal issue. I dont mind learning stuff but ive got so much drupal things that i do know about to get on with to get my site open that i dont want to spend a week trying to learn more about databases. All help appreciated. thanks.

My hosting company upgraded their servers the other now. Now my statistics module is all messed up and it's asking me to repair a table. The error message is-

> User warning: Table './onlineba\_d939/node\_counter' is marked as crashed and should be repaired query: SELECT totalcount, daycount, timestamp FROM node\_counter WHERE nid = 4389 in \_db\_query() (line 148 of /home/onlineba/public\_html/includes/database.mysql.inc).

and

> User warning: Table './onlineba\_d939/node\_counter' is marked as crashed and should be repaired query: SELECT node.nid AS nid, node.title AS node\_title, node\_counter.totalcount AS node\_counter\_totalcount FROM node node LEFT JOIN og\_ancestry og\_ancestry ON node.nid = og\_ancestry.nid LEFT JOIN node node\_og\_ancestry ON og\_ancestry.group\_nid = node\_og\_ancestry.nid LEFT JOIN og\_uid og\_uid ON node.nid = og\_uid.nid LEFT JOIN node\_counter node\_counter ON node.nid = node\_counter.nid WHERE (node.status = 1) AND (og\_uid.uid = 1) ORDER BY node\_counter\_totalcount DESC LIMIT 0, 10 in \_db\_query() (line 148 of /home/onlineba/public\_html/includes/database.mysql.inc).

I have access to PHPmyadmin and i have a very very basic understanding of it. Is there a line of code or query i need to put in it to repair? I should go look maybe there is just a repair button. I think i saw that before. Anyone offer me any help before i destroy everything?

thanks

# Answer
> 0 votes
Since you have PHPMyAdmin, you should be able to fix this with some point and clicking.

1. Navigate to the node\_counter in your Drupal database
2. Go to the 'Operations' tab
3. Hit check tables
4. If something isn't right it should give you the option to repair

If the option to repair doesn't come up and it doesn't appear in the Operations tab (some of these move around version to version of PHPMyAdmin), you can run the command

```
REPAIR TABLE node_counter;

```

from the SQL tab.

Good luck!

---
Tags: database, nodes
---


# Question
Title: Create an Exposed Filter for Integer Values Using Drop Downs
I'm creating a real estate search, and I'm wondering how I might be able to use the Views module to find properties based on their rent per month using a "Min" and "Max" drop downs as opposed to just using text fields.

Essentially, I would like a filter to appear as "Min" drop down box with arbitrary numbers ($100, $200, $300......$10000) and a "Max" drop down with the same values.

Is this possible with any current modules? If not, is it possible through `hook_form_alter()`? If so, can someone point me in the direction of how to get acquainted with working with forms in greater detail?

# Answer
> 1 votes
Sure. You can do it with form alter hooks. Here is an example. The form id will be:

```
views_exposed_form_<view_name>_<view_type>

```

# Answer
> 0 votes
Check the Better Exposed Filters module. It has exactly what you need.

---
Tags: forms, views
---


# Question
Title: hook_module_implements_alter() not working for me. What am I doing wrong?
I use D7 and need 2 different modules to parse article text on save. For simplicity's sake let's say module\_one changes all f's to z's and module\_two changes all foos to bars. So basically "F foo fo foo" is to become "Z bar zo bar". To accomplish that I need module\_two node\_presave event to fire before module1. Otherwise the result will be something like "Z zoo zo zoo". But hook\_module\_implements\_alter() doesn't seem to do the thing. I write it like this:

```
function module_one_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'node_presave') {
    // Move module_one_node_presave() to the end of the list. module_implements()
    // iterates through $implementations with a foreach loop which PHP iterates
    // in the order that the items were added, so to move an item to the end of
    // the array, we remove it and then add it.
    $group = $implementations['module_one'];
    unset($implementations['module_one']);
    $implementations['module_one'] = $group;
  }
}

```

This hook executes but I still get module\_one's node\_presave hook executed before module\_two's. So what am I doing wrong?

# Answer
The code you use is similar to the example code shown in the documentation page for `hook_module_implements_alter()`. It is supposed to be implemented from the module that wants to execute its hook before the other module, but it would work also how you did.

Consider that the list of hooks implemented by modules are cached. If you just edit the code of an existing enabled module, then you would not see any difference in the execution order of that hook implementations.

`hook_module_implements_alter()` should be implemented when you are interesting to alter the execution order of a single hook implementations, and leave the execution order of the other hooks as they are.
If changing the execution order of all the hooks doesn't cause you any problem, then you should just change the module weight, which is computationally lighter.

Usually a module implements `hook_install()`, or `hook_update_N()` using code similar to the following:

```
function mymodule_install() {
  db_update('system')
    ->fields(array('weight' => $weight))
    ->condition('name', 'mymodule')
    ->execute();
}

```
> 0 votes

# Answer
Double check the weight in the system table on your d7 database. You can try giving module one a higher weight therefore making it run second.
> 0 votes

---
Tags: 7, hooks
---


# Question
Title: How to programmatically disallow some users to comment on some nodes?
I've been asked to implement the following:

* I have a content type with a user reference field from the References module;
* a user creates a node and references another user using that field;
* only that user and the node's author are allowed to add comments to that node;
* at some point the author closes comments, but that's part of another question :)

I've browsed the API of node (both module and API itself) and comment, and couldn't find anything useful. In fact I tried with two of the most promising functions (hook\_node\_view and hook\_node\_view\_alter) without success.

I'd appreciate pointers to look at.

(yes, I know I said "complex", but this is just the starting point :)

***EDIT: Partial solution ahead***

```
function _comment_access_check_permission(&$node) {
    if(user_is_logged_in()) {
        global $user;
        $account = user_load($user->uid);
        $account_uid = intval($account->uid);
        $asker = field_get_items('node', $node, 'field_asker');
        $asker_uid = intval($asker[0]['uid']);
        $author_uid = intval($node->uid);

        if($account_uid == 1 or $account_uid == $asker_uid or $account_uid == $author_uid) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
    return true;
}

function comment_access_preprocess_comment_wrapper(&$vars) {
    if(!_comment_access_check_permission($vars['node'])) {
        $vars['content']['comment_form'] = array();
    }
}

function comment_access_preprocess_comment(&$vars) {
    if(!_comment_access_check_permission($vars['node'])) {
        unset($vars['content']['links']['comment']['#links']['comment-reply']);
    }
}

```

This code effectively hides the comment form for those users that are not supposed to comment on a given node.

BUT. If one goes to comment/reply/$nid or comment/reply/$nid/$cid the form is still shown, which is not acceptable. Another overview of the API didn't ring any bell to me, so if you have any suggestion…

# Answer
Implement hook\_menu\_alter() and use your custom access function to control access to the comment system.

```
// Minimalist Example
function MYMODULENAME_menu_alter($items) {
  $items['<path known to hook_menu()>']['access callback'] = 'your_callback_function';
  $items['<path known to hook_menu()>']['access arguments'] = array('your args');
}

```
> 1 votes

# Answer
I would hook\_form\_alter the comment form, and use your logic to set #access on the form. You may need to explicitly call menu\_get\_item to get your node to use in the logic.

You could also use a template\_preprocess\_node that would perform your logic, and hide or show the comment form in the node's render array based on your logic (this assumes it is in that render array, which I am not 100% positive about).
> 1 votes

# Answer
If you're looking to automate the closing of comments based on potentially complex logic the Rules module may be exactly what you're looking for. Managing the comments status of a given node is built in Rules functionality.

If using a contrib module is not an option, seeing how Rules would accomplish this could save you time developing your custom code.

Using nothing more than Rules and maybe the Flag and References modules, you can accomplish everything you mentioned in your original question and it would still allow for additional, possibly more complex logic in the future without needing to write custom code.
> 1 votes

---
Tags: 7, comments, users
---


title: D7 comment form doesn't submit

text:
# Question
Title: D7 comment form doesn't submit
I've successfully printed a comment form on a views-built page using a PHP Views field (as found in this question). The form doesn't submit right away though - instead of submitting, the comment "save" button redirects to the "comment/reply/\[nid\]" page with blank values.

Comment form print code:

```
$comment = new stdClass;
$comment->nid = $row->nid;
$form = drupal_get_form('comment_form', $comment);
print render($form);

```

Are there extra details that should be added to the $comment object before or during the `drupal_get_form()` or `render()` calls?

# Answer
> 2 votes
Try next:

```
// ...
$comment->nid = $row->nid;
$form = drupal_get_form('comment_form', $comment);
$form['#redirect'] = 'CHANGE_VIEWSPAGE_HERE?page=' . (int)$_GET['page'];
print render($form);

```

---
Tags: 7, forms, comments
---


# Question
Title: How do you change which content type a field is attached to (which one owns it?)
While exporting configuration for my site using the Features module, I noticed that one of the fields I use on many content types was initially created on the "news" content type instead of the "article" content type. This presents a problem, since it means all of the features that I export are now dependent on a completely unrelated module (news) to provide a common field (field\_image).

What I'd like to do is change the entity that "owns" field\_image to be article. This will let me export one base feature which provides a bunch of common fields, and have the rest of the features depend on that instead of having them all depend on news.

How can I change which content type owns field\_image without breaking everything?

# Answer
Features is smart enough to require the module that implements the field, without requiring a bundle that you haven't told it to require. So you might consider double-checking the feature you've created to make sure you haven't included the content type you don't want.
> 1 votes

# Answer
Well, this isn't the perfect solution, but may be a way to find it.

Change your content type to what you want to have it and export the feature. Them take a difftool (winmerge) and look at the diffrences between the old version of your features module and the new one.

There's a good chance that you find out what to change.

Don't forget to take a DB Backup before you start.
> 1 votes

# Answer
I think you just have to change the bundle type of the field. Maybe your feature has the field belonging to the "news" bundle. If you change it to "article" it will be done.

Open the feature.field.inc and search for "bundle" then change the value for the correct one. Notice that the array index will be the field name so be careful to not change the wrong field.
> 1 votes

---
Tags: entities, nodes, features
---


# Question
Title: How do I create a rule that closes comments on node after 30 days?
I am on Drupal 7, and I am trying to make a rule that closes comments on a node 30 days after they have been created. I am assuming I need to make a component that has an action of "set data value:" to change the "node:comment" to 1. Where I am confused is how to schedule that component to fire 30 days after the node has been created.

Do you have any suggestion?

# Answer
You need at least 2 rules to make this happen. One is an actual "rule" and the other is a "rule component".

You are correct about the second one being a component which sets the data value on node:comment.

The other one, the rule, needs to be set to activate on the event "After saving new content."

An action for this rule needs to be "Schedule component evaluation". Setting this action then requires you to configure the evaluation, where you set the particular rule component to be evaluated, and then set "Scheduled Evaluation Date" as well.

To make it happen 30 days in the future, enable Data Selection mode, and select "site:current-date", then for the offset field which now appears below it, select 30 days. This will cause your selected rule component to be evaluated 30 days from the current date/time.

After configuring all this and testing it, you can check to see if it works by going back to the Rules interface and going to the "Schedule" tab. Your scheduled task will be listed there.
> 2 votes

---
Tags: 7, rules
---


# Question
Title: Can I call drupal_goto in form #submit handler?
I've a node type Person and want to attach a new submit handler. Will it be fine if I call drupal\_goto to another URL from within this new submit handler?

What I want to do is to ask for some confirmation message and then save the node using drupal\_execute.

In the submit handler I'll save $form\_values in session using key form #build\_id and then in it I'll redirect it to another url with this build\_it in the url as GET parameter. In the redirected form url I'll be doing some checks on the node data( if same title node already present etc) and asking for confirmation. If yes then I'll create/save the node myself using drupal\_execute.

Will it work this way?

# Answer
> 7 votes
Can you call `drupal_goto` in a submit handler: Yes
Should you call `drupal_goto` in a submit handler: **No**

Why?

The reason is that potentially other submit handlers might need to be called in order for things to work properly. If you call `drupal_goto` you would stop the execution flow and make it impossible for the other submit handlers to do their thing.

What you should do instead is to use `$form_state['redirect']`, which when set will be the url that is redirected to when the submission process is completed.

In your specific use case, however it could work since you don't want the node to be saved, but stopping the process in this way could give you strange bugs/side effects.

**But you really should't be doing it this way.**

Instead you should attach a validate handler to the node form. If the validation fails the node is not saved and you can display any message to the user via `drupal_set_messsage` or `form_set_error`. You could save in `$form_state` that the message has been displayed to the user and allow him to save the node anyway if he resubmits the form. This is what the validate handlers are built for, after all.

---
Tags: 6
---


title: Drupal 7 - Ajax form in modal window

text:
# Question
Title: Drupal 7 - Ajax form in modal window
I try to create modal window with form (from page /node/add/page). Try this

```
hook_menu() {items['mypath']=...} + callback (where echo drupal_render($form); exit();)

```

//form has many elements from different modules (node + inline register)

Next

* get rendered form via ajax (form has action 'mypath')
* plug jquery.form.js to the form

Submit

Server returns full page and i'm sure that new page material doesn't save even if i change action to '/node/add/page' instead of 'mypath'

What i do wrong?

# Answer
> 1 votes
It's hard to tell what you doing from your description. A better description could possibly yield better answers.

One possible problem could be that the form needs to be loaded on the page the it is submitted on. This is required for the validate and submit handlers to be processed.

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


# Question
Title: Can a view "a" appear only in the page of view "b"?
I have a view I want it appears only in the page of another view.

Is it possible without writing code?

# Answer
> 2 votes
Put him in a block and show that block only on the page of the other view. Or more precisely, create a block display for view a and have it displayed only on the path defined by the page display in view b.

# Answer
> 1 votes
In the "Another View" you can insert any other view into its header or footer. If that's what you meant.

# Answer
> 0 votes
Use **attachments** in the view and attached it with the view which you want.
Instead of creating a new view or block.

---
Tags: views
---


# Question
Title: How to save node form data in form_values using drupal_execute
I want to save `$form_values` in the session table in the submit handler when a node type (eg page) is saved.

How can I reuse this `$form_values` to create this node again using `drupal_execute` after some time (say tomorrow)?

I've tried creating it but it isn't working out:

```
function abcdonations_entry() {
  if (isset($_SESSION['form_id'])) {
    $fs = $_SESSION['form_id'];
    $form_id = $fs['values']['form_id'];
    module_load_include('inc', 'node', 'node.pages');
    $node = array('type' => 'person');
    drupal_execute($form_id, $fs,(object)$node);
    print "Written successfully";
  }
}

```

Then I save it in this function:

```
function anu_general_form_person_node_form_submit(&$form, &$form_state) {
  $_SESSION['form_id'] = $form_state;
}

```

# Answer
If I understand right you basically want to clone a node later? If this is the case than you can just:

```
$nid = $the_nid_of_the_old_node;  //get the $nid of the old node
$new_node = node_load($nid);      //load the old node object
$new_node->nid = NULL;            //unset nid to tell node_save that this is a new node
// do what ever you need to the new node
node_save($new_node);             //save the new node

```

That should do it.
> 1 votes

---
Tags: 6
---


title: Drupal 7 Forum with these features

text:
# Question
Title: Drupal 7 Forum with these features
I want to setup a forum using Drupal 7 with these features:

* Manage user roles and give or revoke access to forums or topic per user.
* Create moderators where they can add,edit, delete members and forums,topics,posts
* Be able to get email notifications for every action made in the forums
* Be able to upload photos,docs etc

Could you tell which modules I need to make a forum like this?

Thanks in advance

# Answer
I found that using the Advanced Forum and the Forum access modules I can have all the features I want.
> 1 votes

# Answer
Well you can use the forum module that comes with Drupal core or you can integrate a phpBB installation. Check this module: phpBBforum Integration module. phpBB 3 is the best open source bulletin board. It is fast, secure and has a lot of features and extensions (mods). All the features that you need above are supported by phpBB 3.
> 1 votes

---
Tags: 7, nodes
---


title: Advanced Forum permissions

text:
# Question
Title: Advanced Forum permissions
I have installed the Advanced Forum module for Drupal 7.10.

How can I set permissions for each forum I make? I want only administrators to have the "admin forum" permission, and not authenticated users.

Is that possible?

# Answer
The Forum Access module works in Drupal 7, so I'll stick to this for now.

> This module changes your forum administration page to allow you to set forums private. You can control what user roles can view, edit, delete, and post to each forum. You can also give each forum a list of users who have administrative access on that forum (AKA moderators).
>
> This module requires the ACL module in order to function. The D7 version also requires the Chain Menu Access API module.
> 1 votes

# Answer
You will need to use another module to handle the permissions / access control. Look into Taxonomy Access Control, it has a d7 release. You might have to put each forum in its own taxonomy to enforce the permissions.

For example the Admin forum, add it to the "Admin only" taxonomy etc
> 0 votes

---
Tags: 7, nodes
---


title: MySQL dump file installation

text:
# Question
Title: MySQL dump file installation
I am working on replication, and I am stuck on MySQL dump. I want to know if there is the need of installing MySQL dump (I just have mysql community ed: version 5.5 on both servers) because I am stuck on executing dump command. On Google I did't find any solution.

# Answer
mysqldump should just come bundled with MySQL. Have you tried running it from the command line? If you don't have/can't find mysqldump you should be able to use phpmyadmin to do export/import.
> 3 votes

---
Tags: database, backups
---


# Question
Title: How to programmatically code a block to show taxonomy vocabulary as an unordered list?
I'm trying to build a menu using a taxonomy vocabulary with its hierarchical structure. I don't want to use any module to do it.

In this page I see that I can grab the terms for a given vocabulary and do it programmatically http://drupal.org/node/113651

But I need some help to star coding it.

I have a Taxonomy called: Products (the tid is : 2)

Products has the following terms and hierarchical structure:

```
--Cars
----Volvo
----Ford
--Games
----Football
----Rugby
----Videogames
------Pacman
------Call of Duty

```

PHP CODE to generate:

```
<ul>
    <li>Cars
        <ul>
            <li>Volvo</li>
            <li>Ford</li>
        </ul>
    </li>
    <li>Games
        <ul>
            <li> Football </li>
            <li> Rugby </li>
            <li>Cars
                <ul>
                    <li> Pacman </li>
                    <li>Call of Duty</li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

```

# Answer
That's something I have put together for myself in the past. I posted the code on the Drupal taxonomy\_get\_tree() API page where you can get a copy for yourself. The core part of the code is usable with Drupal 6 as well (some smaller modifications are needed to make it work though).
> 3 votes

---
Tags: taxonomy-terms, routes
---


title: Parsing form submitted values - D7

text:
# Question
Title: Parsing form submitted values - D7
Could anyone please point out where I might be doing something wrong? I can't seem to capture the form values to manipulate them when this form is submitted.

```
   function admin_score_table_block_view($delta = '') {
      //The $delta parameter tells us which block is being requested.
        switch ($delta) {
            case 'admin_score_table':

                $block['subject'] = t('Admin Editable Score Table');
                $block['content'] = '';
                global $user;

            $form = drupal_get_form('admin_scores');

            $block['content'] = $form;

        break;
    }
    return $block;
}

function admin_scores($form) {
  if ($node = menu_get_object()) {
        $node = node_load($nid = $node->nid);

        $programmetmp = $node->field_sportevent_cd;
        $programme = $programmetmp['und'][0];
    }

    $form['#tree'] = 1;

    $result = db_query("SELECT cdt.entity_id AS nid FROM field_data_field_team_corpdec AS cdt WHERE cdt.field_team_corpdec_nid = " . $programme['nid']);
    foreach($result as $row){
        $team = node_load($row->nid);

        $form[$team->nid]['nid'] = array(
            '#type' => 'hidden',
            '#value' => $team->nid,
        );
        $form[$team->nid]['team'] = array(
            '#type' => 'textfield',
            '#value' => $team->title,
            '#title' => 'Team',
            '#attributes' => array('class' => 'field-team'),
            '#name' => 'team[' . $team->nid . ']'
        );
        $form[$team->nid]['score'] = array(
            '#type' => 'textfield',
            '#value' => '',
            '#title' => 'Score',
            '#attributes' => array('class' => 'field-score'),
            '#name' => 'score[' . $team->nid . ']'
        );
    }

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save scores',
    );

    return $form;
}

function admin_scores_form_submit($form, &$form_state){
    var_dump($form_id);

}

```

# Answer
> 2 votes
Your form is called `admin_scores()` but your submit function is called `admin_scores_form_submit()`...this isn't Drupal's naming convention so your submit handler will never be executed.

Either change the name of your submit handler:

```
function admin_scores_submit($form, &$form_state) {

}

```

Or add your non-standard submit handler in the form itself:

```
$form['#submit'][] = 'admin_scores_form_submit';

```

Also the signature you're using for your form function is slightly wrong, in Drupal 7 it's like this:

```
function admin_scores($form, &$form_state) {

```

---
Tags: forms
---


# Question
Title: Login from one Drupal instance on another Drupal instance
I'm working on a project that has some unconventional requirements.

Basically, I have two sites, each one with an individual Drupal installation and instance. The main site (I'll call it "master") has a lot of registered users, and the other one does not (I'll call it "slave").

I need the possibility of logging into the "master" site through the "slave" one. Like, the "slave" site would have a login form, that would connect to the "master" site and authenticate the user.

I've thought of using APIs like OAuth for this, but I didn't find any solid documentation or tutorial of how to do this with Drupal.

*Observations: I can't make them multisites, they are two isolated Drupal instances. And it must work for Drupal 6.*

Can anyone give me some directions?

# Answer
Have a look at the Single Sign On module. It's only for Drupal 6, which is what you need, but it's not actively maintained. If it works as advertised, I think you are good to go.

There is also the Bakery Single Sign-On System, but I don't think it fits your specs and requirements.
> 2 votes

---
Tags: 6, users, authentication-authorization
---


# Question
Title: How to check where in a menu tree a node is & then display a portion of the tree?
How can I check where in a menu tree a node is, and in particular how can I determine what its ultimate parent is? And how can I display a portion of a menu tree? Here's an example menu tree to illustrate:

```
m1
-subm2
--subsubm3
-subm4
m5
-subm6

```

If I were on the pages linked to from items 1-4, I'd want to find out that the ultimate parent of these items is m1, and then display only the portion of the menu below m1, ie:

```
m1
-subm2
--subsubm3
-subm4

```

# Answer
I am pretty sure Menu Block will do what you need. I have used this module to display portions of menus only under one parent item as you mention and it worked great. It's for Drupal 6 & 7 as well.
> 5 votes

---
Tags: routes
---


# Question
Title: Show a view on a custom nodetype only if the logged in user is the author of this node
I'm using Drupal 7, with the Views module version 3, and the Context module (no block).

I have a draggable view I want to show on a gallery node. The draggable view shows the image nodes belonging to this gallery node for sorting.

Now I want to limmit the display of this view to the author of the gallery node. (Only the author of the gallery node should organize the image nodes.) I think this could be done with context or relationship (and some coding) inside views, but I don't know how.

I know how I can display the view only on the gallery-node (via Context module). So I only need a way to limit the display of the view to the author of the gallery.

Maybe someone has a solution.

# Answer
> 1 votes
You just need to add an argument to this, passing the logged in user's uid. In Drupal 6, views 2 you used to have to reverse engineer this and add custom php into the argument handling code but this is built into Views 3. In your view:

* Add Contextual filter, 'Content: author uid'
* Select 'provide default value', type 'user id from logged in user'

This will find the uid of the logged in author and pass that as an argument to your view, restricting the view results to only items that were authored by the owner of that node.

---
Tags: views
---


# Question
Title: When does hook_field_storage_details_alter() fire?
I need to modify the field storage details so some additional data can be stored with a form field. I found hook\_field\_storage\_details\_alter(), but it doesn't seem to fire. When is this hook used?

# Answer
> 3 votes
The function that invokes both `hook_field_storage_details()` and `hook_field_storage_details_alter()` is \_field\_info\_prepare\_field(), which is indirectly called from the following functions:

In other words, all times information about a field is required, that hook is used.
As Clive points out, \_field\_info\_collate\_fields(), the function that directly calls `_field_info_prepare_field()`, caches the information returned by those hooks, which means they are not always invoked; they are invoked when the cached data don't exist, or have been removed. This makes `hook_field_storage_details_alter()` used in a similar way to `hook_menu_alter()`, which is called only when the menu definitions need to be rebuild, and not all times Drupal is retrieving the menu definitions given by all the enabled modules.

# Answer
> 1 votes
It's invoked from `_field_info_prepare_field()`, which in turn is only called by a single function, `field_info_collate_fields()`.

This function is in turn called by a fair few, all of which are part of the Field Info API:

* field\_info\_cache\_clear()
* field\_info\_extra\_fields()
* field\_info\_field()
* field\_info\_fields()
* And a few more (have a look at the "10 functions call \_field\_info\_collate\_fields()" bit on the `field_info_collate_fields()` docs).

Looking at `field_info_collate_fields()` it seems that `_field_info_prepare_field()` is only called after Drupal's caches have been cleared (i.e. when there's no available cache data):

```
if ($cached = cache_get('field_info_fields', 'cache_field')) {
  $info = $cached->data;
}
else {
  // _field_info_prepare_field() is called a few lines after this

```

So I think the answer to your question is that the hook is invoked after you've cleared Drupal's cache.

---
Tags: 7, hooks, entities
---


# Question
Title: Strange error updating PHP code in a node
I have a 'Basic Page' node that contains PHP code which returns the following error, when I edit and save it:

> Error 101 (net::ERR\_CONNECTION\_RESET): The connection was reset.

I believe it is not the real error; if I edit anything but the code, I don't get any error.

What I do is changing `<?php if (user_is_logged_in()): ?>` to `<?php if (user_is_logged_in() && (inarray('approved user', $GLOBALS['user']->roles)))): ?>`.

I'm pretty positive the code is right; the PHP filter is enabled, and the administrator user is the only user who can use it. I'm not really sure what else could be the issue.

# Answer
> 4 votes
`inarray()` isn't a PHP function, you're probably looking for `in_array()` :)

The error you're getting is probably masking the internal `Call to undefined function inarray()` exception that would be thrown.

**EDIT**

You also have one too many closing parentheses at the moment, I'd recommend separating out your code to make it cleaner:

```
<?php

$has_required_role = in_array('approved user', $GLOBALS['user']->roles);
if (user_is_logged_in() && $has_required_role):
  // Do something
endif;

?>

```

---
Tags: nodes
---


# Question
Title: Export Apache Solr enabled facet settings
On the Apache Solr settings page `admin/config/search/apachesolr/enabled-filters` you can control which filters are enabled on your site's search interface.

These settings are not stored in regular Drupal variables, hence, you cannot export these settings in a Feature like you would do with another variables. I am interested in making these settings persistent by storing them in Features.

This would allow to effortlessly switch from a produduction Solr instance to a local instance without having to manually re-apply all these settings by reverting the relevant Feature.

What would be best way to store these settings in Features?

# Answer
This code resolved my need to backport production enabled-facet settings into localhost. Features are not used. `tfk_search` is the name of my module, substitute this for your own.

```
/**
 * Implement hook_form_FORM_ID_alter().
 *
 * Alter apachesolr_enabled_facets_form(), add an additional submit handler
 * that helps us export enabled facet settings via Features.
 */
function tfk_search_form_apachesolr_enabled_facets_form_alter(&$form, &$form_state, $form_id) {
  $form['#submit'][] = 'tfk_search_enabled_facets_form_submit';
}

/**
 * An additional submit handler for the active facets form.
 *
 * Save current settings into default server. Allows backporting
 * production settings into localhost. No Feature revert needed.
 *
 * @see apachesolr_enabled_facets_form
 */
function tfk_search_enabled_facets_form_submit($form, &$form_state) {
  $enabled = array();
  foreach ($form_state['values']['apachesolr_enabled_facets'] as $module => $facets) {
    $enabled[$module] = array_filter($facets);
  }

  // We hardcode 'solr' here because apachesolr_default_server() resolves to something
  // else in production.
  apachesolr_save_enabled_facets('solr', $enabled);
}

```

After importing the database from production into local, while your default Solr instance is still the same as the one in production, go the enabled-facet settings page, and save it (even if you make no changes on it). Then switch the default Solr instance to the local one (`solr`). It should automatically pick up the facet settings for production.

*Note that this solution is good for backporting settings, but not for exporting them á la Features. It would not work if you wanted to automatically push these settings into various sites.*
> 2 votes

---
Tags: 7, search, features
---


# Question
Title: Synchronize drupal database with a traditional database
I have a installation of plain Drupal 6 with its own database. I have also another database, different from the one used by Drupal.

I want to connect this database (with its own structure, tables and relations) with the database used by Drupal, and use the information in that database for creating views, for example.

I have a table "Persons" with 2 fields (*Name*, and *Age*) in the external database. I want to transfer (or connect, or synchronize) that information to my database in Drupal, or handle this information with some module. In my Drupal site, I have a "Persona" content type with two CCK fields: *Name*, and *Age*.

Is there any existing solution?

# Answer
Easy answer: use the data module for drupal 6.x

http://drupal.org/project/data

"Data module helps you model, manage and query related sets of tables. It offers an administration interface and a low level API for manipulating tables and accessing their contents. Data module provides Views integration for displaying table data and Drupal search integration for searching table content."

The included data\_ui module will let you setup the connections to your external database and map the fields.
> 4 votes

---
Tags: database
---


title: server side path to filesystem

text:
# Question
Title: server side path to filesystem
How do I get the server side directory of the filesystem path?

For example, my files are in http://mydomain.local/myfiles; this is the root of my drupal filesystem. I am searching for a function that will give me d:\xampp\htdocs\drupal\myfiles.

# Answer
`$_SERVER['DOCUMENT_ROOT']` will get you the d:\xampp\htdocs and `$base_path` or `base_path()` will give you the Drupal part.
> 4 votes

---
Tags: 7, files, uri
---


title: Add location(s) to user account

text:
# Question
Title: Add location(s) to user account
I have a Content Type called locations. I need to be able to assign these to Drupal users. Some users will have multiple locations.

Is there a module that will let me do this, or what are some suggestions you all might have?

# Answer
There is a way but it may not be ideal depending on how far you are along in your site development. The way you would link content to content is through the node\_reference field that comes with the CCK module. The problem is that this doesn't work with Drupal profiles in 6.x, only nodes. One solution is to install the content profile module

http://drupal.org/project/content\_profile

which allows you to create a new content type for your profiles. From there, you would just add a field of type 'node\_reference' to your new profile content type and connect it to 'locations', and allow the user to make multiple selections, etc.

Of course this is less than ideal if you already have a significant number of profiles on the system but there is a migration path from the core drupal profile data to the new type in another module:

http://drupal.org/project/profile\_migrate
> 2 votes

# Answer
Disclaimer: It's been a while since I worked in Drupal 6, so there may be a more elegant way to do it.

My method basically consists of 2 steps:

1. Use the Content Profile module to build user profiles as nodes
2. Use the Content Construction Kit module and specifically the NodeReference part of it to associate a profile with a location from your custom content type.
> 1 votes

---
Tags: 6, users
---


# Question
Title: Referencing both a node and user in the same field
In Drupal 7, I am looking to create a field in a content type that can either reference another specific content type and/or also reference a user. I am creating the content type programmatically in the .install file and am looking to be able to reference both types in the same field.

It currently works with one or the other as:

```
'field_sport_team_members' => array(
  'field_name' => 'field_sport_team_members',
  'label' => 'Team Members',
  'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  'type' => 'node_reference',
  'description' => 'The members of the team',
  'weight' => '3.5',
  'required' => 0,
  'settings' => array(
    'referenceable_types' => array('club_person'),
  ),
),

```

for the reference to the content type and

```
'field_club_person_user' => array(
  'field_name' => 'field_sport_team_members',
  'type' => 'user_reference',
  'label' => 'Team Members',
  'description' => 'If this entry corresponds to a user, you can select the user here.',
  'weight' => '3',
  'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  'translatable' => TRUE,
  'locked' => FALSE,
  'settings' => array(
    'referenceable_roles'  => array (
      4 => '4', //captain
      5 => '5', //player
    ),
    'referenceable_status' => array(
      1 => '1',
      0 => 0,
    ),
  ),
),

```

for the reference to the user type.

I guess my real question is now with the advent of "entities", is it possible to make a entity reference, but also to specify which content types to search for as well?

# Answer
There are a few ways to do this. You said "and/or", you could use Field Collection and add a node reference and a user reference to it. See the field collection module.

The other option would be the relation module or the entity reference module which can both reference any "entity." The former is a lot more complex. Entity reference has a usable widget with autocomplete which might be exactly what you need. To narrow the entity reference down to the exact content types you want along with users, you will probably have to write a custom widget. You can see the default widget implementation in the source.
> 5 votes

---
Tags: nodes, entities
---


title: Use a managed file in a menu_item

text:
# Question
Title: Use a managed file in a menu_item
Is there a way to create a menu that links to a managed file? I tried many times, but nothing I tried works.

Do you have any idea?

# Answer
> 1 votes
If you enter the full path of the file, it should work but if you're looking to create the menu with a relative path, see https://stackoverflow.com/questions/4335700/drupal-primary-link-item-to-a-relative-file-on-the-server or How can I add relative path to a pdf file link in drupal menu

---
Tags: 7, routes, files
---


# Question
Title: Emails sent via a Rules action contain arbitrary line breaks
I have an email sent by Rules. Here is the text of the email in the Rules action:

> Welcome to x! As a professional user, you can now showcase your business on x by creating a Professional Profile and uploading photos of your best x.

Here is what the user gets (note line breaks):

> ```
> Welcome to x! As a professional user, you can now showcase your
> business
> on x by creating a Professional Profile and uploading photos of your
> best x.
>
> ```

I'm not sure why there are arbitrary line breaks being inserted in the text when sent via email. I've excluded the RTE on email field in the rule, and included only plain text.

# Answer
> 5 votes
You are most likely up against the hard limit of line length (77) for plain text emails, defined in a Drupal core function `_drupal_wrap_mail_line`. It quotes RFC 3676 as the reason for this.

If you want the one line of text you might be able to do it using a HTML formatted email rather than plain text. Alternatively you may want to reformat your email so it suits the available width. The third option of altering core or making a plugin to let you make long lined emails is probably a little overboard.

---
Tags: rules, emails
---


# Question
Title: Why can Wordpress ship with latest version of jQuery but Drupal cant?
Just a general question to as what holds Drupal back from being able to use the latest version of jQuery? I am guessing it is something technical but would like some details.

Even jquery update module only updates a few versions for Drupal 7 it goes for 1.4.4 to 1.5.2 while Wordpress ships with 1.7.1

* Drupal 6 to jQuery 1.3.2
* Drupal 7 to jQuery 1.5.2 and jQuery UI 1.8.11

# Answer
> 4 votes
My understanding is that the version of jQuery gets locked down with the version of Drupal during development to ensure stability. It is all part of the testing process. The Drupal developers fully test the system before releasing a new major version of the CMS, including the JavaScript functionality. The incremental changes that go on throughout the year do not provide the time to test at this level so the jQuery version stays the same.

I am not very familiar with Wordpress, but my understanding is that they make considerably more regular major upgrades to the versions of their CMS. So jQuery gets updated more frequently. However, from what I've read little testing takes place.

While getting stuck with an old version of jQuery can be frustrating, I'd rather go for a stable well tested system.

# Answer
> 0 votes
The project page for JQuery update module is not quite up to date. Have a look at this issue / patch: -- It's still be worked on so use with care but it looks promising and it looks like it's getting attention and recent as well.

In your tags you did not specify what version of Drupal you are using though, the issue above is for Drupal 7. (That's one of the gotchas of Drupal, sometimes lurking around in the issue queues can yeield some nice finds and solutions that may not be evident yet on a module/s project page.

---
Tags: javascript
---


# Question
Title: How to jump to another know page on a button click?
I need to implement a select list (something like auto-complete in JQuery UI) with a `Go` button on a mini-panel (or block). I can do this in Javascript. When the user selects a value, a corresponding page (for example: article) URL is computed.

Assuming we know the URL of that page, how do I get Drupal to jump to that page when the user clicks on the `Go` button? I am no expert in PHP, but could implement some if necessary, or is there a better solution?

# Answer
> 2 votes
If the whole implementation (including the URL computing) is done on the client side with javascript then the easiest solution would be to simply use code like the following:

```
$('#go_button_id').click(function() {
  location.href = 'url_to_the_computed_page';
});

```

On the server side you could use Drupal's block hooks and form API to create a block with a simple form and then use `$form_state['redirect'] = 'url_to_the_computed_page';` in the form submission handler for the redirect.

---
Tags: redirection, 7
---


title: How do I reformat status messages?

text:
# Question
Title: How do I reformat status messages?
I'm trying to restyle the status messages block, and I just can't figure out how to do it. I ought to be able to -- it's just defining a theme function, right? :) -- but it's just not happening for me. I'm not sure if I'm not defining the function properly, or not registering it properly in hook\_theme, or even if I need to register it in hook\_theme. Arggh -- can anybody out there clarify this for me? Thanks very much!

# Answer
the function you need to hook is:

`themename_status_messages()`

where themenameis your theme's name. You can see the status message theme docs here.

What specifically are you trying to restyle? Most of it can be done with CSS, without introducing a theme hook.
> 3 votes

# Answer
If you are talking about `theme_status_messages()` all you need to do is create a `phptemplate_status_messages()` or `YOURTHEMENAME_status_messages()` function in the `template.php` file in your theme's directory and do whatever you want to do differently (the original is defined in `includes/theme.inc`).
> 0 votes

---
Tags: 6, hooks
---


title: Creating multiple node references

text:
# Question
Title: Creating multiple node references
I have the following content types - Efforts, Objectives, Groups and the user.

Efforts and Objectives can be shared by both users and groups. A user/group can have multiple objectives and efforts and can also share the same objectives/efforts.

Is it possible by using node references ? or Is there any other way where I can implement this functionality in drupal ?

# Answer
sure you have to use node reference I think you need a node reference in efforts and objectives to select users or group so you need a node reference to a view (you can reference to a view it should not be node)

the same user/Group make a view reference to objects and efforts

If you have any problem make a comment
> 0 votes

---
Tags: nodes
---


# Question
Title: Conceptual help needed for creating forms related to parent node
I would like to ask for your opinion in creating a solution for the following application requirements. The general purpose of the application is to administrate students, teachers and courses much like a school administration software.

Some content-types will have related forms (original format is PDF) that are filled in partially by the user and partially by the application. After filling in the required data, the forms must be printable (PDF) and stored for future editing and printing again. The filled form must always stay related to a specific parent node. Means, if the user views or edits the content of a certain node, he needs to see the related forms and be able to click on them to fill in data or edit or print the filled in form again and again.

A small example.

Content-type: student (node)

```
- related form: attendance
- related form: enrollment

```

Properties of the related forms:

```
- original forms are available as PDF files
- some fields are filled in programmatically, taking data from the currently viewed student node
- other fields are filled in manually by the user
- filled in forms need to be printable (PDF) or send as mail attachment
- filled in forms need to be stored for future printing / editing
- forms always need to be related with their parent student node

```

My targeted solution is as follows using as example the form "attendance":

1. programmatically create and validate the form "attendance"
2. store the filled form as a PDF file in the file system
3. add the PDF as attachment to the related student node
4. add an edit button beside the attachment that leads the user to the filled form (for editing and printing again)

Could this solution work? Does anybody have ideas or hints for a better solution? Any comments are very appreciated.

# Answer
I would solve this a bit differently:

1. Programmatically create and validate the form "attendance" - sounds good.
2. I would create a separate database table and store the filled form data there. It should have node (and user) id fields to determine to which node (user) it is related to. The node id field or node and user id field combination should be unique so you can always get the right attendance data for the specific node/user. Optionally it could have a unique, auto-incremental attendance id as the primary key if more than one field would be needed otherwise (easier to create unique paths for every attendance). Then I'd also add either separate fields for every form field or one field for all the data (serialized) depending of the needs.
3. Add a link instead to a programmatically created path (example: attendance/1/pdf where 1 would be the unique id for the attendance). When the user goes to the page create the pdf from the attendance data that they can download/view.
4. Add a link to the attendance edit form page (example path: attendance/1/edit).

One more thing to note is to get the (view/edit) permissions right if there is a need for restrictions.

In case my solution idea doesn't fit too well with all the specific requirements I would just say that you should store data in the database not files.
> 1 votes

---
Tags: nodes, forms
---


# Question
Title: How do I access my fields in a .tpl file
I have a file views-view--MyView--block-2.tpl.php

there is no `$fields` variable, it doesn't exist.

if I do a `foreach($view->field as $v=>$f)` and print both `$v` will show me all my fields in that view and display

* created
* title
* field\_op\_author\_nid
* field\_main\_image\_fid
* field\_teaser\_value
* comment\_count

but $f is always empty.

How do I access my fields?

\[EDIT\] Ok, let me clarify. the .tpl file I have renders just fine. the markup I have in that file shows up. The issue is that I cannot access the fields I set up in the view and displaye. I tried changing the filename to include -fields- and I indeed did get the $fields variable. This looks to be exactly the same as the `$view` variable that I had before, which I don't know how to get data out of. I can see the fields I need in there but the `var_dump($fields( or $ view))` is about 20 pages long and every example I have seen has been just using `$fields["fieldname"]`, which does not work.

Am I just maybe doing this wrong entirely? What is the best way to set these up, is it to have multiple tpl files, one for each field and row?

# Answer
> 0 votes
By the time the processes reach the views-view.tpl.php level, the Fields have already been rendered and are not available for further manipulation.

I would need more information about what you are actually trying to do, as well as which versions of Drupal and Views you are using, in order to suggest a specific solution. For example: are you trying to manipulate the data within the fields, or just wrap the field content in different HTML?

Either way, you can do a lot of manipulation of the field data and wrapping HTML within the Views UI, using the "Rewrite Results" option within each field's settings, or you can get even more control over the wrapping HTML by utilizing the Semantic Views module.

# Answer
> 0 votes
I ***THINK*** you need to be using views-view-fields--myview--block-2.tpl.php to access $fields.

# Answer
> 0 votes
Simple concept is go to theme information and check the tpl file names in the field you want and choose the unique file name from there and create the tpl file.
Now click on the first file name which will give you the basic code, copy that in your tpl file now in comment you will see all four variable try with `$row` and print the whole array and find all your other fields as well.

# Answer
> 0 votes
If you are not sure about the file name for your template you can use the theme developer module. You can just point and click on in your browser to find the right theme and template functions.

---
Tags: views
---


title: Validate a path within the site?

text:
# Question
Title: Validate a path within the site?
I'm working on a module that accepts user-specified paths for special treatment. I want to have a validation step where I check whether that path actually exists on the site.

Is doing a query to the `menu_router` table sufficient? Is there a better way -- say, a Drupal function -- to validate a url?

# Answer
Looking at the code for menu\_edit\_item\_validate(), which is the function that validates the input from the user when creating a new menu item, you will notice it calls drupal\_valid\_path(). If that function is not enough, you could look at the code of `menu_edit_item_validate()` to see if that code can be useful to create your own validation function.

```
  $normal_path = drupal_get_normal_path($item['link_path']);
  if ($item['link_path'] != $normal_path) {
    drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $item['link_path'], '%normal_path' => $normal_path)));
    $item['link_path'] = $normal_path;
  }
  if (!url_is_external($item['link_path'])) {
    $parsed_link = parse_url($item['link_path']);
    if (isset($parsed_link['query'])) {
      $item['options']['query'] = drupal_get_query_array($parsed_link['query']);
    }
    else {
      // Use unset() rather than setting to empty string
      // to avoid redundant serialized data being stored.
      unset($item['options']['query']);
    }
    if (isset($parsed_link['fragment'])) {
      $item['options']['fragment'] = $parsed_link['fragment'];
    }
    else {
      unset($item['options']['fragment']);
    }
    if ($item['link_path'] != $parsed_link['path']) {
      $item['link_path'] = $parsed_link['path'];
    }
  }
  if (!trim($item['link_path']) || !drupal_valid_path($item['link_path'], TRUE)) {
    form_set_error('link_path', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $item['link_path'])));
  }

```

If you need to verify if the anonymous user has access to the menu item, you can use code similar to the following one:

```
drupal_save_session(FALSE);
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();

$result = drupal_valid_path($link, TRUE);

$GLOBALS['user'] = $original_user;
drupal_save_session(TRUE);

```

To change the code I shown from `menu_edit_item_validate()`, you should rewrite the last control statement as the following code.

```
  drupal_save_session(FALSE);
  $original_user = $GLOBALS['user'];
  $GLOBALS['user'] = drupal_anonymous_user();

  if (!trim($item['link_path']) || !drupal_valid_path($item['link_path'], TRUE)) {
    form_set_error('link_path', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $item['link_path'])));
  }

  $GLOBALS['user'] = $original_user;
  drupal_save_session(TRUE);

```

This is the only possibility you have, if you don't want to rewrite all the code Drupal uses to verify if a user has access to a menu item, as that code verifies the currently logged-in user has access to the menu item, not a user for which the user object is passed to the code.
> 4 votes

---
Tags: 7, uri
---


# Question
Title: Linking organic groups - or am I overlooking a better solution?
I'm attempting to use Drupal 7 with organic groups to create a network of groups for local affiliates of a national organization. Initially we want users in each group to be able to post private content inside of the group, which is not a problem. However, since local affiliates tend to share ideas and files we'd also like a group administrator to be able to "link" their group with another trusted affiliate so that users of the two affiliates can have access to the content in the linked groups.

I realize the people in each group can be added to other existing groups, but as far as I am aware this is on an individual basis and thus would not be sustainable going forward as members that are added and removed from their primary group would not automatically have their membership changed in the other affiliated groups.

The closest thing I've seen is http://drupal.org/project/og\_affiliations but it's no longer being updated. I was wondering if anyone has any ideas for approaching this setup or if there might be a better solution than OG that I'm overlooking?

# Answer
> 1 votes
I have not played around with og much but from what you are saying this should be possible with rules. Basically you would create an event based on the change (perhaps create a group admin role only flag which lets them flag each other to create the bond and the trigger. That way if one breaks the bond, the permissions are reversed which would require an extra but similar rule) that would trigger an action to load a list of users from the group. Then add a loop to loop through the list of users performing an action on each one as you go (i.e. add to other group). Not sure what custom actions og brings to rules or vice versa but I see no reason why it shouldnt be possible this way.

# Answer
> 0 votes
I'm not sure if this is right for your situation, but you might also want to consider Domain Access, which was created with a similar use case in mind - a national organization and local affiliates.

The pro would be that the functionality of publishing content to one or more affiliates is built-in. But it doesn't solve your problem of bulk-adding members of one affiliate to another, so you'd still need a solution like the one 7wonders suggests.

You may already be familiar with this module and have determined it doesn't do what you need, but if you're not, you should take a look.

---
Tags: organic-groups
---


title: D7 Form Builder and Comment Forms

text:
# Question
Title: D7 Form Builder and Comment Forms
I need to create a post/comment structure almost exactly like what you're looking at right now: original post with comments, subsequent 'answer' posts with their own comments. In response, I'm displaying a views page with a custom path displaying the original post (content type) and the subsequent answers (also content types). The issue lies with printing comment forms for each of the following nodes.

So far, I'm attempting to use the Views PHP field to print the comment form and failing pretty hard. There is D7 comment form doesn't submit relating to this, and Nikit's solution *did* produce a comment form on demand. However, this form does not submit or preview, submission just redirects the user to the node's comment reply page. Even now I do not understand how this method of calling `drupal_get_form()` works with two arguments.

So I turned to the trusty Drupal API to reference the drupal\_get\_form() function and saw that it **doesn't** take two arguments and returns drupal\_build\_form() instead. I thought that calling `drupal_build_form()` straight up might be more appropriate, since from what I could gleam off of the scarce user feedback said I needed to use a `form_state['redirect']` of some sort to get users back to the original node page they posted their comments from. As expected however, everything I try returns a pile of errors and gets me nowhere.

The one spot of success was with the Commentsblock module that allowed me to place a real live comment form on a page and actually have the stupid thing submit a comment. While this works for the main content, I'm still at a loss for the subsequent 'answer' comments/forms. In ripping through the source code for the module I discovered `comment_node_page_additions($node);`, but this does not turn out any valid results either.

There are so many questions here:

* How does one actually USE the Forms API (and to print comments)?
* Should I be doing this in a .tpl file instead of Views?
* Where does the second argument of `drupal_get_form()` go?
* What exactly is the difference between `drupal_get_form` and `drupal_build_form` and how are they used?
* Is `$form_state['redirect']` called before either of these API calls or after?

This might seem like 'too much' of a question for a single thread, but I'm tired of posting partial questions and getting partial answers. In the interest of education, I would like to build some sort of tutorial either on Drupal.org or elsewhere so that this information can be made available to others in the same situation. Obviously I am not the best person to undertake this due to my massive lack of understanding, but maybe, just *maybe* with your help this can become a reality.

# Answer
1. If you select the 'forms' tag and select its mini menu option 'info', you will see a link to the Drupal pages for the form API and a great basic explanation on how it is used.
2. You should not use PHP in the view. PHP in content of any sort presents a security risk. The best place to do this is in a custom module.
3. The form API provides documentation on both.
4. `$form_state` is used as central storage for all information about the form. Any part of the `$form_state` array can be read and written to by any function at any time.
> 3 votes

---
Tags: 7, forms, comments
---


# Question
Title: Performance and loading times of theme like Zen vs building a theme from scratch?
Ive used Zen for every Drupal site ive made for years so im well aware of the benefits and how much it speeds up front end development. However I have noticed that there are far more div tags and css than would be needed if I built a theme from scratch and only included exactly what was needed. Especially as my clients are increasingly interested in mobile optimisation, are there any stats or anecdotal evidence about how much of a performance hit this extra markup is causing?

# Answer
> 1 votes
Although I have used Fusion, instead of Zen, my personal experience is probably applicable. You can run some comparisons using Zen vs. Stark, which is very stripped down to get an idea how they compare. There are, of course plenty of other factors that can contr5ibute to the equation.

Regardless of the performance issue, there is also the development question. Styling one of these themes can be a challenge especially if you include panels, views, superfish menus, or any other module that may also affect appearance. I had a full head of hair when I started.

I found it much easier to use Panels-Everywhere and Panels to bypass the them system and create my own display formats. This removes a lot of inherited CSS and made styling much easier.

---
Tags: performance, theming
---


# Question
Title: White screen of death when uploading a file attachment
I am currently experiencing a problem when adding file attachments to nodes in Drupal 6. When attaching a file and clicking the upload button, the screen goes white. I checked the files directory and the file does not appear there so it would seem it never gets uploaded. This problem occurs on the production server but not the test server. I have tried displaying php errors by modifying the index.php file but that does not display anything. I have the php memory set to 154MB but still no dice. I have Googled and searched this site but can't find a solution. Has anyone else experienced this problem? Can anyone provide some insight as to what the cause of this might be (and hopefully how to fix it)?

System setup

Ubuntu 10.4, Apache, PHP 5.3, MySQL 5.1

Drupal 6.22, CKK 6.x-2.9, jQuery UI 6.x-1.5, jQuery Update 6.x-2.0-alpha1, plus a whole boatload of other modules (that may or may not be relevant).

Thanks for any possible insight into this.

# Answer
> 0 votes
mod\_fcgid have to do with FastCGI.

There are actually a few PHP settings you may need to investigate and modify.

Reference: Increase upload size in your php.ini

In short though, you will need to up your `upload_max_filesize` as well as your `post_max_size`

Also, I would recommend watching your /var/log/apache2/error.log (Default location in Ubuntu 10.4) while debugging. Generally running `sudo tail -f /var/log/apache2/error.log` will show you 'white screen' errors in real time.

---
Tags: files
---


# Question
Title: User-Profile-Form.tpl.php not working. Help!
I am not rendering any results. This is my template.php:

```
function fueldeluxe_theme($existing, $type, $theme, $path) {
  $items = array();

  /**
   *  Account edit Forms
   */

  $items['user_profile_form'] = array(
    'render element' => 'form',
    'template' => 'user-profile-form',
    'path' => drupal_get_path('theme', 'fueldeluxe') . '/templates'
  );

  return $items;
}

function fueldeluxe_preprocess_user_profile_form(&$variables) {
  $variables['account'] = drupal_render($variables['form']['account']);
  $variables['picture'] = drupal_render($variables['form']['picture']);
}

```

This is my user-profile-form.tpl.php:

```
<div id="account-settings">

  <div id="profile">
    <?php echo $picture; ?>
  </div>
  <div id="account">
    <?php echo $account; ?>
  </div>
</div>

```

As you can see I'm trying to load the user profile field forms. However I'm not able to render any results. The page loads okay when I add dummy text but no account field forms.

Do I need a module for this to work?

Also what would the variable look like for calling the custom field added to a user?

# Answer
I'm struggling with what you're asking in the first portion of your question, but looking into the previous Stack Exchange page you referenced you can use the Panels module to quickly accomplish two column layouts for these forms. You can also use template overrides to change the layout of the registration pages.

If you're specifically looking to quickly implement a tabbed UI for the user profile, I believe the Profile2 module may offer a built-in solution.

> "Also what would the variable look like for calling the custom field added to a user?"

You may need to use load\_user() first to get a complete user object to access custom profile fields.

```
$account = user_load(<USER-ID>); //$node->uid or $user->uid

```
> 0 votes

---
Tags: 7, users, theming
---


title: Drupal 7 MultiStep Form

text:
# Question
Title: Drupal 7 MultiStep Form
I am trying to implement the Multistep tutorial (Step 9) from http://drupal.org/node/717750 in Drupal 7, however in the following function

```
function my_module_my_form_new_name($form, &$form_state) {
  $form_state['storage']['new_name'] = TRUE;
  $form_state['rebuild'] = TRUE; // Will cause the default submit function
                                 // to be skipped.
}

```

I just cant set the `$form_state['storage']['new_name'] = TRUE;` therefore i can't catch it in :

```
 if (empty($form_state['storage']['new_name'])) {
    $form['new_name'] = array(
      '#type' => 'submit',
      '#value' => 'Add another name',
      '#validate' => array('my_module_my_form_new_name'),
    );
  }

```

I can however declare it in the beginning of the function, which can be executed fine. So how can I set it in Drupal 7?

# Answer
Helpful links for creating multi steps form are https://drupal.stackexchange.com/questions/135/are-there-any-examples-of-setting-up-multistep-forms http://drupal.org/node/717750, and http://drupal.org/project/examples.

I practiced multi step forms by getting the code of the form tutorial from http://drupal.org/project/examples, and added further steps; it works excellently fine for me.
> 4 votes

---
Tags: 7, forms
---


# Question
Title: Latest added data in a particular contenty-type on custom page
I am a newbie in Drupal,I have content-type "News" where the user adds news related to product. I want to show the latest 3 added news on content-type "Home-Page" *(Home-Page is not front page).*
What would be the standard way to get the desired output?
\**I am using Drupal7

# Answer
> 3 votes
There are many, many ways to accomplish this but here is one of the simplest ways I can think of.

I'm going to use the Drupal Views module to do this. The intent of this is not to cover all things Drupal, rather it's to give you a crash course in creating a block using Views to accomplish what you're looking to do.

First, install and enable Views. There are several tutorials out there that show you how to do this. Nodeone has an awesome video introduction to Drupal Views. (Personally this is one of my favorite Drupal resources. :)

Now that Views is installed and enabled, go to Structure, then 'Views' (In D7 this will be at `http://www.example.com/admin/structure/views`.)

---

Next create a new view (Add New View.)

Next, configure your View settings. The example settings below will create a new block that contains the three most recent News items that link to the full version of each article article. Views is capable of far more, but for the sake of simplicity I'll stick to creating a simple block.

Now go back to "Structure" and this time go to "Blocks."

My theme will be different from yours, but what you need to do is find the view you created, choose a location on your theme where you would like it to be displayed and then click save. In this example I'm moving the block to the top of the navigation bar on the right hand side of my theme.

Once saved you should see similar output on your site as in the image below. Note that this has my theme applied and your block will look different.

Lastly, to control which pages this block will be displayed on you can use the Blocks visibility settings. How do I show blocks only on certain pages? is a great resource.

There are likely a million other ways to accomplish this, but this was the quickest I could think of using my nifty Greenshot app.

# Answer
> 1 votes
Check out the Views module. This allows you to make pages (or blocks or many other things) which can get data from your drupal installation. Very powerfull.

In your case, you use a view to get the top 3 items from the content type "News" sorted by date posted.

---
Tags: views
---


# Question
Title: A particular content type forces preview before save. How do I turn this off?
I've set up a new content type, but for this (and none of my other custom content types), it forces a preview before the save button appears.

Is there a way I can turn this off? I've looked around and can't see an obvious option to turn it off, but maybe I'm being blind. It's really frustrating.

# Answer
> 6 votes
You can set this option easily:

1. Edit the content type
2. Click *"Submission form settings"*
3. Set *"Preview before submitting"* to *Optional* (or *Disabled* if you don't want previews at all).

---
Tags: 7, nodes
---


# Question
Title: Customizing main_menu so that it shows nested elements with styling in Drupal 7
I have the following menu structure which i like to implement in Drupal 7 :

```
<ul id="dropdown-menu" class="fixed">
    <li><a href="index.html">Home</a></li>
    <li><a href="about.html">About</a>
        <ul class="sub-menu">
            <li><a href="about.html">About Us</a></li>
            <li><a href="team.html">Team</a></li>
        </ul>
    </li>
</ul>

```

So far i have the base elements displaying correctly using :

```
<?php
print theme('links__system_main_menu',
array('links' => $main_menu, 'attributes' => array('id' => 'dropdown-menu',
'class' => array('fixed'))));
?>

```

Problems :

* It doesn't display nested elements
* I can only control the styling of the first level but in my code i have to apply a subclass of 'sub-menu' according to my theme.

Can someone point me to a starting point ? Thanks

# Answer
As far as I know, it's not possible to make `theme('links__system_main_menu' [...])` display the nested elements. That suprised me, too...

One way to fix this: set up a region in the theme for the menu and put a menu block in there. This will display the nested elements, however styling the menu itself won't be much easier than before. `theme_menu_tree()` and `theme_menu_link()` hooks could be useful.

Also, check out the Menu block module.

p.s. I'm currently doing something similar that you do and it seems to be quite complicated for me, too, so I just summarized what I've already found.
> 2 votes

---
Tags: routes, navigation
---


title: Module to manage lots of blocks

text:
# Question
Title: Module to manage lots of blocks
Any module to manage lots of blocks? Since the block page is so huge to load. Or any other methods to manage lots of custom user defined content expect node.

# Answer
Try the Context module.

> Context allows you to manage contextual conditions and reactions for different portions of your site. You can think of each context as representing a "section" of your site. For each context, you can choose the conditions that trigger this context to be active and choose different aspects of Drupal that should react to this active context.
>
> Think of conditions as a set of rules that are checked during page load to see what context is active. Any reactions that are associated with active contexts are then fired.
> 3 votes

# Answer
The block admin page is not supposed to be loaded in daily activities. Don't worry about it. If a huge draggable table make that page impossible to use, then disable JavaScript when you are on it.
> 0 votes

---
Tags: blocks
---


# Question
Title: Which type of page to use for a customized front page in Drupal 7?
I am watching the following tutorial on panels. The author is creating a content type for 'Home page', and later, a node view variant of node templates. He mentions that he is not 100% about this way of proceeding, but he is used to it.

The more I learn about this subject and the more I try to replicate this approach, the less I am convinced by it. Creating a content type for a home page seems like an heresy.

The panels dashboard offers to create panel pages, but also landing pages. It seems to me like a landing page would be enough (after setting it as the default front page), but would a panel page offer more benefit in this case?

# Answer
> 3 votes
I always tend to use the Context module. Just set up a front page context that doesn't load all the unnecessary items (blocks, breadcrumbs or whatever) then have any node/panel you fancy as a home page without all the extra items that you don't need rendered onto the page. It does seem slightly overkill to have an entire content type dedicated to one node though, I agree with that.

# Answer
> 1 votes
The "homepage" word is abusive. It's not the home/landing page of your website. In the tutorial, it's just a layout. All nodes with the content type "homepage" will use this layout. That's all. And there might be a number of nodes "homepage".

If you want a real and unique homepage, that means no other pages have the same layout, then the way is to use a custom page (a landing page) and define it as frontpage (the "correct" term to say "homepage" in Drupal).

In short, there are two solutions for two different problems.

---
Tags: 7, panels
---


title: Video upload via FTP

text:
# Question
Title: Video upload via FTP
The Video module for Drupal 6 allows for video files uploaded via ftp to be played. Does this module's Drupal 7 version have this feature? If not what is the work around for large files?

# Answer
> 5 votes
You can add this feature using the FileField Sources module. This module adds FTP (and more) upload to any FileField upload field, including the Video FileField upload field.

---
Tags: 7, files
---


# Question
Title: Increasing width of Views 3 search form filter
I am trying to increase the size of my views search filter form. The form id is views-exposed-form-blog--user-s-tab--page and am trying to use this in code I've used for my search block but its not working.

Here's my search block code -

```
function Themename_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_block_form') {
    $form['search_block_form']['#size'] = 26;
  }
}

```

Any ideas how I can make this work?

Thanks in advance

# Answer
> 3 votes
Perhaps you can get away with a simple CSS rule in your theme's stylesheet? Something like this:

```
#views-exposed-form-blog--user-s-tab--page input{width: 200px;}

```

That width can be anything. In this example, it'd be 200pixels wide.

---
Tags: 7, views
---


# Question
Title: Dropdown menu with descriptions only in sub-menu elements in Drupal 7?
I'm trying to implement a dropdown menu in my custom theme. At the moment, this means I have a region for the primary and another region for the secondary menu.

According to the design I would like implement, the description of a menu element should be visible - but only for sub-menu elements, like in this menu:

My problem is the following:

**I can't find a way to handle different levels of menus accordingly, i.e. to add the markup of the descriptions only where necessary and the different classes on ULs.**

How should I implement this kind of menu?

\[I've installed the Menu Block module for some help with this. It adds several new hooks that might be useful, but we will see...\]

Thanks for checking out this question!

# Answer
Within your theme's template.php, you can override the theme\_menu\_link() function.

Target the `$variables['element']['#original_link']['depth']` variable to check for the depth of the current menu item.

The variable `$variables['element']['#original_link']['localized_options']['attributes']['title']` holds the "description" value entered on the menu item's edit page.
> 4 votes

---
Tags: theming, routes
---


title: Contextual Filters not working

text:
# Question
Title: Contextual Filters not working
I have a view which is a clone of the Product view (created for the Drupal commerce module).

In the view I set a contextual filter. But it just doesn't work as required.

It is very rare since the view is pretty simple.

Please take a look at the capture I've made: http://screencast.com/t/tgRPQQCm

The "Categoria" field is a **Term Reference** field type.

If I use other field as a Contextual Filter it works fine. Look: http://screencast.com/t/yspxMFxjA0k

Then there is something wrong with the field??

# Answer
I just found the solution to this. It was missing some setting in "When the value IS in the url..."

Check the image capture:

http://screencast.com/t/6dY8k3z4Za
> 0 votes

# Answer
I do not have sound so not sure if I was following properly, but could it be that you are using a contextual filter rather than a regular filter?
> 0 votes

---
Tags: views
---


# Question
Title: Understanding theme hooks and template preprocessors
In hook\_theme for the poll module in drupal 7 the following is defined:

```
function poll_theme() {
  $theme_hooks = array(
    'poll_vote' => array(
      'template' => 'poll-vote',
      'render element' => 'form',
    ),
    'poll_choices' => array(
      'render element' => 'form',
    ),
    'poll_results' => array(
      'template' => 'poll-results',
      'variables' => array('raw_title' => NULL, 'results' => NULL, 'votes' => NULL, 'raw_links' => NULL, 'block' => NULL, 'nid' => NULL, 'vote' => NULL),
    ),
    'poll_bar' => array(
      'template' => 'poll-bar',
      'variables' => array('title' => NULL, 'votes' => NULL, 'total_votes' => NULL, 'vote' => NULL, 'block' => NULL),
    ),
  );
  // The theme system automatically discovers the theme's functions and
  // templates that implement more targeted "suggestions" of generic theme
  // hooks. But suggestions implemented by a module must be explicitly
  // registered.
  $theme_hooks += array(
    'poll_results__block' => array(
      'template' => 'poll-results--block',
      'variables' => $theme_hooks['poll_results']['variables'],
    ),
    'poll_bar__block' => array(
      'template' => 'poll-bar--block',
      'variables' => $theme_hooks['poll_bar']['variables'],
    ),
  );
  return $theme_hooks;
}

```

In `function poll_view_voting($form, &$form_state, $node, $block = FALSE) {` there is `$form['#theme'] = 'poll_vote';`

How does this work and what does this to?

Also there is this function:

```
function template_preprocess_poll_vote(&$variables) {
  $form = $variables['form'];
  $variables['choice'] = drupal_render($form['choice']);
  $variables['title'] = check_plain($form['#node']->title);
  $variables['vote'] = drupal_render($form['vote']);
  $variables['rest'] = drupal_render_children($form);
  $variables['block'] = $form['#block'];
  if ($variables['block']) {
    $variables['theme_hook_suggestions'][] = 'poll_vote__block';
  }
}

```

I was able to create a function theme\_preprocess\_poll\_vote(&$variables) which I was able to change the output. Is their a document that explains how this all works?

# Answer
I'd suggest you read everything you can in the Theming guide. It looks like you're specifically looking for this part of it though.
> 4 votes

---
Tags: theming
---


# Question
Title: How to hide "Include file in display" in File Field?
I'm using File Field in Drupal 7 to let users upload files, but after uploading there is a choice for users to let the file be included in display or not (radio button with "Include file in display" description). Now I want to remove this choice, because I need all of the files display for download, OR at least hide this for non-admin users. What should I do?
Thanks.

# Answer
You need to set that in the field's settings page.

```
Structure > Content Types > [your content type] > Manage Fields > Edit [your file field]

```

You will see settings for the `Enable Display Field` Option. The caveat is that if you already have data in this file field, unchecking this may not have an effect.

(See my screen capture)
> 5 votes

---
Tags: 7, files
---


# Question
Title: In drupal 7, for field widget type, what is "server side" used for?
I created a new content type and added a text field. While creating the text field I am given three options for the widget type: Server Side Only, Hidden Field, and Text Field. The "Server Side Only" and "Hidden Field" come from the Hidden Field module. Can someone explain when Server Side Only would be used?

# Answer
> 0 votes
I can't find any reference on Google to a widget that provides this type of functionality so I can only assume it's something custom, but I think the reasoning for it would be the same regardless:

When using the Drupal form API you can add an element of type `value` which keeps that element server-side only...i.e. the value is available to the form submission/validation functions but it not exposed to the user. A hidden field would still be exposed in the form's HTML so could theoretically be changed by the user before the form is submitted.

I would guess in this case it applies to the node edit form, each node would essentially have a non-editable field with a constant value. I'm not actually sure how useful this would be in normal life but I guess if every node had to have, for example, a geo-location map associated with it, and the value of that location field had to remain constant, this would do it. The same map would just be outputted on each node.

To be honest that could all be nonsense though, it's just an educated guess :)

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


# Question
Title: How to use mssql as database for my site running on redhat linux
My D6 site is running on linux and I'm using Postgresql as database. but now I want to change mssql as database on windows. how I do that?

# Answer
> 2 votes
Once your new server is running, you only have to do a few things.

1. Dump the old database (PgSQL)
2. Convert the dump to MSSQL
3. Import the dump.

If you search on google you should be able to find tools that will allow you to export convert the dump. This is not perfect but is probably the easiest solution.

Alternatively if that doesn't work, you can create a script that from within Drupal fetches data from one database and then inserts it into the other database, effectively using Drupal/PHP to translate the dump. This is much slower and requires more work, but have less chance of failure.

# Answer
> 2 votes
This is simply not possible with Drupal 6, nor will it ever be. It is possible with Drupal 7 on IIS only.

Drupal 7 has a database abstraction layer, so it can be used with any database that has 1) a system database driver and 2) a module to do the un-abstracting to the specific database you want to use. Check out the Drupal SQLSRV project for 2.

The title says this is for a site running on Redhat Linux, but the question says Windows. This only works if you are using IIS as your webserver.

System drivers for MSSQL are barely available for RHEL 5, just released by Microsoft as a PDO driver in December (though this guy got it compiled for a Fedora release, so YYMV), and the Drupal module doesn't support the RHEL system drivers at this time.

---
Tags: 6, database
---