# Question
Title: Complicated content/node access scenario, input wanted
the requirements are the following:

In the site we'll have groups of users, that can access content posted in their group, much like Organic Groups does.

Apart from that though, the author of each node, must have the ability to override that functionality and "invite" specific users to view the node, even if it's in a group bypassing the group's settings. So if the group contained the users U1, U2, and U2, but the author invited U2,U4 and U5, U1 and U3 wouldn't be able to access the node.

On top of that, the author must have the ability to add specific users as "facilitators" to that node which grants them "Edit" rights on the node and the ability to invite more people to view the node as described above.

By using organic groups AND node access user reference, I've been able to accomplish the grouping and either the "participants" feature OR the "facilitators" feature, since as it seems, node access user reference cannot support 2 grant types on the same node.

Now, the general advice is "you don't want to use more than one node access module on your site." (http://drupal.org/node/270000). So the idea of adding yet another one, to accomplish the missing feature sounds wrong. Also creating a custom module to encapsulate all of this functionality seems like a lot of work.

So, since I am facing a sort of a blocker in my project analysis I'd like some input on how you guys would go on about tackling such an issue. Thanks in advance.

EDIT: Seems that even the synergy of Organic Groups and node access user reference is not working as intended. Just works in public groups' content since there is no 'group\_access\_authenticated' record in the 'node\_access' table and node access user reference handles all the grants. In private groups where for example one user (U10) can be a member of the group but NOT in the list of the node's "participants", since he has the 'group\_access\_authenticated' grant, he is able to view the node in question thus breaking the functionality.

# Answer
Well, just for anyone who stumbles upon this in the future, DO write your own content access module. Once you grasp the logic it's quite simple and it will solve your problems while allowing you to keep the logic of other modules involved in your project. Simply copy their code/logic and set it along with the rest of your requirements with higher priority.
> 0 votes

---
Tags: 7, organic-groups, users
---


# Question
Title: Pathauto doesn't work anymore when i change the default language
I've got a big problem this morning.

I'm working with english as default language `Administration » Configuration » Regional and language`. It's much more easy to me to work with the interface in english.

But this morning i have to change the default language to french because my boss want the interface in French (and the website is almost finished)

But unfortunately, all my alias doesn't work anymore like before `www.example.com/my-article` is becoming `www.example/node/5`. More precisely, it's only alias from `content type` who doesn't work fine because taxonomy term are ok.

Does someone has a idea why when i changed the default language in `Administration » Configuration » Regional and language` (english to french) my alias didn't worked anymore?

# Answer
> 1 votes
when you enable translation you can translate a node to that language, as all your nodes are in english, there is no real french node for that.

obviously the path-alias is not taken.

you need to copy all nodes to have them in french too, just hit translate while editing a node, upper right.

there is also the i18n module giving you more translation options.

# Answer
> 2 votes
This happens because the table url\_alias has a language property that doesn't match anymore with the default language. Try to change the language code to your default language or delete the information. (Of course, make a backup before in case of).

---
Tags: 7, path-aliases
---


# Question
Title: How to provide the ability to upload media to the server?
I want to provide the ability to upload PDFs/mp3s etc. to the server.

What is the best way of achieving this?

I've seen the media plugin but it seems that replaces the upload field rather creating a stand-alone media area? Or maybe it does?

# Answer
> 5 votes
I think Media is a great module unless if your client will upload and use the same PDFs/MP3 once a time.

But if your client plan to use at severals places the same Media, so Media module is for you.

Also, give a look at Scald, seems to be a promise module.

---
Tags: 7
---


title: Members in organic group module

text:
# Question
Title: Members in organic group module
I am using OG module for creating a group. Based on the group we made the functionality of adding a member, discussion based on the created group. I have a link with subscribing a member for my created group. I have doubt with how to show the added member in the front end group list. Please suggest me some ideas.

Thank you, Sathish

# Answer
I think for that purpose, if I understood well, you need to use Views module with a user view you will be able to do create list or whatever you want.
> 0 votes

# Answer
Og module by default gives OG members view. Install views module and check for OG members view. Enable the block on all Group Landing pages. That should solve the problem!
> 0 votes

---
Tags: organic-groups
---


title: Long time of node_submit + node_save

text:
# Question
Title: Long time of node_submit + node_save
I measure time of my batch node creation and it's fairly acceptable at the beginning with, let's say 200 nodes, and totally disappointing at 1700 nodes. After some measurements I found out that the culprit is the node\_submit / node\_save part. For loop of 20 nodes creation it takes 5-6 seconds for each node to happen.

Where should I look for optimization? Is it some heavy module ruining my performance? Maybe it's some devel function that slows it down.

On almost empty base my call runs for 8 secs. When there's about 1600 nodes in the base I have to wait 120 secs! (loop of 20-21 nodes 5 secs each).

# Answer
> 0 votes
I found the culprit. After turning most of the modules I found out it's WORKBENCH.. Probably it has efficiency problems. Now instead of 15-20 seconds it takes 1 sec to node\_save.

---
Tags: 7, performance
---


# Question
Title: Ubercart vs Drupal commerce for french ecommerce site
This is my first experience with french e-commerce site . I want to know which solution will speed up the developing of the website .

Also is there a module payment for Carte bleu in drupal commerce, and is it ready for production site ?

# Answer
Check this article which compares Ubercart & Commerce modules. Winner is commerce module for most advanced features and simplicity.

Commerce module is written from scratch to solve usability and other issues in Ubercart. Commerce module will be obvious choice for E-commerce portal.

As far as i know there is no out of the box module for Carte bleau payment gateway. But, if you know the module development you can write one and contribute to community using commerce payment gateway API. This will help you.

Best of luck :-)
> 2 votes

# Answer
For a fast solution D7 with Drupal commerce. Install a demo to see, Drupal commerce provide a version of Drupal7 with all modules necessary already installed. Add some items and you can use your e-commerce site few minutes after the install.

Now what'll take you times is the theming of your site. For that Ubercart can be better because of his background much more bigger than Drupal commerce.
> 2 votes

---
Tags: commerce, ubercart
---


# Question
Title: How do you dynamically redirect a user's role?
This is a two parted question that deals with two different Modules "User" (or even possibly "triggers and actions") and Profile2. The main task is to have a user dynamically placed within a user role based on the information they submit within the user registration form fields. Presently, I have the form set up with a taxonomy button list. What happens next is the user should then be given a profile type that they can edit after the account creation is complete. Can you help?

# Answer
One of the easiest ways with the UI is to use Rules. Create a new rule that is set on either when a user creates saves a new account or saves a new profile (or what ever the instance is that prompts for role change). Then you set up a condition of a matching data comparison. Then have it change the user role.
> 0 votes

# Answer
Checkout Auto Assign Role module.

You might need some customization or might have to play with the rules module as well.
> 1 votes

---
Tags: users, actions, rules
---


title: Adding web font from Fonts.com

text:
# Question
Title: Adding web font from Fonts.com
I made a test.html file to test web fonts bought on Fonts.com.

```
@import url("http://fast.fonts.com/cssapi/3bcaa9a7-xxxx...xxxx.css");

```

This worked without any problem. But when I add this to my global.css file in my Drupal Template, it doesn't work. Other things from global.css are all ok... So the file gets loaded.

Any other simple way to do this without the use of a module?

# Answer
Oh my god... It had to be something stupid. This was the sollution:

On Fonts.com go to "Manage Web Fonts", and add a domain. The HTML I tested was on my localhost, the Drupal wasn't.

Glad I found the answer when I was walking outside...
> 0 votes

---
Tags: 7, theming
---


title: ajax request only the first time works?

text:
# Question
Title: ajax request only the first time works?
I have made an ajax request to update the select options based on the first select field selection

but the respond only works fine with the first request despite being seen with firebug

help me solve it please

thanks in advance

here is the code

```
 function listings_form_alter(&$form,&$form_state,$form_id){
    $governments=array();
  if($form_id == 'place_node_form' && arg(1)=='add' && arg(2)=='place'){
    $vocabularies=taxonomy_get_vocabularies();

  foreach($vocabularies as $vocab){
      if($vocab->machine_name =='governorates'){
          $_SESSION['vid']=$vocab->vid;
          break;
      }
  }
        $options=array(0=>'choose gov');
  $g=taxonomy_get_tree($_SESSION['vid'],0,1,FALSE);
  $x=count($g);
  for($i=0;$i<$x;$i++){
                  $options[$g[$i]->tid]=$g[$i]->name;
  }

   $form['gov']=array('#title'=>'Gov','#name'=>'governorate'
,'#type'=>'select','#options'=>$options
     ,'#ajax'=>array('callback'=>'ajax_callback',
  'event'=>'change','wrapper'=>'replace','method'=>'html'));

 $op=array(0=>'choose city');
$form['city']=array("#title"=>'City','#name'=>'city',
'#type'=>'select','#prefix' => '<div id="replace">',
'#suffix' => '</div>','#options'=>$op);

function ajax_callback($form_state,&$form){

$childs_obj=  taxonomy_get_children($_POST['governorate'],$_SESSION['vid']);
foreach($childs_obj as $child_item){
    $op[$child_item->tid]=$child_item->name;
}

$form['city']=array("#title"=>'City','#name'=>'city','#type'=>'select','#prefix' => '<div id="replace">',
        '#suffix' => '</div>','#options'=>$op);
return array(
'#type'=>'ajax', '#commands'=>array(ajax_command_html("#replace", render($form['city'])),
ajax_command_alert($_POST['governorate'])
    )

```

); ?\>

# Answer
> 0 votes
Please see http://drupal.org/coding-standards, as it is hard to read.

However that said, I usually find if ajax is only working once then as the element is replaced Drupal gives it a unique id which then breaks a selector. For example #form after the ajax request becomes #form-1 and is no longer targeted. -check for this in firebug

---
Tags: ajax
---


title: referenced node in primary tabs

text:
# Question
Title: referenced node in primary tabs
I am looking for a way to show a referenced node into the primary tabs menu.

I created a content type "fact box" that is referenced to an article. Now i like to have the content type title of the fact box node in the primary tabs menu.

I tested the Quicktabs Module and References Tabs, but they don\`t use the primary tabs menu.

What\`s the right way to reference a node into the primary tabs menu?

# Answer
> 0 votes
Is this for Drupal 7?

If so you can create a custom module using hook\_menu\_local\_tasks\_alter, maybe in the hook get the arg for the nid for the current page. Then do a node load on the current pages nid to check a reference is set, then from this reference field which will contain the nid... do another node load to get its title. Finally the title local menu tab.

---
Tags: routes
---


# Question
Title: nodeapi with op = load being ran multiple times
I am currently creating a custom module. I am trying to alter a node's body before it is displayed to the user. So I used hook\_nodeapi();

I did something like

```
function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
  if($node->type=='page' && $op =='load'){
    dsm($op);
    //the rest of my code goes here
  }
}

```

When ran, this displays 8 "load"s when viewing a page.

Why is that? I think it is because of the other modules I have that may be calling node\_load, but I am not really sure.

Can anyone shed a light here? And how do I make it possible so that my code is not ran multiple times (in this case, 8 times)?

Thanks.

UPDATE: I forgot to mention a couple of key things.

I am using the revisioning module. The page I am viewing is an unpublished revision. I tried this:

```
function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
  if($node->type=='page' && $op =='load'){
    dsm($node->nid);
   dsm($node->vid);
   //the rest of my code goes here
  }
}

```

I get 8 similar nids, and then 7 similar vids (the unpublished revision), and then 1 vid (the currently published revision)

916 4544

916 3740

916 4544

916 4544

.. and so on

# Answer
You need to use view $op

```
function hook_nodeapi(&$node, $op, $teaser, $page){
  if($node->type=='page' && $op =='view'){
    if ($teaser) {
      drupal_set_message("I am viewing page content type teaser");
      //the rest of my code goes here
    }
    if ($page) {
      drupal_set_message("I am viewing page content type full node view");
      //the rest of my code goes here
    }

  }
}

```

> **view**: The node content is being assembled before rendering. The module may add elements $node-\>content prior to rendering. This hook will be called after hook\_view(). The format of $node-\>content is the same as used by Forms API.

And you need to check for teaser view or full node view using $a3 or $a4 respectively.

Check how many nodes you are rendering in a page. For example if you are in a view where view is displaying 10 nodes then 10 times message will appear.

Hope it answers your issue !
> 0 votes

# Answer
hook\_node\_api will be invoked for each every node available in the page or in one execution.

If you want to alter, particular node's content then add a condition with nid or title
> 0 votes

---
Tags: nodes
---


# Question
Title: How to obtain a token based on a entity_reference field?
I have a node type A with a **entity\_reference field** named "field\_subnode" pointing to a node type B:

A -\> B

I'm using pathauto, with the following patterns setted up:

URL path for nodes of type A: books/\[node:title\]

Now I need something similar to: **books/\[node-type-A:title\]/\[node:title\]** as path for my nodes of type B, to obtain urls like the following:

books/my-car-book/chapter-1

**Which token I have to use to obtain what I want?**

I've tried different tokens like for example:

books/\[node:field-subnode:1:title\]/\[node:title\]

but without success.

Thank you for helping me.

# Answer
You need the Entity Tokens module, part of the Entity project: http://drupal.org/project/entity. Once it's enabled you'll see the available recursive tokens in the tree.
> 3 votes

# Answer
This is a workaround I've used recently. It requires you to define your own token for a single entityreferene field. Assuming you have a module called mymodule, the entityreference field on the node is called field\_subnode this will allow you to use the token chains like \[node:subnode:title\]. Rename mymodule with your own module name and clear your caches after implementing.

```
/**
 * Implements hook_token_info().
 */
function mymodule_token_info() {
  return array(
    'tokens' => array(
      'node' => array(
        'subnode' => array(
          'name' => t('Node reference'),
          'description' => t('Node referenced via field_subnode'),
          'type' => 'node',
        ),
      ),
    ),
  );
}

/**
 * Implements hook_tokens().
 */
function mymodule_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  $sanitize = !empty($options['sanitize']);

  if ($type == 'node' && !empty($data['node'])) {
    $node = $data['node'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'subnode' :
          $default = '';
          if (isset($node->field_subnode)) {
             $subnode = entity_metadata_wrapper('node', $node)->field_subnode->value();
            $default = $subnode->title;
          }
          $replacements[$original] = $sanitize ? filter_xss($default) : $default;
          break;
      }
    }

    if (isset($node->field_subnode) && $subnode_tokens = token_find_with_prefix($tokens, 'subnode')) {
      $subnode = entity_metadata_wrapper('node', $node)->field_subnode->value();
      $replacements += token_generate('node', $subnode_tokens, array('node' => $subnode), $options);
    }
  }
  return $replacements;
}

```
> 1 votes

# Answer
I have a similar setup with services and sub-services and the following pattern works beautifully. I'm setting this pattern on the sub-service content type where I have a term reference field called field\_service linking to its parent service.

```
services/[node:field-service:title]/[node:title]

```

In your case, you're setting the reference field on the parent node instead of on the child node. If it's possible, flip this. If not, I'm not aware of a token that you can put in B that will reference the field that is set in A (whereas in my case it's a token in B referencing a field in B) and I guess most probably this won't be available even in future releases for technical difficulties.

I'm using the following:

* Drupal 7.15
* entity 7.x-1.0-rc3 (with Entity tokens module enabled)
* entityreference 7.x-1.0-rc5
* pathauto 7.x-1.2

Hope this helps.

Cheers.
> 1 votes

---
Tags: 7, tokens, entities
---


# Question
Title: Form api: Combine two text fields into a div?
Using the form api is it possible to combine two text fields onto the same row?

E.g. form

```
<?php
function foo_form($form, $form_state) {
  $form = array();

  $form['range'] = array(
    '#type' => 'fieldset',
 );

  $form['range']['min'] = array(
     '#type' => 'textfield',
     '#title' => 'Address'
  ),
  $form['range']['address2'] = array(
     '#type' => 'textfield',
     '#title' => 'Address'
  )
  // ...
  return $form;
}

```

Desired output

```
<div>
  <h2>Range</h2>
  <input name="min" /> to <input name="max" />
</div>

```

# Answer
```
<?php
function foo_form($form, $form_state) {
  $form = array();

  $form['range'] = array(
    '#type' => 'fieldset',
    '#prefix' => '<div class="myclass">',
 );

  $form['range']['min'] = array(
     '#type' => 'textfield',
     '#title' => 'Address'
  ),
  $form['range']['address2'] = array(
     '#type' => 'textfield',
     '#title' => 'Address'
     '#suffix' => '</div>',
  )
  // Remaining code
  return $form;
}

```
> 11 votes

# Answer
Its better use css to align two inline . Find out the wrapper div id, then apply this css

```
WRAPPER_ID {
  display :inline; // or try inline-block
}

```
> 1 votes

# Answer
This Drupal Stackexchange answer regarding Horizontal Form Elements answered earlier may be beneficial to you. I typically do the same thing with a wrapper div, but did not know about the `container-inline` class.
> 0 votes

# Answer
There's a module that may be of assistance: Field Collection (7.x)
> -1 votes

---
Tags: 7, forms, theming
---


# Question
Title: Render filename of file upload field in node template
I have a field for uploading a file. And in \*node--content\_type.tpl.php\* I want to just print the filename of the uploaded file.

So far I have this

```
$node = node_load($nid);
//get field item in correct language
$item = field_get_items('node', $node, 'field_file_upload');
//get field_file_upload value
$output1 = field_view_value('node', $node, 'field_file_upload', $item[0]);
print render($output1);

```

But it renders a link to the download and a thumbnail of the download type.

**I want to just print out the filename.** I tried using:

```
$output2 = field_view_value('node', $node, 'field_file_upload', $item[0]['filename']);
print render($output2);

```

But this renders a thumbnail of the download type e.g PDF icon rather than showing the filename.

The printed array for $output1 is:

```
Array
(
    [#theme] => file_link
    [#file] => stdClass Object
        (
            [fid] => 196
            [display] => 1
            [description] =>
            [uid] => 1
            [filename] => drupal-7-theming-cheat-sheet.pdf
            [uri] => public://drupal-7-theming-cheat-sheet_0.pdf
            [filemime] => application/pdf
            [filesize] => 224804
            [status] => 1
            [timestamp] => 1348746651
            [type] => undefined
            [rdf_mapping] => Array
                (
                )

        )

    [#access] => 1
)

```

The printed array for $output2 is:

```
Array
(
    [#theme] => file_link
    [#file] => stdClass Object
        (
            [scalar] => drupal-7-theming-cheat-sheet.pdf
        )

    [#access] => 1
)

```

Any ideas? Thanks for your help!

# Answer
I think you missed a key in between. Try,

```
$output2 = field_view_value('node', $node, 'field_file_upload', $item[0]);
foreach ($output2 as $key) {
  if(is_object($key)) {
    echo "File Name: ".$key -> filename;
  }
}

```
> 2 votes

---
Tags: 7
---


title: Tab Tamer settings

text:
# Question
Title: Tab Tamer settings
Is there way to show tabs not only for admin?

I need tabs on user account page for authorized users. In user permissions I didn't found this option..

# Answer
If you want to build your own tabs, check out `vertical_tabs_example` module in Examples.
> 0 votes

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


# Question
Title: Show Colorbox or other Modal Window on page load
I'm working on a module that shows a modal window of some sort (I've used Colorbox so far, but I'm not attached to it) upon page load. I've gotten to the point where I need to make it display on page load and am now a little bit stumped how I'd do that -- any ideas? Using D7, btw.

Thanks!

# Answer
> 1 votes
I figured it out, it's pretty easy. See below:

```
function popupmessage_init(){
    $colorbox_js = 'jQuery(document).ready(function(){ jQuery.colorbox({html: "<h1>Your Message Here</h1>"}); });';
    drupal_add_js($colorbox_js, 'inline');
}

```

# Answer
> 0 votes
I am not quite sure what you need but i use Colorbox extensivly. I even show nodes in pop-up windows, without layout, by sending parameter in url which basically says "use other page layout for this link". It is tricky though, to break from this kind of windows.

For one time popup, i just use cookies, jquery and colorbox in combination.

I found also http://drupal.org/project/popup module very useful for some needs.

Also you have Jquery UI modal http://jqueryui.com/demos/dialog/ .

---
Tags: 7, javascript
---


# Question
Title: Using version control/deployments with Context
I've started to use Context. It actually works pretty well. I've created a context locally. It looks like, in order to get that context remotely, I have to export it and then copy and paste that into the remote server.

It's not a major pain, but we have dev, stage and live servers, plus the context isn't under version control, so any changes (or in fact the context itself) aren't stored in code.

Ideally, I'd have a situation like Views where I export the View, paste it into a file, deploy that file from version control to remote servers and the View updates on those servers.

Is this possible for context? Maybe using CTools?

The slight quirk is: I don't really like Features, and, at the moment, it seems overkill to add that as a module just for the sake of one context.

# Answer
> 0 votes
OK; so I swear I did look reasonably hard for this before I posted the question, but I have done the thing where I've genuinely found the answer 15 minutes after posting.

http://www.mcdruid.co.uk/content/default-drupal-contexts-like-default-views was the blogpost I needed - he's created an issue to get this information into the module, but it looks like it won't happened.

This seems to work really well, and I've created a separate submodule just for contexts.

---
Tags: 7, version-control
---


# Question
Title: How to migrate a real real messy Drupal setup to a fresh, new, well structured and totally new stable environment
The situation is as follows: there is a Drupal website which has loads of content (it is for a popular Iraqi newspaper), but the way the website has been built is very, very **very** messy. Content types are awkwardly structured, views are a total chaos, css is a big pile of non-structured, non modular and totally not maintainable setup of statements, there's no consistency *whatsoever*. Moreover, many things are in such a way implemented that upgrading to a newer version (Drupal 7 for instance, it is still running on 6) is gonna be a real pain in the ass. This site is doomed to be redesigned from bottom up, otherwise every change will make it more inconsistent and more difficult to maintain.

I'd really like to migrate it to OpenPublish. It's been proven to be a good environment for news-outlets, with well established worflows.

But where to start? How do I map these messy, and awkwardly structured content types to the more properly structured ones that OpenPublish uses? And then: how do I migrate the data, without losing any information? Basically they are the same types of content from an abstract perspective: news-articles, blog posts and pages, but internally there's loads of differences and difficult hurdles to overcome.

Are there any modules that are able to map different types of content types and tell which fields correspond to each other? Are there others that enable you to migrate the data without losing information and structure?

*edit: added examples below*

Two particular problems for instance:

* In the messy version, each article has an author. An author is always a regular user account. So the amount of user accounts has exploded with registrations that are actually not used. OpenPublish links user profiles (which are nodes basically) to articles. Problem: howto resolve this inconsistency when migrating data?
* Similar problem: in the messy version, each article has a slideshow field (which can contain multiple images) as part of the node article. In OpenPublish you create a reference to a separate gallery **node**, which also has more meta-information attached to it. How to split those up, without losing their relationship?

Any tips? Best practices? Thoughts?

# Answer
I think the Migrate module will help you a lot
> 1 votes

---
Tags: nodes, importing-exporting, migrations
---


title: Displaying data from a web service

text:
# Question
Title: Displaying data from a web service
I'm using Drupal 7, and I need to retrieve data from a web service. This data cannot be stored in the Drupal database due to regulations. What would be the best practice for retrieving this data: using Java, Drupal Entities, or storing in tokens?

We are currently making calls based on an ID stored in the database and displaying the data from the web service associated with that ID.

The problem with this is that it's all being done outside of Drupal, and we are unable to use Drupal to manage any of this content. So we have many modules with custom code to do everything from creating forms, pre-filling forms, tying into a users account on Drupal, etc.

We are at a point where we can totally refactor how this works.

Do you have any suggestion on how we can improve this?

# Answer
It sounds like your question cannot be answered unless it is redefined. Drupal entities, views, and all of the other niceties that you would like to do involve storing information in the database.

You might look more closely at your regulations, and see what specifically they allow you to do. For example, sqlite stores its entire database in a file. If you used an sqlite database where the database file was stored in a volitile storage device (e.g. a RAM based filesystem), would you still meet regulations?

Even if this is possible, you might have performance problems if the amount of data you need to store is large, because sqlite was designed only for small databases, and is mostly used for testing. The same idea might work for mysql or postgres, though, as ultimately even these databases store their data in files.

If your data retention regulations are strict enough, you may find that the technique you are currently employing is the best you can do.
> 2 votes

---
Tags: services
---


# Question
Title: How do I use the time function in Views Math expression?
I'm having trouble with the Global: Math Expression in a View. I have an entity type which is a student. I'd like the student grade level to change automatically from year to year, so I'm storing a graduation year and would like to display grade level by a Math expression. To do so, I need to include a current time element (month and year). I have read that time() is useable, but I can't get it to work. Perhaps I'm using the wrong format in the Expression box under Configure field? As a test, I put in just time(), but I get a zero at the output. Is time() useable within Views Math Expressions or do I have to abandon that approach and learn to use the Computed Field module? If time() is useable, would I be able to convert seconds to years by getting an integer value for time()/60/60/24/365.25 or does is there no integer conversion function here?

# Answer
If you are using the Views PHP Field, http://drupal.org/project/views\_php, you can enter in custom php field information. I would take the original date variable and subtract the date as of now to get the value you want:

```
  //Just creating a random freshman grad date

  $graduation_year = (date('Y-m-d', strtotime('+4 year')));

  $now = (date ('Y-m-d', (strtotime('now'))));

  $diff = abs($graduation_year - $now);

```

Based on the absolute difference in years you can do validation in your views field that validates this information and sets the student as a freshman, sophmore, junior or senior (assuming highschool :) ) based on the $diff value of 1,2,3,4.

That validation would look like:

```
if ($diff == 1) {
print('Senior');
}
elseif($diff == 2){
print('Junior');
}
elseif($diff == 3){
print('Sophmore');
}
elseif($diff == 4){
print('Freshman');
}

```

I didn't put exception handling but you get the idea.
> 0 votes

---
Tags: views
---


title: Repeating text field on user profile

text:
# Question
Title: Repeating text field on user profile
In the user profiles, I would like to have an education field grouping. In this grouping I'd like to have these text fields.

* Degree: BS/BA, MA/MS, PhD, Post Doc, etc
* University
* Year Graduated
* Area of Study

Now, my users will have multiple degrees and such.

Can I create a "repeating" group of these four fields from 0 to infinity?

# Answer
> 1 votes
Field collection should be a good way to do it.

# Answer
> 2 votes
If you're working in Drupal 7, check out the Field Groups Module.

> Fieldgroup will, as the name implies, group fields together. All fieldable entities will have the possibility to add groups to wrap their fields together. Fieldgroup comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers.

If you're on Drupal 6, you want the MultiGroup module, which is a part of the 3.x branch of CCK.

---
Tags: 7, entities, users
---


# Question
Title: Custom field, from custom content type, not showing up even with "entity has field" condition - Commerce/Rules
I am trying to create a custom Commerce price multiplier rule, based off of a content type field, that holds the multiplier value.

I add the "entity has field" condition, from the content type, with the data selector "commerce-line-item" ,but when I go to add the action, with "calculate a value", the custom field isn't in the data selector options. And the "entity is type" doesn't include the content types; just "node"

--- So does anyone know how I could access a field in a content type through rules to use as a multiplier? I'm a web developer, so I could write some code if there is no other way, but it would be nice not to have to, and at least be headed in the right direction to know how I need to write.

--- And if anyone knows of an easier way to price per product without a rul

Here is what is in the data selector listing (I should have one that includes the content type field "field\_deal\_price"):

site:current-user:uid
site:current-user:last-access
site:current-user:last-login
site:current-user:created
site:current-user:roles:
site:current-user:status
site:current-user:profile-main: site:current-user:profile-business: site:current-user:profile-customer: site:current-date
site:current-cart-order:order-id
site:current-cart-order:created Date created
site:current-cart-order:changed Date changed
site:current-cart-order:uid site:current-cart-order:owner:
site:current-cart-order:commerce-line-items:
site:current-cart-order:commerce-order-total:
commerce-line-item:line-item-id Line item ID
commerce-line-item:order-id
commerce-line-item:order:order-id
commerce-line-item:order:created
commerce-line-item:order:changed
commerce-line-item:order:uid
commerce-line-item:order:owner: commerce-line-item:order:commerce-line-items:
commerce-line-item:order:commerce-order-total:
commerce-line-item:quantity commerce-line-item:created
commerce-line-item:changed commerce-line-item:commerce-unit-price:amount
commerce-line-item:commerce-total:amount
commerce-line-item-unchanged:line-item-id commerce-line-item-unchanged:order-id commerce-line-item-unchanged:order:order-id commerce-line-item-unchanged:order:created commerce-line-item-unchanged:order:changed commerce-line-item-unchanged:order:uid
commerce-line-item-unchanged:order:owner:
commerce-line-item-unchanged:order:commerce-line-items: commerce-line-item-unchanged:order:commerce-order-total:
commerce-line-item-unchanged:quantity
commerce-line-item-unchanged:created
commerce-line-item-unchanged:changed
commerce-line-item-unchanged:commerce-unit-price:amount commerce-line-item-unchanged:commerce-total:amount

# Answer
> 0 votes
I've noticed that if I add two "has field" entries back to back then do a data comparison, sometimes only the second "has field" is available in the data comparison. What I do is add the first "has field" and then do the data comparison, then add the second has field. I'm not sure if this is related, since you are adding actions, but I hope it helps.

---
Tags: nodes, commerce, rules
---


# Question
Title: Write errors to the log unless the user is an administrator
Under error reporting it is possible (and actually recommended for live sites) to write errors to the log, but not to the screen as well. I don't want to show errors to my users, but at the same time I never check my logs. Is there a way of only showing these errors on screen to administrator users?

# Answer
> 0 votes
Set error messages to none and install this Logging and alerts module.

> Currently, the following modules are included:
>
> Email logging and alerts Allows routing of watchdog messages to various email addresses, based on their severity levels. For example, emergency and critical messages need to go to a pager or mobile phone email address, while debug messages go no where.
>
> Web server logging Allows routing of watchdog messages to the web server's error log. Note that what is in your PHP configuration for error\_log defines where the message will go. For example, on a UNIX like system, this will be syslog(3), which may end up in /var/log/apache2/error.log, and on Windows, it would be the event log.
>
> You define which severity levels are to go to the error log. For example, you can only specify that emergency and critical messages need to go to the error log, and use other modules for the other levels.
>
> Watchdog triggers Provides a trigger for watchdog events. You may now trigger actions when an event occurs.
>
> Watchdog rules Provides rules integration for watchdog events. You may now trigger additional ruleset responses when an event occurs.

# Answer
> 0 votes
Using the devel module you can print to the screen errors that you are seeing, but that requires custom work to catch specific exceptions that you expecting to see.

---
Tags: 7
---


# Question
Title: How do I remove the authoring information?
I want to publish some static pages, but when I try they always show the publishing date and author, which makes them look more like a blogs.

I have looked at a way to disable the feature "authoring information" for this page, but the best I can find is how to make it anon, which is not what I want either.

The content types I have on the site are:

* Article
* Basic page
* Blog entry
* Book page
* Forum topic
* Poll

The theme I am using is Bartik 7.15, if that makes any difference.

# Answer
You can disable it for each content type, going on `admin/structure/types/manage/<content type>` (e.g. admin/structure/types/manage/article for the Article content type).

What you are looking for is in the "Display settings" tab visible at the bottom of the settings page.
> 7 votes

---
Tags: nodes
---


# Question
Title: How can I create a Install New Module-style "add button"?
In the Modules page, there is a button that looks like this:

Is this easy to reproduce? If so, how is it done?

# Answer
Figured it out. You create a sub-item in your `hook_menu()`, then set its type to `MENU_LOCAL_ACTION`.

```
  $items['menu/url'] = array(
    // --snip--
    'type' => MENU_LOCAL_ACTION,
    // --snip--
  );

```
> 0 votes

---
Tags: forms
---


title: How to use 'if Token is'

text:
# Question
Title: How to use 'if Token is'
I would like to use an if statement depending on my token something like

```
<?php if ([simplenews-category:name] == 'fishing'): ?>
 Go fishing   <?php else: ?>
 Go sailing    <?php endif ?>

```

Above code doesn't work, can somebody please give me advice?

I'm using Drupal 7

# Answer
> 2 votes
You need to replace the token first with it's actual value. You can do this with token\_replace();

I haven't used simplenews yet, but you will need to do something along the lines of:

```
<?php if (token_replace('[simplenews-category:name]', array('node' => $node)) == 'fishing'): ?>
 Go fishing   <?php else: ?>
 Go sailing    <?php endif ?>

```

Once `[simplenews-category:name]` has been converted, string comparisons should work as intended.

As a note, you will likely need something other than `array('node' => $node)` to get this to function.

---
Tags: tokens
---


# Question
Title: How to set the language to Swedish when users visit example.se and to French when visiting example.fr?
I have a Drupal 7 website in 18 languages. The main URL is example.com and 18 other international domains are domain aliases of the main URL (example.de, example.fr, example.se, ...).

The Language detection and selection feature in Configuration currently selects the language based on the path of the URL (example.com/de, example.com/se, ...) but not based on the actual URL extention (example.de, example.se, ...).

**How can I set the language to Swedish when users visit example.se and to French when visiting example.fr?**

Thanks in advance!

Kind regards, Jan

# Answer
On admin/config/regional/language/configure/url change the **Part of the URL that determines language** to *Domain*.

Then set up domains to all languagues: admin/config/regional/language/edit/LANGCODE
> 1 votes

---
Tags: i18n-l10n, uri
---


title: Exporting menu structure using services

text:
# Question
Title: Exporting menu structure using services
Is it possible to to export the menu structure of my drupal site using the services module? This way the website structure can be generated on the drupal website -\> make it available for webservices -\> acces by mobile in order to build the same structure dynamically in the mobile app.

# Answer
> 1 votes
The Menu API is fairly extensive. It is likely there is already a function available to return what you need.

For example, you can return an entire menu tree using the menu\_tree\_all\_data().

```
$navigation_tree = menu_tree_all_data('navigation');

```

You could also return everything known to the menu router with menu\_get\_router();

```
$everything = menu_get_router();

```

---
Tags: routes, services
---


title: Colorbox Node and template files?

text:
# Question
Title: Colorbox Node and template files?
I have a node being pulled into a modal with overlay using Colorbox Node but it's pulling in more markup and pieces of the page than I really want.

After trying to pick through some user threads on drupal.org, the only solutions I saw suggested were ones that only work for Drupal 6 and/or break when page caching is enabled.

Is there a robust way to template the output of nodes in modals in Drupal 7?

# Answer
Colorbox Node creates a new display mode for each content type - that's where you can change the fields shown.

Structure -\> Content Types -\> 'manage display' on the content typ ein question - in the top right, select the 'Colorbox' display mode and adjust what shows and doesn't show as needed.
> 1 votes

---
Tags: nodes, theming, javascript
---


# Question
Title: how to filter taxonomy vacobulary using views contextual filters
I have taxonomy vocabulary

```
parent term1 -
  child term1,
  child term2,
  child term3

parent term2 -
 child term4,
 child term5,
 child term6

```

I will be passing view arguments as parent term1. So the output should be (child term1,child term2,child term3).

Please let me know how to achieve this using views contextual filters

Thank you very much for your help!

# Answer
> 0 votes
You can refer Hierarchical Select module, which allows you to create taxonomy structure like your requirement and also allows to filter accordingly your requirements in view.

---
Tags: views
---


# Question
Title: Invalid form POST data in AJAX Login form
I am working on a drupal 7 website using an AJAX login form. I have a problem, the form work fine once and then doesn't work when I logout and try again. I need to empty cache and try again to have it work again. I think this is something linked to the form\_id not found in cache but I don't know how to fix it.

Any solution?

Thanks

# Answer
**short:** it should works if you disable "cache pages for anonymous users"

**long:** When Drupal's core caching feature is switched on, forms are delivered to anonymous visitors from cache which results in the situation where one and the same form gets delivered more than once with the same form\_build\_id.

As soon as one of the anonymous users submits such a form, the record gets removed from cache.

The next visitor who is submitting the same form will potentially run into trouble because of the missing form record in cache.

The regular Drupal FAPI seems to be OK with that but if the form gets submitted via Ajax, the submission gets rejected, a watchdog entry gets issued ('Invalid form POST data') and drupal\_exit() gets called.

The result of that is that the user would have to reload the page before being able to submit the form. This can be annoying i.e. if the form being used is the user login form. It seems as if just nothing is happening.

This issue arrises always when page caching for anonymous users and form submission via Drupal's own ajax mechanism get used in combination.

**source:** http://drupal.org/node/1694574
> 10 votes

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


title: Set total cart amout

text:
# Question
Title: Set total cart amout
If the user didn't buy anything ever, at the first time he gets a 20% tax of total shopping cart amount. I'm newbie in Drupal and can't understand how to implement it. Say I'll do checking for first order (I imagine how), but I can't find how to change total cart amount without changing every item price.

I hope you can help me :)

# Answer
> 0 votes
The trick to this is to create a discount. Force users to register before purchasing an item and than check the order history of a user at checkout. If the user has no order history at checkout than give him a 20% discount, if not than charge retail price.

This can be achieved with

1. http://drupal.org/project/commerce\_checkout\_login
2. And either a custom module or rules

---
Tags: commerce
---


# Question
Title: Redirect to the registration page of the main domain
I have a master site at http://www.abc.com and a subsite at http://www.abc.com/xyz.

I want to redirect a user to the registration page of the main domain, whenever a user tries to register on the sub-domain. As they are different Drupal setups, how do I redirect a user?

# Answer
Follow below steps to solve your issue.

1. Install rules module in subsite.
2. Create a rule with condition as page being viewed is user/register
3. Add an action redirect to URL with url as main site user/register path

Other way to do is using custom module in sub site

Use hook\_init in custom module

```
   <?php
      function yourmodule_init() {
         if (arg(0) == "user" && arg(1) == "register") {
           drupal_goto("http://www.abc.com/user/register");
         }
      }
   ?>

```
> 4 votes

# Answer
If you are using drupal 6 ,you can use Path redirect ,install and enable it in your subdomain and `add redirect` from `http://www.abc.com/xyz/user/register/` to `http://www.abc.com/user/register`.

and in drupal 7 you can use Global Redirect or Redirect module ,after install and enable one of them, just need set a redirection from `http://www.abc.com/xyz/user/register/` to `http://www.abc.com/user/register`.
> 2 votes

# Answer
Try the htaccess.

```
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://example.com/

```

htaccess
> 0 votes

---
Tags: redirection
---


title: 'Change email' form on custom page

text:
# Question
Title: 'Change email' form on custom page
I would basically like to display the form/field that is used for changing the user's email address on a custom page with my own layout and things.

Ideally, I would like to make it so that if Javascript is enabled, the email address would appear as text with a 'Change' link next to it. The link would make a text box appear in place of text so that the user can change the address. Obviously, all this would happen without refreshing the page, and if Javascript is not enabled the email address should appear in the text box immediately like normal. If anybody can provide me with at least some, or all of the code that I need, that'd be so awesome.

Thanks in advance

# Answer
> 4 votes
If you've enabled the PHP Input Filter, you could add the following into your node/page. The javascipt won't execute if disabled, leaving only the input field :)

```
<?php
    drupal_add_js('misc/jquery.js', 'core', 'header');
?>

<script type="text/javascript">
(function($){
    $(document).ready(function(){
        var email = $('input#edit-email');
        if (!email.hasClass('error')) {
            var change = email.val() +' <a href="#">Change</a> ';
            $('input#edit-email').hide().after('<div id="edit-email-container">' + change +'</div>');

            $('div#edit-email-container a').bind('click', function(e, t){
                $(this).parent().hide().parent().find('input').show();
                e.preventDefault();
                return false;
            });
        }
    });
})(jQuery);
</script>

<?php
function userEmail_form() {
    global $user;

    $form['email'] = array(
        '#type' => 'textfield',
        '#default_value' => $user->mail
    );

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

    return $form;
}

function userEmail_form_validate(&$form, $form_state) {
    if (!valid_email_address($form_state['values']['email'])) form_set_error('email', 'Invalid Email Address');
}

function userEmail_form_submit(&$form, $form_state) {
    global $user;
    db_query('UPDATE {users} SET `mail` = "%s" WHERE `uid` = %d', $form_state['values']['email'], $user->uid);
    drupal_set_message('Email updated');
}

echo drupal_get_form('userEmail_form');
?>

```

---
Tags: 7, forms, javascript, emails
---


title: Add next/prev link to image in drupal 7

text:
# Question
Title: Add next/prev link to image in drupal 7
I have a taxonomy with lots of nodes in it. Each node contains a large image. I want that image to be linked to the next node within the taxnomy. How can I do this in Drupal 7?

# Answer
If you are interested to use a more flexible module, Custom pagers will do the job. Overlay the "next" link above the image using CSS absolute positioning.
> 2 votes

# Answer
Please see the solution that should work !

* Hook into node view using hook\_node\_view by writing a custom module.
* Change the image field to a image with link using below technique

1. Get nid of current node using $node-\>nid;
    2. Get taxonomy term id associated with node object using this technique.
    3. Get all other nodes attached with same taxonomy term that you got in step 2 using taxonomy\_select\_nodes
    4. From the list of node id's that you got in step 3 check the node id which is just greater than $node-\>nid and store it in variable $next\_nid
    5. Form a link using l function that should be markup for image field.

$overrided\_image\_field\_value = l($image, 'node/' . $next\_nid, array('html' =\> TRUE));

That should do the work !
> 2 votes

# Answer
I would use the Views Slideshow module to have a view block with all the nodes belonging to the taxonomy term that is being viewed at the time. Aspects such as adding next/previous links are 'easy' using views slideshow. For node that contain large images this module should be more than apt for the job.The link should get you started.
> -1 votes

---
Tags: nodes, taxonomy-terms, paging
---


# Question
Title: Cron has been running for more than an hour and is most likely stuck, problem is persisting
I am getting this error each time I run the cron. When I saw the status report I found last time cron was run was about 8 weeks ago. It is same for all the 3 websties that I host with the same server, shored hosting. when I tried to run cron manually, it ended with a message cron failed. Somewhere I read it possible reason could be /tmp folder, so I created a tmp folder in installation directory for all the three websites. It did work for one of the websites, I am able to run cron manually in that website. But for other two websites it was the same error. A discussion in drupal.org told it could be problem with cron\_semaphore variable. I tried deleting cron\_semaphore variable using phpmyadmin and cleared the cache, but still it is same problem. Sometimes when I try it manually , it gives error message that MYSQL has gone away from query while inserting data into watchdog. Is it because of the MySQL or file permissions problem ? Can it be cured if I update core to latest version? Or should I contact the hosting provider, is there is a problem with them?

# Answer
> 3 votes
There are too many factors that can stop the cron from being executed.

To see where exactly it breaks, open `includes/module.inc` and at the line 496 (function `module_invoke_all()`) add this:

```
foreach (module_implements($hook) as $module) {
  $function = $module .'_'. $hook;

  // This is the line you should add:
  if ($hook == 'cron') watchdog('cron debug', "Cron is processing module: $module");

```

Then run the cron from admin. The last module to be called is the one which breaks. Look further into the implementation of `hook_cron()` of that module and debug further.

This is inspired by this comment.

See this discussion.

---
Tags: 6, cron
---


# Question
Title: How to theme a node form from my custom module?
I have a node type with machine name "resource", and I'm trying to theme it in my module "modulename".

I've tried doing this:

```
function modulename_theme() {
  return array(
    'resource_node_form' => array(
      'render element' => 'form',
      // 'template' => 'resource-node-form',
      // 'path' => drupal_get_path('module', 'modulename'),
    ),
  );
}

//I've tried both functions, getting nothing

function theme_resource_node_form($variables) {
  dsm($variables);
  return 'Testing';
}

function modulename_resource_node_form($variables) {
  dsm($variables);
  return 'Testing';
}

```

I've cleared cache, nothing happens. I've also tried with templating approach:

```
function modulename_theme() {
  return array(
    'resource_node_form' => array(
      //'render element' => 'form',
       'template' => 'resource-node-form',
       'path' => drupal_get_path('module', 'modulename'),
    ),
  );
}

```

And placing resource-node-form.tpl.php in modulename module folder. Cleared cache, nothing happens.

Sure I'm doing something wrong, but I can't figure it out. I've used templates for existing forms from a custom theme, but I'd like to do it this way, this time. Better approach for this project I'm working on, I think.

Thanks for your answers, ask me if you need more info!

# Answer
> 2 votes
Use this:

```
/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {
    // Expected format: NODE_TYPE_MACHINE_NAME_node_form
    case 'resource_node_form':
      // Requires devel module to be installed.
      // See all available elements displayed using krumo.
      $dpm($form);
      break;
  }

}

```

**Update:**

Depending on the complexity of your layout, check Display Suite and Field Group modules, as their functionality might be what you need.

You can also follow up this article if you want to do this from a tpl file. The approach is similar to what you were trying to do.

# Answer
> 1 votes
Can you please try as following-

Go to your theme folder (used by your site) and create one new tpl file named as node-resource.tpl.php, then write your theming inside it.

May be it will help you.

For theming create node you can do as following-

node-resource-add.tpl.php

---
Tags: 7, forms, theming
---


title: Print Term ID in block on Term page?

text:
# Question
Title: Print Term ID in block on Term page?
I have a block that displays on term pages. I need to print the term ID in this block.

I can see the term in the url (if I turn off pathauto) is something like this: mysite.com/bslb22/taxonomy/term/3

So is there some php that can get the ID from the url? Thanks

# Answer
Use this:

```
// Make sure we are on the term page
if (arg(0) == 'taxonomy' && arg(1) == 'term' && arg(2)) {
  print arg(2);
}

```
> 2 votes

# Answer
There is two ways how to get that. You can use menu\_get\_object or simpler arg.
> 1 votes

---
Tags: 7
---


# Question
Title: User role referencing when they might not exist
I'm making a Drupal 7 site that has an event content type. There are two user roles: venues and speakers, and both can create events. I need a way for both to be referenced in the node (with auto-complete), but keeping in mind that they won't necessarily have an account on my site.

Example 1: The venue "Big Conference Center" creates a new event called "Cool Conference 2012". Their speaker is John Doe, so they enter his name in a text box, it finds him using user role Speaker auto-complete, and he is referenced. If you go to John's user page now, it lists Cool Conference 2012 as an event he is speaking at.

Example 2: The same venue creates another event. This time the speaker is Jane Anon, who doesn't have an account on the site. The auto-complete returned nothing, so Jane Anon is stored in plain text in that field. When Jane Anon joins the site two weeks later, she is presented with a list of events that match her name, and she can select which ones are hers. Then, the plain text changes to a reference.

Examples 1 and 2 should work the same if it's the speaker who is creating the events and the venue who is referenced.

# Answer
Lets say there is a module in drupal which just does what you are asking for, how would you like it? :P

I found this module recently. TextNodeReference

What this module does is

1. It creates a new widget for the references. Once the widget is enabled,
2. If the referencing node exists then it will store a reference to that node in the table.
3. If the node doesn't exist already on the system, then it will store it as text. But when the node with the same title is created, it will auto-reference it to the node.

Caveat : When that node doesn't exist, make sure that you are entering that right title(for the author or venue), and then use the same title when creating the actual node for that entry(author or venue).

You can thank me later, but do thank Boobaa who wrote this module.
> 1 votes

---
Tags: 7, users, ajax
---


# Question
Title: Block visitors based on geographic location conditionally in .htaccess on multi-site install
I have a Drupal 6 multi-site install that runs numerous different websites for a single instance of Drupal. These web sites attract worldwide traffic which is what my client wants, with one exception.

One of the sites attracts lots of visitors from Italy, which my client doesn't want as it creates problems for them. As I result of this I would like to block visitors from Italy visiting the site by blocking them based on IP addresses (**note that I already have the IP addresses and the method of blocking the visitors**). The way I want to block the visitors is in the `.htaccess` file like so:

```
<Limit GET HEAD POST>
order deny,allow
deny from 2.16.70.0/23
deny from 2.19.16.0/20
etc...
allow from all
</Limit>

```

My issue is that if I put that code into my `.htaccess` file, it will block visitors from Italy visiting each of the websites in the multi-site install, which I don't want. I simply want to block them on a particular website, perhaps based on the URL or something. Can anyone point me in the right direction?

# Answer
You can add this restriction directly in the vhost of your client instead of .htaccess. At that level you should hace a vhost per site.
> 2 votes

---
Tags: 6, multi-sites, .htaccess
---


# Question
Title: Required Fields with unlimited field collection items
I have a D7 instance with a field collection called field\_professions and associated to a content type with "unlimited" amounts of fields. Within this field collection I have two fields that are required (field\_professional\_user and field\_professions). I also have an unrequired field called field\_serving\_since. For the sake of testing I made the entire field collection required.

Now, when I have an item entered, I can enter a 2nd, 3rd etc. item, but whether I fill out all 3 fields, 1 of the required fields, or the unrequired and none of the required fields, it never validates that the fields are required. I can obviously see the red asterisk, but there is no validation.

# Answer
> 1 votes
I faced This bug in field collection module ( really I didn't find out why they do this :( ). There is no way to achieve this ( have unlimited and required fields in field collection ). You just achieve it trickly . (set it unlimited and none-required) . use jquery for validate( checking filled ) fields.

This problem almost accures when you don't want set default value for field .(if you set default by any edit add a waist item ).

---
Tags: entities
---


# Question
Title: Is there a way to log changes to module settings for better long-term administration and debugging?
We run quite a complicated Drupal 6 site with a lot of custom modules which was already migrated from D5. There are a few site administrators and we have had situations where a change in the settings of one module (usually something conflicting with Boost) has caused a problem with the site that is only detected later. We have no way to quickly tell which settings have been changed recently and what their previous values were.

Is there an additional module that hooks into to all variable\_set() calls (for example) and logs the old and new values so that we can have an admin view listing all changes over time and which user made the change? It would be great to have an option to add a note to each item to explain why the change was made?

We try and share notes in our wiki on such changes but I think it would be much better if such data was available from inside Drupal itself.

# Answer
Blame module sounds like it might fit your needs:

> The Blame module is an audit tool that allows the site administrator (or those with appropriate permissions) to see changes that have been made to any form on their Drupal website. The purpose of this module is to provide the ability to quickly identify which user made which changes to which form at a specific time. This includes node forms, contact forms, administrative settings, webforms, etc.

In the past when I've needed to find configuration changes I've grepped access logs for posts to specific forms.
> 1 votes

# Answer
Here is our workflow.

First of all you code base should use a versioning system as Git or Subversion, doesn't matter which you like or want use, but the main point its to use a versioning system.

Then you should give a look to Features module and all his modules relatives. This will allow you to create a set of module that include standard configuration and etc.

So, mostly popular modules are using either variables or ctools to manage their configuration, for those who sue CTools, Featues will help you export their configuration, for the others you've Strongarm.

I think just with this, you will covers at least 80% of your configuration, for the rest your should either move it to features or use hook\_update\_N with a module.

Here what is important its that all your configuration must be inside files and committed to the versioning system.

Like that, you will which configuration has been changed and see the historic through the versioning system.

I think the most important part its to move the already existing into Features and force people to use Features when they are doing changes in the configuration.
> 1 votes

---
Tags: debugging
---


# Question
Title: How do I upload an image to the public:// directory?
Is it possible to upload the picture and set it as user picture?

User picture can be set via `$user->picture = $file->fid; user_save($user);`but how do I upload the file from a URL to the `public://` directory?

# Answer
> 1 votes
If you want to create the code for saving the image yourself, you could do

```
$response = drupal_http_request($url_image);

if ($response->code == 200){
  $file = file_save_data($response->data, 'public://' . 'foldername/' . $filename);
}

```

And in $file-\>fid you'll find the fid you need.

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


# Question
Title: In Drupal 7 how can I programmatically create a menu link to a view?
I am trying to programmatically create a menu link to a view. The view already has a menu item but I basically need a shortcut to it in another menu location in a separate module.

# Answer
> 3 votes
You can do it using hook\_menu and views\_embed\_view in a custom module.

```
function yourmodule_menu() {
    $items = array();
    $items['duplicate-view-path'] = array(
        'title' => 'View Title',
        'page callback' => 'custom_render_view',
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
    );
    return $items;
}

function custom_render_view() {
  $output = views_embed_view($view_name, $display_id = 'default');
  return $output;
}

```

# Answer
> 1 votes
Instead of using code, I will simply create an alias. You can do it if you've Path module activate and if you go to `admin/config/search/path` (Drupal 7) you will be able to create an alias that then you can use in your another menu.

---
Tags: views, forms
---


# Question
Title: CSS/jQuery not showing in Drupal 7 when upgraded from 6
I have just recently upgraded a large site from Drupal 6 to Drupal 7. When I load up the site it doesn't load any theme at all. Even when I check the admin panel under appearance it shows the enabled themes, but nothing shows up at all, style wise. When I view the source, it isn't pulling in any CSS or jQuery files at all. Does anyone know how I would go about fixing this?

Also, I am receiving this error '***The specified file temporary://fileoR4rjt could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.***'

I thought it may have something to do with the tmp folder/file-system but I can't seem to get anything to work.

Any help would be great. Cheers.

# Answer
Theming system as a little bit changed on Drupal 7. You should give a look at that page for more informations.

For your file-system problem, you should check the configuration of File system and see where is trying to put the files from the temporary folder.

By default Drupal tries to put that into sites/default/files, so check if the rights of this folder as write/execute/read for the owner and the groupe and if the group is at least the web server.

Also, maybe this problem with file-system can likely fixe your CSS/jQuery problem. So try to fix it before read the documentation from the new theming changes on Drupal 7.
> 2 votes

---
Tags: javascript, theming, upgrading
---


# Question
Title: Display a particular field in a view by a comma separated values using custom code
For a partular view say "abc" I have created a view.

Now I want a particular field in that view as comma separated values.

How can I achieve this. Can I do this with custom coding only for that particular field.

I am learning drupal custom coding. so If this is possible through custom coding Please give me sample code.

Thanks in advance

# Answer
You could create a template for the field you want to modify.

Click on link Advanced -\> Themes -\> Information, while editing the view, and select the right template and file name. Then, in the template you can modify the output of the field.
> 0 votes

---
Tags: 7, views
---


title: How do I invoke web services?

text:
# Question
Title: How do I invoke web services?
I am working on a site, and I want to integrate my site with an external site; for that, I need to use web services to get data from the external server. I don't know the technology used by the server.

I have to work as client. Can any one please tell me hoe to call web services from my site? Please write any code if it is required. Will `drupal_http_request()` help me?

I am using Drupal 6.

# Answer
> 1 votes
You should have a look at the Services module. You can use XMLRPC and/or REST server (and many more) to communicate with your remote server. Link to the documentation.

> A standardized solution of integrating external applications with Drupal. Service callbacks may be used with multiple interfaces like REST, XMLRPC, JSON, JSON-RPC, SOAP, AMF, etc. This allows a Drupal site to provide web services via multiple interfaces while using the same callback code.

# Answer
> 0 votes
The Alternate solution is Views . Install Views module and Json document Views module. With this you can get data from your site in many ways. Have a try

---
Tags: services
---


title: Boost not caching subdomains

text:
# Question
Title: Boost not caching subdomains
I have a website with subdomains set up, the naked domain without any subdomain gets cached by boost and there is the message by boost in the footer. But any subdomain does not get cached. We are using the sites module http://drupal.org/project/sites, to split the subdomains into different drupal sites.

We have this error on the status report page - Boost crawler did not get a 200 response; 302 returned instead.

my boost settings

```
  ### BOOST START ###
  AddDefaultCharset utf-8
  FileETag None
  <FilesMatch "(\.html)$">
    <IfModule mod_headers.c>
      Header set Expires "Sun, 19 Nov 1978 05:00:00 GMT"
      Header set Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
    </IfModule>
  </FilesMatch>
  <IfModule mod_mime.c>
    AddCharset utf-8 .html
    AddCharset utf-8 .css
    AddCharset utf-8 .js
  </IfModule>
  <FilesMatch "(\.html)$">
    ForceType text/html
  </FilesMatch>
  <FilesMatch "(\.js)$">
    ForceType text/javascript
  </FilesMatch>
  <FilesMatch "(\.css)$">
    ForceType text/css
  </FilesMatch>

  # NORMAL - Cached css & js files
  RewriteCond %{DOCUMENT_ROOT}/cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.css -s
  RewriteRule .* cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.css [L,QSA,T=text/css]
  RewriteCond %{DOCUMENT_ROOT}/cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.js -s
  RewriteRule .* cache/perm/%{SERVER_NAME}%{REQUEST_URI}_\.js [L,QSA,T=text/javascript]

  # Caching for anonymous users
  # Skip boost IF not get request OR uri has wrong dir OR cookie is set OR request came from this server OR https request
  RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [OR]
  RewriteCond %{REQUEST_URI} (^/(admin|cache|misc|modules|sites|system|openid|themes|node/add))|(/(comment/reply|edit|user|user/(login|password|register))$) [OR]
  RewriteCond %{HTTP_COOKIE} DRUPAL_UID [OR]
  RewriteCond %{HTTP:Pragma} no-cache [OR]
  RewriteCond %{HTTP:Cache-Control} no-cache [OR]
  RewriteCond %{HTTPS} on
  RewriteRule .* - [S=1]

  # NORMAL
  RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html -s
  RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]

  ### BOOST END ###

```

# Answer
> 1 votes
I applied this patch and now it works

http://drupal.org/node/1508994

---
Tags: caching
---


title: How to use security review module

text:
# Question
Title: How to use security review module
I have installed the security review module and enabled it but where to see the security flaws? There is not next page that I am being redirected to, tried google but not much help.

# Answer
> 2 votes
IF it is Drupal 7

Navigate to Administer \>\> Reports \>\> Security Review to run the checklist.

# Answer
> 1 votes
The project comes with a README.txt file that is full of good advice. Most modules come with those, actually. I definitely suggest reading them.

> -- USAGE --
>
> Navigate to Administer \>\> Reports \>\> Security Review to run the checklist.
>
> If a check is enabled it will be run. You can enable or skip a check on this page only after it has been run. Clicking on the 'Help' link beside each check will provide details on why the check exists and what was found on the last run.

The same menu is used for both the Drupal 6, and Drupal 7 versions of the module.

---
Tags: security
---


# Question
Title: How can publishers create hierarchical taxonomy terms during node creation?
I have a chicken and egg problem in terms of allowing users to classify and populate their own sections of the site.

I need users to be able to hierarchically classify their content on the fly. I think this means I can provide them with a term reference field. However, the term reference field only gives a predefined selection. The fully populated taxonomy would need to exist before hand.

I'd like to use taxonomy based URLs to make everything seamless: i.e. /section/subsection/node. I just don't know how to get lay users to easily populate these taxonomies on the fly.

Is there a widget which would allow users to add terms to a term reference field during node creation? AFAIK, only tags can be created on the fly, which doesn't help my URL system.

# Answer
The Hierachical Select Module allows you to enable on the fly term addition into an ordered taxonomy.

It's unfortunately under minimal developent, but is available for D7 and gets the job done. If there are better options, pleaese let me know, but I think this should handle the above use case for now.
> 1 votes

---
Tags: taxonomy-terms, uri, subsites
---


# Question
Title: Default image is not displayed while creating a node
I have created a content type and added a *Preview Image* field. Its type is *file* and its widget type is *image*. For *Default Image*, I have uploaded an image that should be displayed at the time of creating one new node.

My problem is that it is not displaying on the node creation form.

# Answer
> 0 votes
Here is the screen shot for field type. The drupal version i am using is Drupal 7 .

# Answer
> 0 votes
You can add a picture to the content creation page by adding HTML or to the HELP TEXT of your image field. Go to /admin/structure/types/manage/product-node/fields, click "edit" on the right of the image field, put your HTML in help text. Another, but rather unholy way is to add the HTML code using jQuery .append(). I hope this works for you.

---
Tags: nodes, 6, media
---


# Question
Title: Views: changing the language for taxonomy terms
Is there a way to display taxonomy terms in a language given by a Views argument, i.e. to override the user's language preference? The field formatter "Plain text (localized)" doesn't do the trick.

Example:

**Tab one: English**

* Africa
    + Story 1
    + Story 2
* Middle East
* Europe

**Tab two: Français**

* Afrique
+ Histoire 1
* Moyen-Orient
+ Histoire 2
* Europe

The stories are a single content type, but completely different pieces of content (not translations). I'm using quicktabs to render this.

Edit: the taxonomy terms are already translated via the i18n module, the question is about getting Views to display the translation I want.

# Answer
> 3 votes
By default views doesn't allow to filter the taxonomy terms by the language, only with nodes.

But, you can use the Internationalization Views:

http://drupal.org/project/i18nviews

After you enable the module go to relationships and add "Content: Taxonomy terms on node" Then you can find " Taxonomy term: Language " under filters. This should do the trick.

Good luck.

# Answer
> 0 votes
You can translate taxonomy terms with the Internationalization module.

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


# Question
Title: How to give different permissions for different domains
I am using the domain access module in Drupal 7.

I want one domain to be accessible by anonymous users and the other domain to be accessible only by authenticated users.

How can I give the "view published content" permission to anonymous users for only one domain.

# Answer
> 1 votes
Is seems that Domain Strict, a Domain Access submodule, may help you, as stated in this issue:

> DA is a node access module (which is designed to enhance what 'access content' means), and you should be able to do this now by using Domain Strict and configuring user behaviors.
>
> Domain Strict forces people to be members of a domain in order to view its content. You would enable the module, then you will note:
>
> 1) Anonymous users cannot access any content. This is because they cannot be assigned to a domain (since thiey have no account).
>
> However, you can use the User Defaults setting page to assign anonymous users to the primary domain.
>
> 2) Use the same User Defaults setting to assign all 'authenticated' users to the domain(s) you prefer.
>
> Under this setup, anonymous users would still have the 'access content' permission, but can only see nodes posted to the primary domain.
>
> See section 4.10 of README.txt and the README for Domain Strict.

Check also README.txt from Domain Strict.

> \[Domain Strict\] it changes the default Domain Access behavior. This module makes the grants given to a user specific to the domains that the user is registered to see.

You'll have to deal with User Defaults setting to set permissions for anonynmous users since initially they don't have domain assigned.

---
Tags: domain-access, users
---


title: Move user profiles under a menu item

text:
# Question
Title: Move user profiles under a menu item
In Drupal 7, currently when I go to a user profile, the breadcrumbs go as follows: "Home \> username."
I have a People section as part of my main navigation, so I would like the breadcrumbs to behave more like: "Home \> People \> username."

How can this be accomplished?

# Answer
There are two possibilities: You can implement a hook in a module, or implement a theme function in the theme you are currently using.

### Module

In Drupal 7, you can implement hook\_menu\_breadcrumb\_alter(). The hook implementation receives the current breadcrumb array by reference, and the menu item for the currently visualized page. The example provided in the documentation page is the following one:

```
function hook_menu_breadcrumb_alter(&$active_trail, $item) {
  // Always display a link to the current page by duplicating the last link in
  // the active trail. This means that menu_get_active_breadcrumb() will remove
  // the last link (for the current page), but since it is added once more here,
  // it will appear.
  if (!drupal_is_front_page()) {
    $end = end($active_trail);
    if ($item['href'] == $end['href']) {
      $active_trail[] = $end;
    }
  }
}

```

An example of implementation of such hook could be the following one ("mymodule" needs to be replaced with the short name of the module that contains the hook):

```
function mymodule_menu_breadcrumb_alter(&$active_trail, $item) {
  if (substr($item['href'], 0, 4) == 'user') {
    // Add a trail item before the one linking to the user profile page.
  }
}

```

For a method that can be used on Drupal 6 too (when you want to develop code that is for both Drupal 6 and Drupal 7, and you don't want to write code for each Drupal version), you can use drupal\_set\_breadcrumb() to set the breadcrumb for the user profile pages.

An example of how the function can be called is the following Drupal function:

```
function blog_view($node, $view_mode) {
  if ($view_mode == 'full' && node_is_page($node)) {
    // Breadcrumb navigation.  l() escapes title, so we should not escape !name.
    drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Blogs'), 'blog'), l(t("!name's blog", array('!name' => format_username($node))), 'blog/' . $node->uid)));
  }
  return $node;
}

```

You could alter the menu callback for the menu items associated with the user profiles, and use a menu callback that first sets the breadcrumb, and then calls the original menu callback. The hook to implement in this case is hook\_menu\_alter().

### Theme

As far as I recall, a theme can also implement some alter hooks as a module does; alternatively, a theme just overrides a theme function ("mytheme" needs to be replaced with the short name of the theme).

```
function mytheme_breadcrumb($variables) {
    $breadcrumb = $variables['breadcrumb'];

    // Modify the breadcrumb.
}

```

The variable `$breadcrumb` is an array containing the HTML for the single parts of the breadcrumb. The default implementation of the theme function is the following one:

```
function theme_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];

  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

    $output .= '<div class="breadcrumb">' . implode(' » ', $breadcrumb) . '</div>';
    return $output;
  }
}

```

Between the two possible implementations, I would rather use a module, as it doesn't depend from the currently set theme; the theme can be changed, and the code would still change the breadcrumb. Generally, the code of a theme should alter the way elements are rendered, not to change the breadcrumb to alter the links it contains.
> 6 votes

# Answer
Check out the Menu position module.

> Often times site builders want certain types of content to appear in a specific position in the navigational menu. The simplest solution, adding all of that content individually to the menu system, has performance and usability issues. (Imagine hundreds of menu items added to one spot in the menu.)
>
> This module allows for the creation of rules that will dynamically add the current page into the menu system at the requested spots.
>
> This includes affecting:
>
> * The main links of the theme
> * The secondary links of the theme
> * The breadcrumb trail
> * Menu blocks provided by core's Menu module
> * Menu blocks provided by the Menu Block module
> 1 votes

# Answer
I recently solved this problem in 10 minutes of sitebuilding with the Menu Position module.

One thing to keep in mind is that by default it doesn't allow positioning of user pages, just content types. However, you can "menu position" user pages by their path ("users/\*").

This solves the breadcrumb problem and related contextual problems.
> 1 votes

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


title: Creating table view with user profile2

text:
# Question
Title: Creating table view with user profile2
I installed profile2 and i created two different profile types. I used views module to create a table of some fields of user profile types. Now i want to create a link in table to see user whole profile fields in page. I don't know what is the user profile2 link? I also could not see users profile2 field by administrator user.

# Answer
In the View create a *relationship* with the *User uid*. After this You should see a few more field options for you to use.
> 1 votes

---
Tags: views, theming, users
---


# Question
Title: How to create a tick list which one role can alter for 'lesser' roles to see?
I would like some pointers as to what might be the best approach to this issue please?

An admin role needs to be able to interact with a list of nodes for a fitness site. They need to be able to show/hide these nodes in a list for 'lesser' roles. In addition to this the admin needs to be able to mark the node as complete so that the 'lesser' role can see this update. ie

**Admin sees options to amend node list:**

Lose 10 lbs - Show - Mark as complete

Attend 2 sessions - Hide - Not marked as complete

Run 3 miles this week - Show - Not marked as complete

**'Lesser' role sees:**

Lose 10 lbs - Complete.

Run 3 miles this week - Incomplete.

Obviously, I would like to be able to extend this list so that each user is able to see a list that is unique to them, which the admin role has interacted with to show/hide and complete/incomplete different sections.

I'm puzzled as to what approach I ought to take and would really welcome some suggestions to get me started.

Thanks.

# Answer
From the interface that you have outlined, I could see that the 'Flag' module might be really nice for the administrator and user to interact with this kind of list. In a list of nodes, flags would allow in place editing, changing the status, without going into each individual node.

You could configure the names of flags, status, and transition. It would also be possible to assign permissions as to who has permission to change flags between states, and to allow users to change some of the flags themselves.

http://drupal.org/project/flag

To restrict what is seen by the users in the lists, perhaps you could build two similar views blocks: one showing all of the nodes (for administrator), and the other filtered only to show those with flag set to 'show' (for normal users).

The options in each view can be configured to selectively shown each block only to the appropriate role, and then both blocks could be embedded at the appropriate place.

Please note, that is not really enforcing permission to view the hidden nodes, and that a user could find them if they really try hard. It's just being selective about what is shown in the lists.

I was not able to quickly spot an existing module in drupal.org which would set node access by flag status. You may have some luck with some further searching.

However you can use 'Rules' to take actions on flag changes. I think you might be able to pull something together by setting up a series of rules which then assign individual node permissions using 'content access' or another node access module of your choice when the show/hide flag changes state.

Otherwise you could use node\_api and write your module to enforce your particular access rules based on flag status.
> 0 votes

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


# Question
Title: Commerce: Setting Custom Form Default Values
I would like to set custom default values for both the Customer Shipping and Billing forms. I built a custom page/pane that occurs at the beginning of the Commerce Checkout process. This page/pane has 5 fields that pull basic user information before depositing the user at the 'express' checkout form (part 2 in the multi-step form -- or better known as the typical Shipping/Billing forms). My objective is to be able to use the data saved in $form\_state\['order'\]-\>data; in order to pass it into the default\_values in certain textfields within the Shipping/Billing forms.

Using hook\_form\_alter does nothing to modify the Shipping/Billing in either $form\_state or $form. There doesn't appear to be a declaration of default\_value within the forms. Even if I do declare a value/values, it does not show up on the page. Any ideas?

# Answer
> 0 votes
The trick is to use

function hook\_field\_widget\_addressfield\_standard\_form\_alter(&$element, &$form\_state, &$context) { }

---
Tags: forms, commerce
---


# Question
Title: Drupal Commerce - Persistent Data Storage within the Cart
My objective is to build an commerce site that attributes 'tokens' (integer values) to products and than keeps a running total of the complete token value within the cart. The idea is to check against how many tokens the user has before allowing a purchase, allowing a product to be added to cart, etc. etc. So far my strategy has been to do this:

1. Hook\_entity\_info\_alter on the line item product type 'token-based-products' to add a persistent data field for the token value which is required and accessible within views. This seems pretty straight forward.
2. *My Question*. How do I keep persistent data storage about tokens within the cart for validation? The objective for this is to create a few hooks that check the running total token value of the cart before allowing/disallowing a product being added AND before allowing products to be checked out.

# Answer
> 0 votes
I discovered that the wise thing to do was to attribute tokens per user and do either a custom module validation or rules before the product being approved for checkout. Due to the fact that quantities can change in the cart, the validation would also trigger on deletes, or quantity changes in the cart.

---
Tags: forms, commerce, entities
---


# Question
Title: What qualifies as "active development" on drupal.org?
The D7 JW Player module claims to be "Actively maintained" and "Under active development", and yet hasn't had a commit in 30 weeks.

The page for "Actively maintained" implies that the only required qualification for that status is that bug reports are "*looked at*". That seems pretty minimal to me. What about the requirements for being considered "under active development"? Is there really any requirement or can any module be listed as such if its maintainers say it is?

# Answer
> 2 votes
I think you've hit the nail on the head: any module can be listed as "under active development" as long as the maintainer says that's so; unless there's some sort of manual intervention by a user with appropriate permissions on d.o.

From the Dealing with unsupported (abandoned) projects page:

> While most maintainers continue to care for their projects after the initial release, some need to move on and leave the project in the care of the community. Ideally, maintainers will put up a note that the project is in need of a new maintainer so the work can continue uninterrupted. Occasionally, though, a maintainer will stop maintaining a project without explanation.

The page goes on to explain the various routes you can take to either take over maintenance of a module that appears abandoned, or report it so that it can be reviewed. It's not a particularly quick process (the advice is to wait 2 weeks for a response from the current maintainer before continuing), but it's probably your best course of action.

I realise the specific phrase "under active development" isn't mentioned in any of that, but I think it's pretty much the same deal.

# Answer
> 3 votes
If you have edit permissions on a project, you see that it is a vocabulary:

The link is to Maintenance of your project. In other words, it is essentially an honor system that the project creator sets. Unfortunately, developer loses interest in a project they also tend to lose interest in maintaining the webpages and documentation.

Clive has summarized the rest.

---
Tags: community-official-site
---


# Question
Title: What would be a comprehensive but safe set of html tags to use with the HTML Filter but compatible Markdown?
I want to use the Markdown filter on my pages, but using the HTML filter messes it up. However I still want to use it. Does anyone have an idea what other tags should be allowed beside these and what the safety issues are?

This the list I currently use - what else should be added?

```
<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt>
<dd><div><img> <src><h1><h2><h3><h4><h5><h6> <hr> <pre> <blockquote>

```

# Answer
```
<p><table><thead><tr><th>

```

But you don't need enable all of it, just simple reorder the filters, and put the markdown filter under the html filter. So the html filter will drop the unavailable tags, before the markdown process the text, and build own html.

Edit: Checked the OpenAtrium's dedicated Markdown filter, it has the following in HTML

```
<div> <span> <br> <a> <em> <strong> <cite> <code> <strike> <ul> <ol> <li> <dl> <dt> <dd>
 <img> <blockquote> <p> <pre> <h1> <h2> <h3> <h4> <h5> <h6> <table> <caption>
<thead> <th> <td> <tr> <sup> <sub>

```

Markdown PHP Version: 1.0.1n Markdown Extra Version: 1.2.4

And own filter weights:
> 1 votes

---
Tags: theming, input-formats
---


# Question
Title: Best practice two domains on one codebase and database
I have one main domain name at site.com and I simply want to create blog.site.com using the same codebase and database. The only ways I see I can do that are by:

* Using another install
* Using a multi-site install
* Using Domain Access

Among those 3 options, the most straightforward way to keep using one single codebase and database seems to be Domain Access but I wonder if it's not overkill for my use case?

This is with Drupal 7.

# Answer
> 2 votes
It really depends on what you need to do with the Blog vs. the regular site. For Flocknote, we decided to use www.flocknote.com/blog for the blog (so it would be easy to maintain as part of the rest of the website), but also have blog.flocknote.com redirect to the /blog URL (we set that up through a simple .htaccess rule, but you could also set up the redirect through your DNS provider).

If you really don't want the blog running within the same interface/site as the main site, but still want it running on Drupal, you can do that with one of the methods you mention. Just install another drupal site at `blog.example.com` using a database prefix (see Sharing a single database across multiple sites). Domain Access is a great solution if you plan on setting up more than a few subdomains on the same codebase, but it's overkill if you *just* want to run a `blog.` subdomain.

Or, if you want to set up another database, you could create a folder `blog.example.com` in the sites folder, point the `blog` subdomain/virtualhost to the same directory as the main site, and then use the separate database when installing Drupal.

---
Tags: domain-access
---


# Question
Title: Show all children of a specific taxonomy term using Views exposed filters
I have a Views exposed filter that checks nodes with specific terms. I can't seem to find an option to display all children of a term if the parent term is selected.

For example, I will outline a vocabulary:

```
Parent 1
 - Child 1
 - Child 2
 - Child 3
   - Another child
Parent 2
 - Child again

```

If I select "Parent 1" as part of my filtering process, it will display any nodes tagged with that Term. However I'd like it to display all children as well as just the term.

# Answer
> 1 votes
Contextual filters (in the Advanced section) has a parent filter.

Also if you add a Relationship to parent you can make use of that within normal filters.

# Answer
> 0 votes
You could change the way you use your taxonomy's to always include the parent.

For example try using the cck content taxonomy tree widget, then add a little custom js so any time a child is checked the parent it also automatically checked.

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


# Question
Title: Upgrading from d6 to d7: getting puzzling 'requirements problem' error
I am trying to upgrade from d6 to d7 and I'm getting a requirements problem immediately after running upgrade.php. It seems there's some crucial information missing. For me, at least: absolutely no clue what is happening here.

I've got the Ad module (as well as ad\_image, ad\_flash) enabled

The error that is thrown back at me is:

> upload (Missing): Unresolved dependency, Flash Ad requires this module.
> upload (Missing): Unresolved dependency, Image Ad requires this module.

See screenshot

# Answer
> 4 votes
Before upgrading the drupal core, you must deactivate your contrib modules. I think you did not.?

Upgrade the core first. Then upgrade any contrib modules. If you have used cck in drupal 6, you will need the cck module to do the migration.

---
Tags: 7, upgrading
---


title: Using db_query and joins

text:
# Question
Title: Using db_query and joins
I am using Drupal 6 and trying to use db\_query to delete rows from a table based on joins in order to untag a certain node of all tags of certain vocabulary.

This http://drupal.org/node/1079620 implies that delete doesn't work when using joins.

So I have a tried all the following forms of $queries:

```
1) $query = "DELETE a FROM {term_node} a LEFT JOIN {term_data} b ON a.tid = b.tid WHERE a.nid = %d AND b.vid = %d";

2) $query = "DELETE a FROM {term_node} a, {term_data} b WHERE a.tid = b.tid AND a.nid = %d AND b.vid = %d";

3) $query = "DELETE FROM a USING {term_node} AS a, {term_data} AS b WHERE (a.tid = b.tid) AND a.nid = %d AND b.vid = %d";

```

Before running

```
$result = db_query($query, $nid, $vid);

```

None of them deletes the rows from database. I have checked that $nid and $vid get the appropriate values and when I take of the curly brackets and run the query in phpMyAdmin it works like a charm.

I tried to perform simple query where there are no needs from joins. It didn't work either. But once again it works perfectly if I run the query in phpMyAdmin.

I started thinking could it be somehow related to the Drupal batch processing. The delete query not working gets executed when feeds module is performing a batch process (importing nodes to Drupal). So does Drupal during batch process somehow restrict access to tables or something? I didn't find anything in the mysql logs.

# Answer
Some thing you can try doing is try printing the entire query string like,

```
$query = "DELETE a FROM {term_node} a LEFT JOIN {term_data} b ON a.tid = b.tid WHERE a.nid = ".$nid." AND b.vid = ".$vid;
print $query; //printing the query

```

Notice that I have used the variables instead of place holders %d. This might not be relevant but has helped me many times while debugging queries.

On the link you mentioned http://drupal.org/node/1079620, have you tried #5 ? if not give that a try, it should work IMO.
> 1 votes

# Answer
A thing that has bitten me in the past is PHP's "I'm not a typed language until I am a typed language," so throwing a cast into the mix, eg,

```
$result=db_query($query, (int) $nid, (int) $vid);

```

has solved some of these problems for me.
> 0 votes

# Answer
I am curious on the other answers coming, and too lazy to go test this out in dummy d7 instance, I would consider not using left joins with the delete operation.

I think I would try using 2 queries instead of a join. I just think it would be the next possible options short of using subqueries, but those don\`t seem really well supported by D6 db\_select anyhow. So the simplest approach when confronted one can try to divide and conquer. Just use 2 queries, I would consider as an alluring alternate approach.

I'll post working code example during the week-end if you really need one, but it's basically a 10 liner maybe 15 max.

Good-day, happy coding
> 0 votes

---
Tags: database
---


title: Control Fieldset Width in a Block?

text:
# Question
Title: Control Fieldset Width in a Block?
Anyone know how to control the width of a drupal fieldset that's in a block? I have a custom block that I've added 3 fieldsets to using the same exact fieldset code in each, however out of the three, the top one's width is fine, the middle one's is overflowing into the middle column, and then last one is fine. The screenshot shows the top block and the "broken one below it. I want the width to be the same as the top block, which is automatically setting it's width the same as all of the rest of the other blocks in the same column.

Screenshot

# Answer
I would do this with CSS as @Ivanhoe123 suggested.

```
fieldset {
    width: 100px;
}

```
> 1 votes

---
Tags: forms
---