# Question
Title: How to make a page look like it would have w/o tpl
Say, for example, I want to customize the edit user page, so I have created a user-profile.tpl.php. Is there a way to echo out what the page would be normally? What variables should I have access to?

I have tried var\_dumping `$node`, `$form`, `$page`, `$content`, and `$user_profile` and all but the last are null...

`print render($user_profile);` results in a list of profile fields, but not the edit-user page that I get without the tpl file.. (where you can change password, email, etc.

I'm curious for pages/nodes/etc in general, not just this particular one. It's an issue I always struggle with.

# Answer
To see the array $var / $variable -

```
echo "<pre>";
print_r($var); //or $variable whichever is applicable.
echo "</pre>";

```

This will output the entire $var/$variable array in structured manner and you can find out all the data available in your tpl.

Hope that is of some help...
> 2 votes

# Answer
You can simply open the default template (modules/user/user-profile.tpl.php in this case).

The comment at the top of the file should show the variables availible to you.
> 1 votes

---
Tags: 7, theming, nodes
---


# Question
Title: How to add new tab in user edit page drupal
How can i add a new tab in user edit page. In user view page it is coming , but user edit page is not giving any result.

```
function usermail_menu() {
$items = array();
$items['user/%/invoice'] = array(
    'type' => MENU_LOCAL_TASK,
    'title' => 'Subscription Invoice',
    'page callback' => 'usermail_invoice',
    'access callback' => 'user_is_logged_in',
    'weight' => 3
);
return $items;
}

```

This is working correctly. For user edit page i changed the path as

```
function usermail_menu() {
$items = array();
$items['user/%/edit/invoice'] = array(
    'type' => MENU_LOCAL_TASK,
    'title' => 'Subscription Invoice',
    'page callback' => 'usermail_invoice',
    'access callback' => 'user_is_logged_in',
    'weight' => 3
);
return $items;
}

```

But it is not coming. Please help me. Do i want to add something else?

# Answer
> 3 votes
In user.module I saw

```
$items['user/%user/edit'] = array(
    'title' => 'Edit',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_profile_form', 1),
    'access callback' => 'user_edit_access',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'file' => 'user.pages.inc',
);

```

So `user/%user/edit` will be considered as a parent menu item.

Try this:

```

function usermail_menu() {
  $items = array();
  $items['user/%/edit/invoice'] = array(
    'type' => MENU_LOCAL_ACTION,
    'title' => 'Subscription Invoice',
    'page callback' => 'usermail_invoice',
    'access callback' => 'user_is_logged_in',
    'weight' => 3,
  );

  return $items;
}

```

MENU\_LOCAL\_ACTION allows you to add actions on the parent item.

Clear menu cache after making changes.

# Answer
> 3 votes
You just need one item only. Please make the following change

```
$items['user/%user/invoice'] = array(
    'type' => MENU_LOCAL_TASK,
    'title' => 'Subscription Invoice',
    'page arguments' => array('user', 1),
    'page callback' => 'usermail_invoice',
    'access callback' => 'user_is_logged_in',
    'weight' => 3
);

```

---
Tags: 7, hooks
---


title: how to resolve undefined property error

text:
# Question
Title: how to resolve undefined property error
This is my code:

```
function my_module_node_presave($node){
  if ($node->type == 'add_stock') {
    $stock_value = $node->field_stock_value['und'][0]['value'];
    drupal_set_message('stock_value :'.$stock_value);

    $sku = $node->field_sku['und'][0]['value'];
    drupal_set_message('sku :'. $sku);

    $key = $node->field_reference['und'][0]['nid'];
    drupal_set_message('key :'. $key);

    $key1 = node_load($key);
    //$pnode =  $key1->field_product_stock['und'][0]['value'];
    //drupal_set_message('key1 :'.$key1);
    //if (module_exists('uc_stock') && function_exists('uc_stock_adjust')) {

      uc_stock_set($node->$sku, $stock_value);
      uc_stock_adjust($node->$sku, $stock_value);

    //}
  }
}

```

The error I get is the following one:

> Notice: Undefined property: stdClass::$tshirt-11 in my\_module\_node\_presave() (line 40 of
> D:\xampp\htdocs\photo\photogallary\sites\all\modules\my\_module\my\_module.module).
>
> Notice: Undefined property: stdClass::$tshirt-11 in my\_module\_node\_presave() (line 41 of D:\xampp\htdocs\photo\photogallary\sites\all\modules\my\_module\my\_module.module).

# Answer
> 3 votes
When you write `$node->$sku`, PHP takes the value of `$sku` and uses it as name of a property.
In your case, `$sku` contains `'tshirt-11'`, and `$node->$sku` is equivalent to `$node->tshirt-11`. Since `$node->tshirt-11` is not defined, you get the error you see.

The code you should write is the following one.

```
  uc_stock_set($sku, $stock_value);
  uc_stock_adjust($sku, $stock_value);

```

As side note, the value of a field is accessed using field\_get\_items(). The code you use to set `$sku` should be rewritten as the following.

```
$items = field_get_items('node', $node, 'field_sku');
$sku = $items[0];

```

---
Tags: nodes, debugging
---


# Question
Title: Image slider in content type based on selected images from another node (same content type)
As a novice in Drupal php & hooks, I have a question about content type. It is all about Drupal 7 with all up-to-date modules installed.

I have a content type for hotels (about 400 hotels). This content type has lots of fields. One of field is for image (unlimited values). I have user request for image slider in this content type based on images from another node (same content type). Some kind of “We also recommend..:”

My approach was with Advanced Link module where user can enter link to node and this link is then show as field in view (I have view to catch this). Programmatically, I’m then able to take **nid** from that link and extract image I want from node. But now I’m stuck with putting this image dynamically into this view. Is this approach good anyway?

In the beginning I was thinking about to add textarea field to content type and give a user ability to insert image from server (image that is already uploaded) with ckeditor uploader. Only problem with this approach is that all images names from hotel node are in special format (TH-023.jpg…), so they would be in big trouble to find image.

My second thought was to write a module to push image into some kind of field inside content type, immediately after user get link from advanced link field (in edit state of content type node). Is this possible?

Anyway, what would be the best way to do this?

Thanks in advance.

# Answer
> 2 votes
I presume that the "We also Recommend" is manually entered by the user and that you are not using any specific logic to do it.

If that is the case then your approach would be to add an entity reference field in the content type and reference the nodes you want from there.

Once you have that setup you can create a view to get the images from the nodes related the current view using relationship.

If you don't want to add the recommendations manually the you can use taxonomy to categories the contents and then display the images from the nodes tagged with the came taxonomy term.

---
Tags: nodes, media
---


title: How to change node id in drupal 7?

text:
# Question
Title: How to change node id in drupal 7?
I'm very new to drupal. I'm using drupal 7 with ckeditor. I've created one block with 3 views (Link, Image, Link) in it and I've wrote jQuery on 2 links. Then, I've developed second block with same type of views and wrote same jQuery for 2 links in this new block.

But I found (in FireFox using FireBug addon) that all links have same node id. **views-field-view-node** for 1st link and **views-field-view-node-1** for second link for both blocks. So when I click on 1 block's 1st link, action fires in both blocks because drupal received same link id for another block also.

How can I change/modify this node id of view? So I can give separate action.

Used jQuery:

```
drupal_add_js("jQuery(document).ready(function() {
    // change slideshow with your view name
    jQuery('.view-slideshow .view-content').cycle({
        fx: 'fade',
        speed:  'fast',
        timeout: 3000,
        next:   '.views-field-view-node-1', // problem is here. This id is same for both block's link
        prev:   '.views-field-view-node'
    });
});", 'inline');

```

Thanks in advance....

# Answer
This is not a Drupal related problem.

Your 'next' and 'prev' selectors are not specific enough. You should write also the parent block id.

Every block in a page has a unique id attribute in HTML. You should find stuff like

```
<div id="block-3" class="block">

```

wrapping your slideshow.

Just declare a more specific jQuery selector, adding the block id.

Here's a modification for your code, assuming that the block has a "block-3" id:

```
drupal_add_js("jQuery(document).ready(function() {
    // change slideshow with your view name
    jQuery('.view-slideshow .view-content').cycle({
        fx: 'fade',
        speed:  'fast',
        timeout: 3000,
        next:   '#block-3 .views-field-view-node-1', // added a 'parent child' jquery selector
        prev:   '#block-3 .views-field-view-node'
    });
});", 'inline');

```
> 1 votes

# Answer
From the link you shared...looks like you need a slideshow. \- You could simply use Views and Views Slideshow for your purpose.

Hope it helps. If not please do add your comments. I'll try to help if I can. :)
> 0 votes

---
Tags: views, nodes
---


# Question
Title: CKEditor violates layout borders in Drupal 7
In Drupal 7 the CKEditor violates border of left column (where it should be) and penetrates into right column. Now, I can not resize it because when I resize borders of CKEditor by dragging resize button, the icons (image tabs) of CKEditor does not react and does not obey to this act and still remain in right column, although the very borders of editor are changed.
In other words CKEditor icons not only violates borders of my site layout, but also it's own CKEditor borders. I should mention that this nuisance occurs only in my Chrome and Opera browsers, while, for example, in Firefox everything is ok.
Version of CKEditor is 3.6.5. and by following some suggestions I tried to fix this problem by putting library of 3.6.6. version but no solution found. How can this be solved?

# Answer
Install CKEditor module directly instead of use with wysiwyg module.
> 0 votes

---
Tags: 7, wysiwyg
---


# Question
Title: Multistep information collection with reference to price addition or substraction
As I have posted previously, I was trying to built product kit with customization option. But there is no easy solution for that and diving into the coding using drupal commerce or ubercart need understanding of those module first.

So I reviewed the requirement again and saw, checkout is not required. I just have to declare the product kit & gather the information...

Have a look here on this link - Customize Your Laptop

I have to declare package like this. Where there would be default price for kit which will be sum of all default product. Every kind of product, there would some other option either in radio or checkbox and at time of going through step by step user can give their input and total price would change accordingly.

I will tell you the options which I have till now -

* Webform (But the reference price change would be an issue)
* Quiz (Same problem)
* Form API (Client can't create package from them-self that is the main criteria behind this application)

Can I have some suggestion from someone, like what can be my roadmap or which module can help me with it by some tweaking or their API?

# Answer
If you dont want the shopping aspect of the site then I would do the following.

1. Create the content types called the product.
2. Add a field with a drop down with the different steps (Processor, RAM etc)
3. Add a field to add the price.

Create a custom module with formAPI to call these values and do the needful.

Multistep forms would be the way to go. With Ajax to give it some flare.

You can download the example module to see how the form APIs work. The examples you would want to check would be the **form example** and **ajax example**
> 1 votes

---
Tags: forms, webforms, entities, quiz
---


# Question
Title: Is it possible to run a Drupal 7 site without jQuery?
> **Possible Duplicate:**
> Remove jQuery and find out what is asking it to be included

I'm building a simple site that is focussed on performance and must run well on mobile and other low-power devices. I want to avoid jQuery if I can, and want to know if it's even possible or whether it's simply a compromise I'll have to live with. I don't want to start building with jQuery removed and have to carefully engineer things to avoid it, only to find I'll need it later, thus wasting effort better spent elsewhere.

If it *can* be removed, are there any gotachas? Any modules to avoid? Anything else to bear in mind?

Another thought: Can it be restricted to certain pages only, where the interaction it provides is required?

**UPDATE**

There is a similar question that also touches on the issue of jQuery dependency, but where that one broadly asks about dependency tracking and CSS files and theming, this one is **focussed** on the feasibility of removal of jQuery in Drupal and its performance implications. The accepted answer here is substantially different from the one there, as is the theme of the discussion here. Therefore I'd argue that this is not a duplicate and offers value to the community.

# Answer
jQuery is part of Drupal core - and because of this, you can't tell WHAT contrib modules are going to be using it. Well, you can, but it'd involve checking any included scripts of any module. Also, you wouldn't remove `poll.module` or `blog.module` just for server side performance if you're not using them - I would suggest the same applies to jQuery.

I don't think removing jQuery is an option at all realistically, it's not worth the hassle of even trying.

The following, however, are MUCH better options.

For starters, get your hands on the jQuery Update module if you're not using it already. One of the best things you could do to improve jQuery performance is use the most up to date version of the library possible.

Next, try Boost:.

> Boost provides static page caching for Drupal enabling a very significant performance and scalability boost for sites that receive mostly anonymous traffic.

or Varnish if you are on a dedicated hosting plan and have the resources to set it up (Drupal module here).

Serving static HTML pages will take substantially less time, than serving a full dynamic page.

Lastly, if it's a REALLY simple site, evaluate whether or not you even NEED Drupal?

Could you perhaps use a Drupal back-end to manage your content and combine it with the Services module to supply your content to a more performance focused site with a lightweight framework such as Laravel? I've run into situations before where I've used Drupal because "IT'S WHAT I KNOW DAMMIT", where I could realistically have used a much lighter framework and removed a lot of overhead.

**EDIT**

I forgot to mention the tag. Check out other questions tagged with and there will be a plethora of people who might have similar front-end performance issues/ideas!
> 8 votes

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


# Question
Title: Update same table using dynamic query in drupal 7
HiAll,

I want to execute below sql query using Drupal 7 PDO, But could not find a way to do,

SQL:

```
"UPDATE  `books`  AS a
  JOIN  `books` b  ON a.pid = b.pid
  SET  a. `status` = 'INACTIVE'
  WHERE   b.`pdays` * (36400) + b.`ptime_from` > 6546"

```

Drupal 7:

```
 $query = db_update('books','pb');
    $query->fields($update_values);
    $query->join('books', 'pc', 'pc.pid = pb.pid');
    //$query->condition("pc.pdays" * (36400) + "pc.ptime_from",$today ,'>');
   /* $query->expression('pc.pdays', 'pdays * :daytime + pc.ptime_from', array(':daytime' => '36400'),'>')*/
    $isbn_reds = $query->execute();

```

How can we write above SQL in D7 PDO?

# Answer
> 1 votes
To execute clauses like that you would use a where funtion. so your code would be something like

```
$query = db_update('books','pb');
$query->fields($update_values);
$query->where("b.pdays * (36400) + b.ptime_from > 6546");
$isbn_reds = $query->execute();

```

# Answer
> 1 votes
Better you break this query into two parts. The first part will fetch the value and the second will do the update.

**Fetch value**

```
$query = db_select('books', 'a');
$query->join('books', 'b', 'a.pid = b.pid');
$query->fields('b', array('pdays'));
$query->execute();
$pdays = $query->fetchAssoc();

```

**Update**

```
$sql = "
UPDATE books as a
  join books as b on a.pid = b.pid
  set a.status = :type1
  where " . $pdays['pdays'] . " + b.ptime_from > :type2";
$args = array(':type1' => 'INACTIVE', ':type2' => 6546);
db_query($sql, $args);

```

Also you cannot use join in where clause.

---
Tags: database
---


# Question
Title: How to combine two node/add/* forms into one form but create two different types of content in drupal 7 on submitting it?
I want to combine two content/add/\* forms into one form but create two different types of content in drupal 7 on submittiing a single from.

# Answer
> 2 votes
My initial thought on a solution was also entity reference and entity inline form but a few caveats regarding the latter. The enitity inline form adds a submit for the additional content type, this seems against your proposed UX so you will need a hook\_form\_alter to change this behaviour (and indeed the label) have a look at http://drupal.org/node/1880850 for a solution I worked on that will give you a lead in (but not a solution to) this.

The other issue is that I got a lot of annoying but non-fatal and non-damaging errors when I loaded entity inline form so stability may not be 100% there. This could be an issue.

# Answer
> 0 votes
You need to use References module by which,

* you can reference one node from another node, hence creating a relationship between the two.
> + add a node reference field in your **Job** content type which will reference **Questionnaire** content type.
>     + you should have some **questionnaire** nodes first
>     + when you create a **job**, you should get a list of **questionnaires** to chose from
>     + in 'Manage Display' for the **Job** content type, chose **Rendered node** as display for the node reference field - So in node view of the job you will have the questionnare node displayed too.

Hope that's helpful.

# Answer
> 0 votes
Use the Inline Entity Form and Entity Reference.

> Provides a widget for inline management (creation, modification, removal) of referenced entities.

Set up your *Job Apply* content type and add an *Entity Reference* field with an Inline Entity Form Widget to reference your *Questionnaire* entities.

This means that on the add/edit pages your users will have the ability to either create a new *Questionnaire* or reference an existing one.

---
Tags: forms
---


# Question
Title: Logged out when hit home link in drupal 7.19?
Noticed I am auto logged out or at least that is how it appears with the admin bar disappearing and login form visible when I hit the home link.

If I go from logged out home page to another page I appear logged back in.

I am on drupal 7.19 and it resides in a folder set up as a subdirectory.

drupal.mysite.com

the folder is at drupal.mysite.com/drupal

This only occurs when I am navigating about without www prefix and does NOT happen when navigating about with www prefix. My site can be accessed either way but currently advertising as without prefix. The www is more secure obviously but need both to work.

# Answer
> 0 votes
Answer is well stated here http://drupal.org/node/110478

Had I spent a little more time reading I would not have had to ask this question. Also I can see now it is making it so no matter which prefix you use the cookie will stick.

---
Tags: navigation
---


# Question
Title: Building a View or Panel(?) from an existing node and customize path and breadcrumb
I have this requirement I don't know how to approach. The site's taxonomy is used in a hierachical way.

I have a `Conference` content type and the breadcrumbs and url's follow this pattern:

`home/conferences/conference-type/continent/conf-title` where `conference-type` and `continent` are taxonomy terms

A `Conference` has an image gallery contained in an `Image field`, which is **not** visible on the Conference page itself but to a dedicated page located to `home/resources/gallery/conference-type/continent/conference-name`

My question is how do I build this page dynamically from the conference node's content ?

I could use a view or a panel and pass the nid contextual filter, but then:

* How do I build the path/breadcrumb from the nid passed as argument?
* How do I make sure the view is invoked on this specific path?

# Answer
The base url of the view would be `home/resources/gallery/%/%/%` this would ensure that the view is invoked only when all three arguments are present.

and Rather than sending one argument to the view you would be seinding three arguments.

1. Conference Type - The taxonomy term
2. Continent - The Taxonomy term
3. conference-name

Since your content would have all three condition to be true you would get the required url. Other wise you can set it to show a page not found or may do some other things as you want.
> 1 votes

---
Tags: views, panels
---


title: Assign a node to an organic group

text:
# Question
Title: Assign a node to an organic group
Programmatically assign a node to an organic group is following my previous question which I have found the solution for Drupal 7, but I am now looking for the same issue in Drupal 6.

How can I programmatically assign a node to an organic group?

I have tried the following and neither of them worked (assuming `$target_group` is the group ID that I want the $node to be assigned to).

```
$node->og_groups = array($target_group => $target_group);
node_save($node);

```

```
$group = node_load($target_group);
$node->og_groups[0] = $target_group;
$node->og_groups_names[0] = $group->title;

```

What is the proper way to do this?

# Answer
> 0 votes
You're on the right track.
You also have to add a row to the og\_ancestry table. Someone posted sample code for Drupal 6 here.

```
/**
 * Implementation of hook_nodeapi().
 */
function mymodule_nodeapi(&$node, $op, $arg, $page) {
  switch ($op) {
    case 'insert':
      // let's autocreate a Wiki node for our Top wiki page when we create a Group
      if ($node->type == "group") {
        global $user;
        include_once (drupal_get_path('module', 'pathauto') .'/pathauto.inc');
        $path = pathauto_cleanstring($node->title);

        $wiki->type = "wiki";
        $wiki->status = 1;
        $wiki->uid = $user->uid;
        $wiki->name = $user->name;

        $wiki->title = $node->title . " Wiki";
        $wiki->body = t("This is the Wiki for your Community. Any member is allowed to edit this page. Be the first to edit this page by selecting the EDIT tab above and deleting this content and replacing it with your own.");
        $wiki->path = "wiki/" . $path;
        $wiki->og_initial_groups[0][$node->nid];
        $wiki->og_groups[0] = $node->nid;
        $wiki->og_public = 0;
        $wiki->og_groups_names[0] = $node->title;

        if ($wiki = node_submit($wiki)) {
          node_save($wiki);
          $sql = "INSERT INTO {og_ancestry} (nid, group_nid) VALUES (%d, %d)";
          db_query($sql, $wiki->nid, $node->nid);
        }
      }

      break;
  }
}

```

# Answer
> 0 votes
I think that the first option you propose is correct.

```
$node->og_groups = array($target_group => $target_group);
node_save($node);

```

---
Tags: 6, nodes, organic-groups
---


# Question
Title: Webforms: Is it possible to set a delete field button?
As far as I understand there is not possible do delete the field value of file upload fields but rather replacing the field with an empty one.

1. Is it possible to add this button using JS and thus delete the text path inside the field without refreshing the page (PLAIN SIMPLE)? Otherwise I am afraid i need to use a php solution with page refresh.
2. If not is it possible for 'Delete' to emulate the 'Browse' button? I mean when hitting 'Delete' to actually browse for another file?

ps. I know webforms are using their own implementation but I am force to find another solution

# Answer
> 0 votes
This link seems to have some solution. Clear upload file input field with jQuery

The relevant js is given below.

> The HTML of any element can be reset with jQuery using the following function and passing in the id of the element's parent. This will reset the HTML within the parent to its original state; it will lose any binding you'd added after the DOM was loaded (such as adding an event handler in $(document).ready). Here's the Javascript for doing this:

```
function reset_html(id) {
    $('#'+id).html($('#'+id).html());
}

```

> In $(document).ready we can now add a div around every element with a clear button, binding a function to it which will reset the HTML of the div like so:

```
$(document).ready(function() {

    var file_input_index = 0;
    $('input[type=file]').each(function() {
        file_input_index++;
        $(this).wrap('<div id="file_input_container_'+file_input_index+'"></div>');
        $(this).after('<input type="button" value="Clear" onclick="reset_html(\'file_input_container_'+file_input_index+'\')" />');
    });

});

```

Note : I have not tested this out myself.

---
Tags: webforms
---


# Question
Title: hook into third party API after checkout
I wondering where to get started on this, I have ubercart core 6.x-2.10 installed and configured with authorize.net. after a user purchases a "product" I want them to be registered on a third party webinar site. Where in the code would I start are there any extra modules I should use?

# Answer
You should probably be looking to use the `hook_uc_checkout_complete()` hook.

From the docs, it takes two parameters, `$order` and `$account` \- I'm guessing `$account` will be the one you'll need to create the account on the third party web service as it's the object that contains the customer/user information.

The registration part of your question depends completely on *which* third-party web service you are talking about, and will *probably* fall outside the scope of Drupal Answers unless there is either an existing integration module, or you are looking to write one and need help on the Drupal side of things (i.e. this is not the place for general API usage questions).
> 3 votes

---
Tags: 6, ubercart
---


# Question
Title: How to hook into file upload and remove button
I am implementing a module (in Drupal 7) that allows the user to upload or remove a file using the managed\_file form type. I have looked at the form APIs and it states that info about the file should appear in \['values\]\['form\_name'\] but that is not what I see. To find any info about the uploaded file I need to look in \['input'\]\['form\_name'\]\[0\]. And when I do, the only values available are \['fid'\] (which is always set to the file id) and \['UPLOAD'\] (which is always NULL). The problem is that I don't know if the user wanted to add or remove the file. How do I determine this? What have I screwed up?

Here is my form:

```
$form_array = array(
  '#type' => 'managed_file',
  '#title' => t('File'),
  '#description' => 'The file associated with this submission',
  '#name' => 'obj_file',
  '#upload_location' => 'private://temp',
  '#default_value' => $submission->file,
);

```

Here is the submit portion:

```
if ($file_id == 0 && $submission->file) {
  $file = file_load($submission->file);
  file_delete($file);
} else {
  $file = file_load($file_id);
  $file->status = FILE_STATUS_PERMANENT;
  file_save($file);
  file_usage_add($file, 'my_module', 'submission', $submission->id);
}

```

According to the API file id should be 0 if removed but it never is in my case. Is it possible to hook into file\_managed\_file\_submit()? That would at least provide an avenue to see which button is being pressed.

Any help or insights would be appreciated!

# Answer
The file `managed_file` field is used to upload files I am not sure if it can be used to delete a file from the server if that is what you are trying to do.

The process actually works as follows

When you click the upload button it uploads the file to the server and stored the fid to the field itself and this is the only value we need in the submit function to handle the file as we would using the file\_load function to load the file and get the file object using the fid alone.

Now when the user clicks the remove button the field value is set to 0. But the actual file is not deleted from the server and the fid is still stored in the file table.

the `'#default_value'` should be set to `variable_get('image_example_image_fid', ''),` this would be used in our form submit function when the field is 0.

The documentation is talking about deleting the file from the temporary table and the server. You would need to remove it in your submit function.

Please check the example from the examples module

```
if ($form_state['values']['image_example_image_fid'] != 0) {
    // The new file's status is set to 0 or temporary and in order to ensure
    // that the file is not removed after 6 hours we need to change it's status
    // to 1. Save the ID of the uploaded image for later use.
    $file = file_load($form_state['values']['image_example_image_fid']);
    $file->status = FILE_STATUS_PERMANENT;
    file_save($file);

    // When a module is managing a file, it must manage the usage count.
    // Here we increment the usage count with file_usage_add().
    file_usage_add($file, 'image_example', 'sample_image', 1);

    // Save the fid of the file so that the module can reference it later.
    variable_set('image_example_image_fid', $file->fid);
    drupal_set_message(t('The image @image_name was uploaded and saved with an ID of @fid and will be displayed using the style @style.', array('@image_name' => $file->filename, '@fid' => $file->fid, '@style' => $form_state['values']['image_example_style_name'])));
  }
  // If the file was removed we need to remove the module's reference to the
  // removed file's fid, and remove the file.
  elseif ($form_state['values']['image_example_image_fid'] == 0) {
    // Retrieve the old file's id.
    $fid = variable_get('image_example_image_fid', FALSE);
    $file = $fid ? file_load($fid) : FALSE;
    if ($file) {
      // When a module is managing a file, it must manage the usage count.
      // Here we decrement the usage count with file_usage_delete().
      file_usage_delete($file, 'image_example', 'sample_image', 1);

      // The file_delete() function takes a file object and checks to see if
      // the file is being used by any other modules. If it is the delete
      // operation is cancelled, otherwise the file is deleted.
      file_delete($file);
    }

    // Either way the module needs to update it's reference since even if the
    // file is in use by another module and not deleted we no longer want to
    // use it.
    variable_set('image_example_image_fid', FALSE);
    drupal_set_message(t('The image @image_name was removed.', array('@image_name' => $file->filename)));
  }

```
> 4 votes

---
Tags: 7, files, forms
---


title: Menu entries not being translated

text:
# Question
Title: Menu entries not being translated
I have sitemap, and I would like to display the menu in the primary language of the site. However, as this screenshot shows, some items are still being displayed in English:

How can I fix this?

# Answer
I miss to determine the language of the menu ... I am stupid it fix by adding the language of each menu i wanna to display on specific language like this
> 2 votes

---
Tags: multi-sites
---


# Question
Title: How to programatically get the machine name of a node?
I want to add the machine name of every node into my page.tpl.php template as a class on the body. How can I get that machine name?

I have access to the node object, but I don't see the machine name in there. Is there an api call I can use?

# Answer
> 2 votes
*Individual* nodes don't have machine names in Drupal 6 or 7, so you can't.

If you want a unique ID for each node, and Node ID won't do (for staging or migration for example), then try taking a look at the UUID module.

> This module provides an API for adding universally unique identifiers (UUID) to Drupal objects, most notably entities.

Also of note...

> Features in Drupal 6 version
>
> * Automatic UUID generation for nodes, node revisions, users and taxonomy.
> * Allow choosing which content types and vocabularies to create UUIDs for.
> * Option to batch create UUIDs for objects which don't have it already.

If, however, you want the node TYPE to be available to your template, and you have the node object, it should be under `$node->type`, or *possibly* `$vars['type']`.

---
Tags: 6, theming
---


title: Drupal 7 access arguments

text:
# Question
Title: Drupal 7 access arguments
Is this right? I want to only give access to the people who have 'Download Original' checked in permissions.

```
function userDownload_menu() {
  $items['user/download'] = array(
   'title' => 'User Download',
   'page callback' => 'user_download_init',
   'access arguments' => array('Download Original'),
   'type' => MENU_SUGGESTED_ITEM,
 );

return $items;
}

```

If this is correct it's not working for me. Otherwise how can I pass a user role to this?

# Answer
You need to use Hook permission to define the permission within your module
> 1 votes

---
Tags: 7, routes
---


# Question
Title: Add link that performs database function
I am building a tableselect. What I want is to have last row be a link that when clicked performs a CRUD using the row ID as input. The goal is to have a "delete" link that removes that row from the database. Or an add link that does the reverse.

I am looking at the example of the admin/content, which creates links like I need at the end of its table. But because this works on Nodes and I am working on database rows (in a custom table), this doesn't seem to really apply.

Are there any good tutorials/examples on something like this. I've found a few that helped me create the table, but this functionality I can't seem to find.

EDIT: And after reading through my own question again, I realized the business logic here wouldn't work... sorry for getting ahead of myself.

# Answer
There are two separate things to take care here, one is dealing with the database table, you will find all the functions you need to use for CRUD operations on databases here.

The other issue is dealing with the table showed on the browser page, if you want to operate with tables your best bet (IMHO) is to use Ctools, install it and enable the Ctools Ajax example submodule, there you will find exactly what you want, a link that removes the file.

Hope this helps.
> 0 votes

---
Tags: forms
---


# Question
Title: How to display content in views with large 4-layer taxonomy term tree filter?
To describe my problem more accurately I'll give a simple example of my situation: I have a categorized content. There are 10 different categories like clothes, cars, lamps etc. Each of them have more child terms(clothes:white,red,black) Each of those has more childs(white: size1, size2 etc). If i put everything under one vocabulary, the term Filter in views gives a very long list of every single term in that vocabulary. That's kind of crappy.

A thing like this would probably solve my problems: http://drupal.org/project/hierarchical\_select

However, it's still not available for views. So how do i go about this?

I saw sites with same category trees using just top layer of vocabulary for views filter, and other terms putting as menus above whole content view. For example if Clothes is selected in filter, you see all the relevant content plus menu of White, Red and Black and so on. Maybe it's not exactly the way they do it but i'm trying to figure out what's the best way to solve this.

# Answer
> 0 votes
You can filter by parent term in views; that way you don't have to list every term in the vocabulary. Also, learn what a contextual filter is and how to use it. Here's a series of free screencasts on learning how to use Views.

# Answer
> 0 votes
I've been following the following issue on drupal.org for a while now about porting hierarchical\_select to views: http://drupal.org/node/1170192. Yikes! The issue has 198 followers, so a lot of us are looking for precisely the same functionality.

The following *very new* module has come out of this effort: Simple Hierarchical Select.

The module provides a widget you can use in views as an exposed filter, so I think it'e exactly what you're looking for. :-)

Let us know if it works out!!

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


title: Ajax comment form error with Fivestar

text:
# Question
Title: Ajax comment form error with Fivestar
I have a page that loads the comments section via Ajax once the user scrolls down to the comment section via a custom Drupal ajax callback I defined:

Comments are loaded fine, and using a custom module I'm able to delete, edit, reply and preview comments via Ajax successfully.

The Comment form is loaded via Ajax as well, using this function:

http://paste2.org/p/2757034

**Now, here's the problem.**

When the comment form isn't a reply to another comment, if I preview the comment and then save, I get this error:

> The form has become outdated. Copy any unsaved work in the form below and then reload this page.

Now, here is the code that's generating the form after it's previewed:

http://paste2.org/p/2757036

I tried drupal\_rebuild\_form() instead of drupal\_build\_form, but I had no success. I searched a lot for a workaround but couldn't find one.

**EDIT:** It appears that **Fivestar** is causing the problem. After disabling Fivestar, the form is submitted successfully. However I can't remove fivestar from this page.

Here's what's in $form\_state when I click in the preview button:

# Answer
This is actually a really annoying Fivestar bug:

http://drupal.org/node/1370526#comment-5367970

The problem is now fixed.
> 7 votes

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


# Question
Title: Primary links background not visible by non-admins
I have styled my primary links with a background and it all works out just fine. Except for when I log out, the background disappears.
So it looks like the anonymous user doesn't have permissions to see the background (which I would fine strange...)

Is this a known issue and if so, what can I do about this?

# Answer
> 1 votes
Did you use the correct classes? E.g. when you use the .logged-in class in your CSS, the style will not be used when not logged in.

---
Tags: 7, theming
---


# Question
Title: Is there a clean-URL-reflective version of file_create_url()?
I have a site with clean URLs enabled and in a test I've written, I compare the current `drupalGetHeader('location')` to `file_create_url($file->uri)`. The tests passes on my site, but on the qa.drupal.org testbot (and, presumably, on any site that doesn't have clean URLs enabled) the test fails.

Is there an API function that's more clean-URL-reflective to `file_create_url()`?

# Answer
I ended up using

```
str_replace('/?q=', '/'drupalGetHeader('location'));

```

So basically I gave up on including the `?q=` that appears in the URL and instead stripped it from everything. It seems a little messy but it works for my purpose. Still doesn't really answer the question though.

`drupal_parse_url()` looked promising at first, but it didn't work because

`drupal_parse_url(file_create_url($uri))` returned 'path' = `http://example.com/path/to/file`

but

`drupal_parse_url(drupal_get_headers('location'))` returned simply 'path' = `/path/to/file`
> 0 votes

---
Tags: testing, uri, files
---


title: Developing Apps with Panopoly

text:
# Question
Title: Developing Apps with Panopoly
I'm developing a panopoly App for Services and case studies. I have added my required field and created the content type, added panels and views etc. Finally I created the feature and downloaded for the same. I have done this from the following Documentation. Creating Panopoly Apps. http://drupal.org/node/1704334

I have achieved step 1-4 and I am stuck on step 5 : Integrate the feature with Apps.

Please help to create the feature as an App. I don't have any server setup.

Thanks in advance.

# Answer
> 2 votes
You'll have to either create your own apps server using the Apps Server module or submit your app to an existing app server. In your case, you'll probably want to post on the Panopoly issue queue and ask about the process to do that; @populist will probably be the guy to answer your questions there.

Check out this post for more info on the Drupal apps scene:

http://chocolatelilyweb.ca/blog/drupal-apps-answer-plug-and-play-drupal-site-building

---
Tags: panels, features
---


# Question
Title: How do I add a checkbox to the performance page and have it repopulate?
I would like to add a checkbox of my own to the performance page in the Drupal administration. I am using hook\_form\_alter like this:

```
function nci_assay_depot_form_alter(&$form, &$form_state, $form_id){
    switch($form_id){
        case "system_performance_settings":
            $form["caching"]["nci_assay_depot"] = array(
                "#type" => "checkbox"
                ,"#title" => "Refresh Assay Depot Cache when 'Clear All Caches'"
                ,"#default_value" => 1
                ,"#disabled" => 0
                ,"#description" => null
                ,"#weight" => -2
            ) ;
        break;
    }
}

```

It will display on the page, but the value will not be saved. Any thoughts?

# Answer
> 1 votes
* to have it "repopulate" after save provide a `#default_value` key that retrieves it on page load.
* to actually save it append (add another) custom form submit handler to the form, after the original one gets fired. Something like `$form['#submit'][] = 'mymodule_mysubmit_handler';` You will have to check where the submit handler is set already in the form, or the element you're trying to hook into (such as `$form['caching']` ...

---
Tags: performance, forms
---


title: Is there a list of ahah effects?

text:
# Question
Title: Is there a list of ahah effects?
I'm getting into the FAPI ahah property and I was wondering if there is a list of all the "standard" possible effects that would be available for use without adding any modules (i.e. additional libraries).

Thanks! Stephanie

# Answer
Accord with the Documentation you can use:

* none (default)
* fade
* slide
> 0 votes

---
Tags: 6, ajax
---


# Question
Title: Is there an option in the Views 3 UI to reset one section of a non-master display to the default state?
I've got a view that contains several different displays. When I override an option for a single display, the header for that section is displayed in italics. For example, if I override the **Filter Criteria** for a single display, **Filter Criteria** is shown as ***Filter Criteria*** on that display.

Is there a way to revert overridden sections (***Filter Criteria***, ***Fields***) from within the UI if I change my mind about overriding? Of course I can manually re-create the settings to match those of the master, but this is a pain...

# Answer
> 5 votes
Yes, just edit a filter or field and choose "revert to default"

---
Tags: views
---


title: Open views content in new window?

text:
# Question
Title: Open views content in new window?
Is there a way to open content in new window or add back button to it in views?

When you click on a content title from Views list there needs to be a quick way to navigate back to that list after viewing content.

# Answer
In views there is an option called Rewrite out put. You can use the rewrite out but as link and Provide the link as well as the target.

If everything is going through views then you can change the path of your content to reflect the path of your view using the pathauto module and use a breadcrumb module that would allow you to create breadcrumb from the path this way the path to the main view would be displayed in the breadcrumb for better navigation. You can take a look at the breadcrumb module
> 1 votes

---
Tags: views
---


# Question
Title: drupal_render radios missing name attribute
When rendering form type radios using drupal\_get\_form, each one of the radio's options can be exclusively selected, as the html name attribute is set to the parent's ('radios') id.

However I'm working on an ajax form module that integrates with mailchimp, and renders these form elements individually in isolation using drupal\_render so they can be placed in a template.

My code to render radios is as follows:

```

$form_child = array (
  '#title' => 'Some Radios',
  '#weight' => '6',
  '#required' => false,
  '#default_value' => '',
  '#type' => 'radios',
  '#options' => array (
    'Option 1' => 'Option 1',
    'Option 2' => 'Option 2',
    'Option 3' => 'Option 3',
  ),
); // This is generated in my module

$form_child = form_process_radios($form_child);

$myhtml = drupal_render($form_child);

```

And here is what happens on my form: HTML output

In the browser

# Answer
> 1 votes
the function of the form\_process\_radios as given by the documentation is as follows

> Expands a radios element into individual radio elements.

So the out put you are getting is correct as per the documentation.

So in your case you dont need to call the form\_process\_radios. You can directly call the drupal\_render function.

# Answer
> 1 votes
I solved this problem eventually by calling drupal\_process\_form in hook\_form\_alter. Not sure if this is correct, but it works well and no extra steps are needed to get form elements rendering correctly. Any follow up or advice is appreciated. I'm sure that drupal\_process\_form is called in the drupal\_get\_form render path, just not sure of what hook to render custom parts in various locations. Probably theme\_hook for the form, but it works well now for my purposes.

---
Tags: forms, theming
---


# Question
Title: How to have tpl for parent but not child?
I want to override the template for just `/user/` but not for `/user/edit` or `user/anythingelse`. Is there a way to do that?

For example, I made a page--user.tpl.php but it effects all of user's children.

# Answer
You are editing in wrong template file. You have to make theme changes in user-profile.tpl.php.

For theme hook suggestions:

```
function themeName_preprocess_page(&$vars, $hook) {
  // Go to user page.

  // Requires devel module.
  dpm($vars['theme_hook_suggestions']);
}

```
> 0 votes

---
Tags: 7, hooks, theming
---


# Question
Title: Using Profile2 and Views - How to display the separate profile data on a single row
I have several different pieces of info in separate profile2 forms. When I run the view to display the data I want, it looks like this:

```
Profile      UID PID IID  Name         Email                     Membership
Main Profile 124 15  1237 Bernardo Lee BernardoLLee@teleworm.us
Membership   124 76                                              Basic Member

```

The Membership and Main Profile show up on different rows for the same users. I was hoping that by not displaying Profile and PID, the data would show up on one line like:

```
UID IID  Name         Email                     Membership
124 1237 Bernardo Lee BernardoLLee@teleworm.us  Basic Member

```

But it still shows on two lines.

Also, I can't figure out where the "profile2" table is. The query in Views is

```
        SELECT profile.type AS profile_type, profile.uid AS profile_uid, profile.pid AS
     pid, 'profile2' AS field_data_field_ibo_number_profile2_entity_type, 'profile2' AS
     field_data_field_first_name_profile2_entity_type, 'profile2' AS
     field_data_field_last_name_profile2_entity_type, 'profile2' AS
     field_data_field_primary_email_profile2_entity_type, 'profile2' AS
     field_data_field_cell_phone_profile2_entity_type, 'profile2' AS
     field_data_field_globalnet_membership_plan__profile2_entity_, 'profile2' AS
    field_data_field_monthly_educational_book_profile2_entity_ty
        FROM
        {profile} profile
        INNER JOIN {users} users_profile ON profile.uid = users_profile.uid
        WHERE (( (profile.type IN  ('main', 'knowing_you_better', 'website_info',
 'credit_card_info', 'membership', 'line_of_sponsorship')) ))
        ORDER BY profile_uid ASC

```

but when I drop it into mysql, it's an invalid query

I don't understand the {profile} and {users} nor the 'profile2' I was hoping to rewrite the query if I can't get views to directly display what I am looking for.

# Answer
I am not sure how you have created the view. But this would be the method to go about it

1. Create a view of the user.
2. Create two relationship of the type **User : Profile** One for the **Main Profile** and the other for the **Membership**
3. Add the required fields choose The corresponding relationship for each of the fields, that is choose the one we created for **Main Profile** for the fields with in Main Profile and Membership for the ones in the membership.

That should bring it all in one line.

You might not be able to have the Profile and PID like in the first out put but I guess you dont want that .
> 2 votes

---
Tags: views, users
---


# Question
Title: How to subscribe to notifications or alerts via RSS feeds?
How would I go about adding the functionality of subscribing to notifications or alerts via RSS feeds for certain pages/documents or images?

# Answer
You can create custom **feeds** using the views. This can contain any fields as you want. And use all the filters, relationships and contextual filters to get the exact feed that you are looking for. The you can place feed link where ever you want it to be seen. This would be done using blocks or may be simply by adding it to the page.
> 1 votes

---
Tags: 7, feeds, notifications
---


# Question
Title: Programmatically create node using feeds
I'm creating nodes from XML using the Feeds module (great module BTW).

```
function boardgamegeek_menu() {
  $items['games/add/%/%'] = array(
    'title' => 'Boardgamegeek add game',
    'description' => 'Boardgamegeek add game',
    'page arguments' => array(2, 3),
    'page callback' => 'boardgamegeek_add',
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

function boardgamegeek_add($objectid, $title) {
  $node = new stdClass();
  $node->type = 'boardgame';
  $node->title = $title;
  $node->feeds['FeedsHTTPFetcher']['source'] = 'http://www.boardgamegeek.com/xmlapi/boardgame/' . $objectid;
  node_save($node);
  /*
  // This does an import
  $myFeed = feeds_source('game_importer');
  while (FEEDS_BATCH_COMPLETE != $myFeed->import());
  */
  return 'http://www.boardgamegeek.com/xmlapi/boardgame/' . $objectid;
}

```

When I run this code, a node is created with a title field value from $title (that's exactly what I want). The import doesn't start automatically, and when I start the import myself, another node is being created without any title.

I would like to update the node I created...

The feed\_nid and the entity\_id should be the same. The feed\_nid is the node id from the node I created, the entity id is the node id feeds created.

Any ideas?

# Answer
From the description what I understand is that you are trying to create a node with all the contents from the feed except the Title which you have set manually.

You have created a feed which would run when you create a node of the type "boardgame" with an HTTP Fetcher.

The way feeds work in this case is when you create the node with the attached feed. It creates a node for the feed itself and also creates additional nodes with the contents in the feed. So in effect the feed is not meant to update the node executing the feed but to create additional nodes from the feed itself. And I guess that is happening without any issue in your setup.

To achieve what ou want to do you can install the following module

Feeds Self Parser

What this does it to update the node being created from the feed it self and not create another node instead.

**Note :** You might have to clear cache for the module to work other wise you might get an error **FeedsMissingPlugin\_feeds\_form in drupal\_retrieve\_form()**

This way you dont really need to create a module just create a node with the with the title entered and the url as well. But if there is some other reason from creating the module then yes that would work fine as well.

Second option is to not use the feeds module itself. Just parse the xml manually and add the required fields and call the `node_save()` function. This would mean you wouldn't have to run the feed script after you create the node it would be done automatically by just calling the url. and it will also take you off the overheads of using the feeds module.
> 4 votes

---
Tags: 7, feeds, nodes
---


# Question
Title: Efficient and easy Drupal 7 Development to Production workflow
How would you put large existing Drupal 7 production site in some simple Development-Staging-Production workflow ?

I read through various documentation about the issue, but would like to know more efficient real life examples.

It is environment where only one person changes Drupal code (for now), and several editors do content publishing (they can edit content on live site and it seems it is ok to allow them).

I have in control Debian box with admin privleges (production site), and recently I did set up local Development/Staging Server (also a Debian box).

I am fond to Drush (haven't took advantage of drush make, though, but I had migrated some Drupal sites from server to server). I haven't used Features module, but I could implement it if neccessary. I have not used GIT yet, but I had read about it in theory. I am not sure is it a must for me to go with GIT, considering only one developer commits code.

My concern is about database updating, as I understood, GIT does not do that, and there could be enormous and critical differences between dev and production DB (settings change, site user inputs (registrations, comments etc, node creation etc)

Any advices?

# Answer
> 7 votes
In short, I would:

* Use features to get my configuration in code.
* Use git to manage my code.
* Use drush to manage my databases.

**Why to use git to manage code:**

1. Drupal.org uses git to manage the Drupal project and all the modules.
2. Version control of code allows you to easily see what changes have been made to your code over time. Without this, debugging/rolling back to a known good state is much harder.

When using git, I personally avoid complicated features (like submodules for Drupal modules) and simply commit all my code (Drupal core, contrib modules, patches, and my features) to a single repository.

If you already have dev and staging servers set up, getting git to push code to all three machines shouldn't be too hard to set up.

**Why to use features to get configuration into code:**

If you do dev/staging/live, you are going to have three sites now, not just one. Keeping track of configuration changes among three sites is a mess.

You basically have two options:

1. Write down all your changes in a text file and apply them site-by-site manually.
2. Use features.

Although #2 is harder to set up, it's much easier to deal with in the long run. A command like `drush @mylivesite fd` will quickly reveal how the configuration on your live site differs from the code in the features (managed by git).

In addition, as an added benefit of getting everything in features, you can edit the features code directly with a text editor; sometimes this is faster than using the Drupal admin UI.

**Why to use Drush to manage databases:**

Drush has a number of commands for syncing databases. It can be a bit of pain to get your servers set up to do this, but once you do, the time savings are tremendous. Google for tutorials for details.

**In conclusion:**

With this setup, most of your configuration will be in code (thanks to features). Your code will be version-controlled and easily pushed between servers (via git). What git can't handle, the database, will be taken care of with drush.

---
Tags: migrations, staging
---


# Question
Title: "Redirect Loop" when creating a multisite
I know there are a few questions related to this one, yet I haven't been able to answer mine.

I want to develop 2 websites pointing to the same Drupal core files,

so :

drupal1.example.com should point /www/dev/sites/drupal1.example.com drupal2.example.com should point to /www/dev/sites/drupal2.example.com

1. I've created both subdomains to point to /www/dev/ folder.
2. I've put settings.php in drupal1.example.com and default.settings.php in drupal2.example.com
3. When I load drupal2.example.com, I get a "Redirect Loop" error.

Do you know what I'm doing wrong ?

Thanks!

**ANSWER :**

When there was no settings.php file in my sites/drupal2.example.com folder, it showed the drupal1.example.com website.

When there was a settings.php file in my sites/drupal2.example.com folder, it got me an infinite loop.

So I modified the settings.php in sites/drupal2.example.com folder to connect to a different empty databse, but then I got an error "Base table or view not found: 1146" then another error upon refresh "error: Class 'SelectQueryExtender' not found".

It seemed as though the installer had a hard time loading the 2nd instance of Drupal since there were no tables in the DB.

So I imported DB #1 into DB #2 and it worked. I could change the theme in drupal2.example.com and I still had the old theme in drupal1.example.com.

The only downside is that I have to delete the content types, nodes, menus, etc ... in my drupal2 but I least it's working!

# Answer
Assuming you have `ServerName` and `ServerAlias` properly defined in Apache, I suspect you have the default canonical URL redirects enabled in your .htaccess. Make sure this stuff is all commented out:

```
  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # uncomment the following:
  # RewriteCond %{HTTP_HOST} !^www\. [NC]
  # RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment the following:
  # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  # RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

```

Also make sure you don't have any other Apache rules that are doing something similar, and that you don't have any modules (eg, Domain Access or Mobile Tools) or custom code that would do a redirect.
> 1 votes

# Answer
If you are on a shared host and have installed Drupal through a Script check if `install.php` is in the document root.

If not, download Drupal, extract `install.php` and put it in the document root. Now go to the site and the installer should work.
> 0 votes

---
Tags: multi-sites, subsites
---


# Question
Title: How to use Views with Fields Collection and filter on where used
I am using Entity Registrations to handle registrations for a sponsored walk. I have setup a fields collection so that registrants can register more than one person at a time.

At the moment there is only one Registration Entity for the 2013 sponsored walk, but in future there will be more.

So.... In views I want to create a table that allows the admin to view the fields collection related to a specific Entity Registration. i.e. Show only those users registered for the Spring 2013 sponsored walk or just those registered for the Summer 2013 Walk.

I could duplicate my fields collection to make a new one for each Entity Registration, but I would rather avoid that type of duplication if I can help it.

Any ideas?

# Answer
I hope you are creating a view of the type Registration in that case you can add a contextual filter of the type **Registration: Host entity ID**

Now when you add the nid of the main node you would see the registration specific to that node.

Note : To get the **Registration: Host entity ID** as a contextual filter you need to enable the Registration Views module.
> 0 votes

---
Tags: views, entities
---


# Question
Title: How can I find the name of the field store in the DB?
I have a content type for which I have created my own img using cck like this:

How can I find the name of the table that stores the img field?

# Answer
**Drupal 7**

If the name of the image field is "Dark Image", then the table name in database will be `field_data_field_dark_image`

**Drupal 6**

As mentioned in this page, table name should be `content_type_YOUR_CONTENT_TYPE_NAME`. If the name of the image field is "Dark Image", inside the table you will find a column called `field_dark_image` that stores field data.
> 3 votes

# Answer
If indeed this is about D6, you have the following possibilities:

1. This image is only found in one content type:

a. Look for a content\_type\_TYPE, eg, content\_type\_story, table.

b. In there, you will have fields/columns like:

```
  i. field_dark_image_fid -- the file id of the image file
 ii. field_dark_image_list -- a boolean used basically to show if the file is there and is listable (eg if it isn't a required field, these columns are still here)
iii. field_dark_image_data -- a serialized blob of other info about the file, alt, title, height, width etc

```
2. The image is found in multiple content types:

a. Look for a content\_field\_FIELDNAME table, eg, content\_field\_dark\_image

b. In there, look for similar fields/columns as in 1. above that are linked back to your content type via the nid and vid fields/columns.

In both scenarios, more/major information about your image field is contained in the files table, which is indexed off of the ...\_fid field/column above, and there you can find information such as uid, filename, path, mime type, size, creation date etc.
> 2 votes

---
Tags: entities
---


# Question
Title: What does this error mean and how can I fix it?
I do not know what this "notice" means:

> Notice: Undefined index: content in ds\_render\_block\_field() (line 947 of /home/magpie/public\_html/mysite.com/sites/all/modules/ds/ds.module). Notice: Undefined index: content in ds\_render\_block\_field() (line 947 of /home/magpie/public\_html/mysite.com/sites/all/modules/ds/ds.module).

I am tempted to just delete the line but I think it is best to check first and verify that it is not important.

Can somebody help explain how errors like this occur? And how to prevent them and deal with them?

# Answer
To check what errors mean, you can use Google. Here's how.

Search for the error message inside double quotes (" ") but don't search for the whole message, just the part up to the line number (why: line numbers may be different depending on the site and you won't get any hits.) Searching inside double quotes forces Google to only match pages that have the exact phrase inside the quotes.

In this case, make a search like this:

> "Notice: Undefined index: content in ds\_render\_block\_field()"

The first result is an issue explaining the problem on Drupal.org.

That issue shows that the problem is with the Display Suite module. If you read through the issue linked above, you will find a link to this issue, which is a bug report. Reading this issue shows that the bug was fixed in a dev version of Display Suite. So, to fix the problem, you should be able to update to the latest dev version of the Display Suite module.
> -1 votes

# Answer
It's a notice, not a big deal to make you worry as it says, there is an undefined line in your display suit module
> 0 votes

---
Tags: display-suite
---


# Question
Title: Conditional price in readonly text field
I have a content type to create membership for a plan, There are around 900 kind of price based on condition. I know conditional field only make visible the text-field when criteria match but if I create text field for each price then my content type will have more than 1000 fields and that is some kind of fussy isn't it ?

So can anybody suggest me any other option to do it, like I know first 4 condition, based on which the value has to come, I can make table for it...but how to go forward to make it appear in content creation page ?

# Answer
> 1 votes
Looking at your requirements I would suggest going with the data module

You could create a table with all the possible combinations. Once that is done in your content type you would be displaying the required fields such as Apartment Type, Plan Type etc. When the content is chosen you can look up in the table and get the correct pricing.

There are some assumptions made here. The prices are fixed and known in advance and changes in price would be minimal. We only need to get the correct price defined byt the table.

As for the down payment and EMI I presume you would have a set rules for the same which can be calculated on the go.

---
Tags: entities
---


# Question
Title: Change site logo for an specific content type
I'm building a really simple site and I came into this question now. The site has a few content types and one of them acts as a moderated wiki (only users with a certain role may create/edit that content). When viewing lists of these nodes or when viewing any node of that content type in full-mode I would like the site logo to be different. Say, instead of «My site», something like «My site \[\[wiki\]\]».

My first thought was tweaking context to change theme settings based on context. Too bad, I didnt find how to get that :/

I've been diving in the available answers here, but I dont seem to have an answer, though a couple of similar question tackle this subject through different systems:

* One attempts to show different logo for different languages and relies and i18n and variable modules. see thread on i18n and variable
* Second one adds a variable (though it is not clear if they put it directly in the node--type.tpl file (and i wouldnt like that :-/), by hand-writing the path to the desired image... see thread on tpl "abusing" :D

Any ideas on what is the best approach to get this custom logo for an specific content type?

Thanks :)

The code provided in the answer wasn't working properly, but I adapted the code and got it to work:

```
function YOURTHEMENAME_preprocess_page(&$vars, $hook) {
  if (isset($vars['node'])) {
  // If the node type is "blog" the template suggestion will be "page--node--blog.tpl.php".
   $vars['theme_hook_suggestions'][] = 'page__node__' . str_replace('_', '--', $vars['node']->type);
   }
}

```

With this function I got a tweakable and customized page.tpl.php. Now I only need to change the $logo value for this content type or add extra settings to the theme, as hard-coding the url path for the alternative logo seems inelegant :)

# Answer
The simplest way would be to create a tpl for the content type to do that you can follow the below steps

First create a preprocess\_page function as given below. This would go into the template.php file.

```
function YOURTHEMENAME_preprocess_page(&$vars) {
  if (isset($vars['node']->type)) {
    $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
  }
}

```

now you can create a new page.tpl per content type something like

```
page__CONTERNTTYPENAME.tpl.php

```

You can copy the entire content of the existing page.tpl.php into this and replace the logo with the desired logo.

in zen theme the logo is in the page.tpl is printed as follows

```
<?php if ($logo): ?>
      <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo"><img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" /></a>
    <?php endif; ?>

```

here you can replace the image src with the direct path to your logo.
> 4 votes

---
Tags: 7, theming, nodes
---


# Question
Title: how to change the background image based on the node (the hard way)
I'm trying to change the background image of my site based on what node the user is viewing (not just what node type, but specifically what node). I have added an image field to my node type called background image. Basically, I'm trying to go into my html.tpl.php file and inject a style right into the body tag, for isstance

```
background-image:url('../images/mybg.jpg');

```

I'm hoping to grab the image field from node that is loaded, but I'm having trouble figureing out hoe to access a nodes field from the html.tpl.php file (i need to do it from here becuase that's where the body tag is). I've added a pre-process function to my template to try and find the correct field, but i've hit a dead end

```
function mytheme_preprocess_html(&$vars) {
     dpm($vars);
}

```

the array that is traced makes no sense to me, and I'm unable to find the field. Is there a better way to do this

# Answer
> 4 votes
The simplest (not necessarily the cleanest) way to do this is:

```
function mytheme_preprocess_page(&$vars) {
  $node = menu_get_object();
  if ($node->nid) {
    // We're on a node page
    if (isset($node->field_background_image[$node->language][0]['fid'])) {
      // Load the file object
      $file = file_load($node->field_background_image[$node->language][0]['fid']);

      // Get a web accessible URL for the image
      $path = file_create_url($file->uri);

      // Add the background to an inline CSS tag
      drupal_add_css('body { background:url(' . $path . ') left top no-repeat !important; }', 'inline');
    }
  }
}

```

# Answer
> 1 votes
Here was the function I used

```
function mytheme_preprocess_page(&$vars) {
    if (isset($vars['node']->nid)
    {
        $uri = $vars['node']->field_background_image['und'][0]['uri'];
        $path = file_create_url($uri);
        drupal_add_css('body { background:url(' . $path . ') left top no-repeat !important; }', 'inline');
    }
}

```

# Answer
> 0 votes
I tried to use the code above but could get no results. no errors but no results. I am using drupal 7 with the versatile HTML5 sub-theme of versatile. It may have had something to do with the theme but I doubt it. what I did to get it to work is change the function from mytheme\_preprocess\_page to mytheme\_preprocess\_node seeing as it is nodes we are pulling this from anyway. the rest is the same. oh and there is a ) missing on line 2. Thanks for the code it was just what I was looking for.

---
Tags: 7, theming
---


# Question
Title: How to edit a field--field-xxx.tpl file when the content is rendered with Display Suite?
I want to show up to 3 images in my teasers. For that I override the `field--field-image.tpl` file in my theme directory and it works perfectly.

```
<?php

if ($element['#view_mode'] == 'teaser') {
    $items = array(array_slice($items, 0,3));
    }

    print "<div class=\"gallery-thumbs\">".render($items)."</div>";
?>

```

I would like to use a Display Suite layout instead for the teaser, but the `field--field-image.tpl` has no effect anymore. Where should I put this code to achieve the same effect (up to 3 thumbnails) using a Display Suite layout?

# Answer
I am a little bit ashamed, but if the issue occurs to someone else, it is not even necessary to write code. There is a dedicated field in the manage display interface.
> 2 votes

---
Tags: theming, display-suite
---


# Question
Title: where is the breadcrumb printed at in the omega kickstart theme?
can someone tell me where omega kickstart breadcrumb is printed in code I have looked in the templates dir and there dosent seem to be a page.tpl.php and the template.tpl.php in the main dir dosent have it either I want to move it to just over the content

# Answer
> 1 votes
By default it's printed in in the `omega/templates/zone--content.tpl.php` template file in the Omega theme itself.

```
<?php if ($breadcrumb): ?>
  <div id="breadcrumb" class="grid-<?php print $columns; ?>"><?php print $breadcrumb; ?></div>
<?php endif; ?>

```

---
Tags: theming, breadcrumbs
---


title: Login link with destination

text:
# Question
Title: Login link with destination
I am trying to create a login link in Drupal 7 that will

* keep the destination if set
* generate a destination based on the page on which the link was clicked if not set
* persist if set on subsequent clicks of the login link
* not be generated if not already set AND the currently viewed page is an undesirable destination (such as user/logout)

I have written the following code and put it into to the body of a block only shown to anonymous users, however, as I am new to Drupal's api can someone more knowledgable here check to see if this is OK or can be optimized, and/or what other destinations other than user/\* should NOT generate a destination if the destination is not already set:

```
<a href="/user<?php $curpath = current_path();
if (strpos($curpath, 'user/') === 0 && !isset($_GET['destination'])) {
  print '';
}
else {
  $newdest = drupal_get_destination();
  $newdestimplode = implode('', $newdest);
  print '?destination=' . drupal_get_path_alias($newdestimplode);
} ?>">Login</a>

```

Alternatively if you know of a setting that puts the login link on pages for anonymous users with the above conditions or a LIGHTWEIGHT module (please don't suggest LoginTobboggan) that does this, let me know here.

# Answer
I wrote this THEME\_menu\_link override to add a destination parameter to login links:

e.g in `template.php`:

```
/**
 * THEME_menu_link override
 * Add unique class (mlid) to all menu items.
 * Add destination param to login link
 */
function THEMENAME_menu_link($variables) {

  $element = $variables['element'];
  $sub_menu = '';

  $element['#attributes']['class'][] = 'menu-' . $element['#original_link']['mlid'];

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  // Add destination to login link
  if ($element['#href'] == 'user/login') {
    $status = drupal_get_http_header('status');
    // don't add dest back to 403 etc..
    if(strpos($status, '403') !== FALSE){
      $dest = drupal_get_destination();
    }elseif(strpos($status, '404') !== FALSE){
      $dest = array('destination' => 'home');
    }elseif(strpos($_GET['q'], 'user/register') !== FALSE){
      $dest = array('destination' => 'home');
    }elseif(strpos($_GET['q'], 'user/login') !== FALSE){
      $dest = array('destination' => 'home');
    }elseif(strpos($_GET['q'], 'user/logout') !== FALSE){
      $dest = array('destination' => 'home');
    }else{
      $dest = array('destination' => drupal_get_path_alias());
    }
    $element['#localized_options']['query'] = $dest;
    $element['#attributes']['class'][] = 'login';
  }

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

```
> 2 votes

---
Tags: 7, users
---


title: Best approach to set up a collection

text:
# Question
Title: Best approach to set up a collection
I've got a bunch of internet links with the properties "Name", "Description", "URL", "Banner (image)" and "Category".

What is the best approach in Drupal to get these organised? Should I create a content type for it and then use e.g. Views etc. to format the output or is there a better way, maybe a module?

# Answer
Create a content type, e.g "Website"

Add fields:

1. URL ( link field )
2. Banner ( image field )
3. Category ( term reference field, create taxonomy vocab 'Category' first )

Name and Description will be the default node title and body fields

After that, you can create / manage your content.

Use Views and/or Panels to control the output on your site.
> 3 votes

---
Tags: nodes
---


title: multi page content drupal 7

text:
# Question
Title: multi page content drupal 7
So i want to create a website which presents information about topics over multiple pages, i.e. say the content was films, one page would be an overview of the film and there would be a button at the bottom which would pull up the films cast etc (think like a multi step signup form).

My current thinking is I could create this as a series of views so have like one view that links to %film/overview, %film/cast etc. As I am still pretty new to drupal I thought I would ask here whether this was the best way to present this type of content, or if there are better options?

Thanks.

# Answer
The Best way is to do it with core Book module

> A book is a set of pages tied together in a hierarchical sequence, perhaps with chapters, sections, subsections, and so on. You can use books for manuals, site resource guides, Frequently Asked Questions (FAQs), or whatever you'd like.
> 1 votes

# Answer
You could build a solution using either:

1. Quicktabs \+ Views
2. Field Group ( client-side multipage-step fieldgroups )

For the user interface effects there.

i.e tabbed widget or next/prev field groups.
> 0 votes

---
Tags: 7, views, forms
---


# Question
Title: Use views to display taxonomy children terms from parent
I'm hoping there might be a solution to this, but I do not have too much hope after searching a bunch. Currently I have some articles that have terms associated with them and these terms are 2-3 levels deep. For example I might have 10 articles that have the term 'green'.

```
-Fruit
--Apple
---Green
---Red

```

I then would like it to have the user be able to view all the video's associated with a specific taxonomy term including all of its children. So if the user goes to www.site.com/fruit/apple, then **ALL** of the apples will show (Both Red and Green).

Here is the problem. I can only make it work if I assign each article all the parent terms leading up to the child term, but unfortunately, the way that my site is constructed, I can only have it so that my article has the deepest term associated with it.

Does anyone know if it's possible to create a view that will look at all the children of a term and include that in the view? I hope I am explaining it correctly. :)

Ex. User goes to www.site.com/fruit/apple and then they get all the articles that are only tagged with 'green' and only those with 'red'.

Thanks guys!

P.S I have hierarchical select installed, but that does not help me because I cannot have it assign parent terms to my articles. So that won't work.

# Answer
With in view there is a an option to add a contextual filter **Content: Has taxonomy term ID (with depth)** There you can select the depth of till which you wan to show the children. So if you select say 5 all the child nodes till a depth of 5 would be shown. I think that should do what you are looking for.
> 14 votes

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


# Question
Title: Attachment of Taxonomy Term Description shows All descriptions on term page instead of only one
I created a View page to display a sortable table of Category | Model | Brand | Price. Each product has it's own content types that has all of these fields entered. Category is a List, Model is the title field, Brand is a term reference, and price is an integer field.

I created a page view from the data of of this Product Content type and used contextual filters to display different views of tables at the /category and the /brand level. Because I had some trouble getting two contextual filters to work on the same Page view, I created a new page view \[Brand\] for the contextual filter for the Brands taxonomy terms. (see question and comments here: Can you display data dynamically from a textfield in the URL and Name of Views?)

Now I created an Attachment to attach to the Brand view. I created the attachment because I would like the Term Description to be above the Brand view that displays the Product Category / Model / Price for each Brand generated by the view. The trouble is that I am getting the description of every brand printed instead of just the brand currently being displayed on the page. Does anyone know what might be causing this issue? I feel like I need a specific filter for this to work.. I've tried different configurations that produce the same result.

Below are my screenshots:

https://i.stack.imgur.com/6gTcI.png --\> The attachment

https://i.stack.imgur.com/S20sQ.png --\> The page view for the taxonomy term

# Answer
> 0 votes
You need to add a contextual filter to the attachment view. This should be the taxonomy ID. And you have to set the **Inherit contextual filters:** to **Yes**

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


# Question
Title: How to create a taxonomy terms "skills" with level "low", "medium", "high"
I'm trying to create a field that allows you to add your skill from a select list, and the level of your skill.

i.e. skill football, level medium.

I may create the taxonomy in this way Football -Low -Medium -High and the use hierarchical taxonomy but it means that I need to add the level per each term.

Is there a way to attach a vocabulary to another vocabulary? in this way I may create a vocabulary skills with all the skills and one vocabulary level with 3 terms. Is there a module or a better technique?

Thanks in advance

# Answer
> 1 votes
Yes, that type of field configuration is possible with

http://drupal.org/project/conditional\_fields

version is -dev for D7 but works well.

# Answer
> 1 votes
Without knowing how you're planning to use this in a larger context, here's what I would do:

1. Create a vocabulary (or possibly just a plain text field with a select list) for "skill"
2. Create a second field with a dropdown list for skill level (I probably wouldn't use a taxonomy for this).
3. Make the second field dependent on the first, per this Stackoverflow question about fieldsets and conditions

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


title: When is it necessary to check_url()?

text:
# Question
Title: When is it necessary to check_url()?
When is it necessary to use check\_url()? For instance, if I create a login link by putting the code below in the body of a block, which of the 3 check\_url() calls are necesssary and which ones are not?

```
<?php print '<a href="/user?destination=';
if ((preg_match('#^user(?:$|/login$|/logout$|/register$)#',
  check_url(current_path())) && !isset($_GET['destination'])) ||
  preg_match('#^user(?:$|/login$|/logout$|/register$)#',
  drupal_get_normal_path(check_url($_GET['destination']))) ||
  drupal_get_http_header('Status') === '404 Not Found') {
    print 'homepage';
}
else {
  print drupal_get_path_alias(check_url(reset(drupal_get_destination())));
}
print '">Login</a>';
?>

```

# Answer
> 1 votes
If you just use l($text, $path, array $options = array()) you can simplify your code and it will take care of check\_url for you.

---
Tags: 7, security
---


# Question
Title: Deleted all the content... but it's all still there?
I wanted to start from scratch so deleted all the content from my Drupal site. Now I am getting the following error:

Notice: Undefined index: name in system\_sort\_modules\_by\_info\_name() (line 949 of /Applications/XAMPP/xamppfiles/htdocs/drupal/modules/system/system.admin.inc).

Also, even though I deleted all the content, it is still appearing under the Menus. Do I need to manually remove it from the menus as well? I was hoping that deleting the nodes/content would automatically remove it from the menus...

I deleted the content by going to Administration » Content, selected all the pages/nodes and them selected the "delete selected content" option.

# Answer
> 0 votes
That `Undefined index: name in system_sort_modules_by_info_name()` error sounds like a broken module not defining its name in its .info file

One possibility is from coder/coder\_sniffer/Test/bad.info

see: http://drupal.org/node/1015368

---
Tags: theming
---


# Question
Title: No access stats for user after registration
Just noticed a new user who joined today has in access stats, "never". How can that be recording never when they have logged in? drupal 7.19 core profiles.

# Answer
> 4 votes
Usually a state "never" means that the user has registered but they have never logged in with their username/password

---
Tags: users
---


# Question
Title: A Rule component to change author on nodes?
I am looking to create a rule's component to allow users to bulk modify the author value on nodes using VBO. Any insight on how I what this component part in rules would look like? The action must allow the user to define whatever author they wish either using a textfield or a list of available accounts on the site in VBO.

# Answer
1. Create a view listing the content that you want to edit.
2. Add a bulk operation in fields

3. Select change the author of the content

4. Go to your view to select the nodes for which you want to change the author

5. Select the author who should be made the new other for all these content.
> 2 votes

---
Tags: 7, rules, views
---


title: 404 error on AJAX file upload

text:
# Question
Title: 404 error on AJAX file upload
I get 404 errors on file uploads on a D7.19 website. The displayed error is the usual oversized file but I'm sure it's unrelated (see below).

Here is the apache log message :

```
POST /file/ajax/field_photos/und/form-YJgDfzca9S88uWmWhrE2GGYBM_sIEKXLGvVKQD34xeU HTTP/1.1" 404 1563 "http://dev.domain.com/node/add/animal" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17"

```

I'm sure the server setup is OK because some other sites hosted on it have AJAX working flawlessly.

Disabling Javascript makes file uploads work OK, so it's definitely some Javascript getting in the way somewhere.

What I tried yet :

* changing JQuery version (update or no update)
* put the website in english (prod will be in french)
* disabling any compression and caching
* enabling any compression and caching
* disabling some modules (Superfish, dev modules, UI stuff)
* different browsers : error is the same everywhere (Safari, Chrome, Firefox).

... and browsed the web like crazy, not finding anything about this precise error.

The only vague hint I have is a file called jquery.cookie whose code doesn't seem to be aliased correctly (`(function ($) { // code here })(jQuery);` ) but I doubt it could be it.

At this stage, any idea would be welcome. The website is supposed to go live tomorrow (!).

# Answer
Solved it !

Explanation :

A file with a name like `'file.xxx'` was present at the root of the site. I removed it and everything started to work.

I then put back an empty file named `'file.txt'` at the root of the website, and the same error rose again.

It can happen more often than it seems. In my case, I downloaded a patch for the filefield module which was named `file_something.patch` and forgot to delete it after applying. Easy to do, easy to forget, hard to remember once you've moved on to something else.

Bottomline : keep your webroot clean of anything not Drupal or you're in for trouble. Can't believe I lost two days with such a simple problem.

Thanks to Mohammed Shameem for his try, and to anyone who gave this a thought.
> 2 votes

---
Tags: 7, ajax, files
---


# Question
Title: How to build a dynamic hyperlink within a Page (Panels)?
On a Drupal 7 Site with Panels and Tokens I have a content-type for Events. For the "Page" (Panels) of a Event I like to add a hyperlink / button to add the event to the personal Google Calendar. This requires to build a hyperlink with some query-parameters in it. Eg:

```
<a href="http://www.google.com/calendar/event?action=
  TEMPLATE&text;=Brunch at Java Cafe&dates;=20060415T180000Z/
  20060415T190000Z&location;=Java Cafe, San Francisco, CA
  &details;=Try our Saturday brunch special:<br><br>French
  toast with fresh fruit<br><br>Yum!&trp;=true&sprop;=
  website:http://www.javacafebrunches.com&sprop;=name:Jave Cafe">

  <img src="//www.google.com/calendar/images/ext/gc_button2.gif">
</a>

```

My approach is to create a custom block with "Full Html" and add the above snippet. Then add tokens like \[node:title\] that should get replaced with the node's title etc. Afterwards I add this block to the Events page (Panels). The problem is that the tokens don't get replaced.

Any idea how I can build this links the most easiest way?

Thanks for help, Marc

**Update:** Got one step forward: I don't use a block but a "Custom Content" pane from Panels. Within this replacement is supported. The problem I now have is that the date/time doesn't get formatted right. I use "date" field-type (Date module). Any idea how I can format that date correctly?

# Answer
> 2 votes
You would want to override the template for the content type you're using, in your theme. If you're using a base theme, copy the node template into your theme and then change it there (don't change the base theme directly). More info on phptemplate and theming is on Drupal.org.

If you don't code, doing this in a View would work. Here's what I would do:

1. Create a content type with plain text fields for all the things you need to make dynamic (if you haven't already done this)
2. Create a View that only displays one item at a time.
3. I'm not sure what your setup is exactly like, so it may take some creativity to filter it to display the right one. You might want to try something like References to relate an Event node to your particular node of your new content type, or configure some contextual filters to pick the right values based on the URL of the Event page, or something.
4. Have your View create a Block and have that Block display on Event nodes
5. Configure your View to rewrite output of a field and make all other fields excluded from display. Views seems to have the peculiarity of only allowing you to use tokens from fields that were added to the display before the field being rewritted so use the last one added.
6. ????
7. PROFIT

But that's a ton of work. You're better off going with the phptemplate option.

# Answer
> 1 votes
Your best bet is to add a new "Ctools content type" that generates your link with l(). I have a tutorial on that over in How does one create a new Ctools plugin.

---
Tags: 7, panels
---


# Question
Title: Colorbox isn't working, although all settings are correct
I'm having a bit of an issue over here. I've installed the Colorbox module like it should (install the library & the module, like described in the documentation), the HTML is generated as it should, but the colorbox module doesn't activate at all...

This is the HTML:

```
<a href="path/to/image" class="colorbox">
  <img src="path/to/image" />
</a>

```

but still, I don't see any colorbox...
Is there something I forgot or oversaw on my install?

# Answer
> 1 votes
Try the following with colorbox:

1. Do you have the latest version? If you updated recently to version from colorbox notice that in the module page says Changes since 7.x-2.1: Important: When updating to this version of the Colorbox module you need to update the Colorbox plugin to v1.3.21.1 or later as well.
2. Mohammed Shameem mentioned in the comments above is valid. He remark the following: please note that colorbox 1.3.26 and 1.3.27 had an error due to which the script was not working with older version of jQuery so you should download the latest version.

However, the version of colorbox included in the Drupal 7.x colorbox module is NOT STATED.

---
Tags: 7, javascript
---


# Question
Title: Select from list or create other structured data in form field
I want to let users choose from a list of checkbox items, and I want users to be able to build their own options, if the options they want aren't in the list of checkboxes.
I'd like users to have the ability to build as many "custom" selections as they'd like.

The value is compound, so http://drupal.org/project/select\_or\_other won't cut it.

Is there a good module for this or a FAPI approach? It seems like this is close.

Here's a pseudo interface for illustration:

Select:

\[\] 1 liter(s)

\[\] 2 liter(s)

\[\] 1 gallon(s)

\[\] 2 gallon(s)

Or other(s):

\[ *(textbox that accepts number)* \] \[ *(dropdown that lets you choose liter(s) or gallon(s))* \] \[Add\] \<--a button

# Answer
After some digging I found Field group and Field collection. After testing both, I found that Field collection is more or less exactly what I was hoping to find in a module. It's still in beta, but seems to be working great for me.
> 0 votes

# Answer
You should check the examples module. Especially the ajax module. there is an example called **Generate checkboxes** This would lead you to the right direction.

The process would go as follows. You create the basic form then use create a button with Ajax call back. and return the required check box using the callback function.

This is the relavent function that generated the form.

```
function ajax_example_autocheckboxes($form, &$form_state) {
  // Since the form builder is called after every AJAX request, we rebuild
  // the form based on $form_state.
  $num_checkboxes = !empty($form_state['values']['howmany_select']) ? $form_state['values']['howmany_select'] : 1;

  $form['howmany_select'] = array(
    '#title' => t('How many checkboxes do you want?'),
    '#type' => 'select',
    '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4),
    '#default_value' => $num_checkboxes,
    '#ajax' => array(
      'callback' => 'ajax_example_autocheckboxes_callback',
      'wrapper' => 'checkboxes-div',
      //'method' defaults to replaceWith, but valid values also include
      // append, prepend, before and after.
      // 'method' => 'replaceWith',
      // 'effect' defaults to none. Other valid values are 'fade' and 'slide'.
      // See ajax_example_autotextfields for an example of 'fade'.
      'effect' => 'slide',
      // 'speed' defaults to 'slow'. You can also use 'fast'
      // or a number of milliseconds for the animation to last.
      // 'speed' => 'slow',
      // Don't show any throbber...
      'progress' => array('type' => 'none'),
    ),
  );

  $form['checkboxes_fieldset'] = array(
    '#title' => t("Generated Checkboxes"),
    // The prefix/suffix provide the div that we're replacing, named by
    // #ajax['wrapper'] above.
    '#prefix' => '<div id="checkboxes-div">',
    '#suffix' => '</div>',
    '#type' => 'fieldset',
    '#description' => t('This is where we get automatically generated checkboxes'),
  );

  for ($i = 1; $i <= $num_checkboxes; $i++) {
    $form['checkboxes_fieldset']["checkbox$i"] = array(
      '#type' => 'checkbox',
      '#title' => "Checkbox $i",
    );
  }

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

  return $form;
}

```

There are couple of other examples related to the form api in the examples module that you can check out as well.
> 2 votes

---
Tags: forms
---


title: Adding titles to sorted nodes in a View

text:
# Question
Title: Adding titles to sorted nodes in a View
So I'm struggling again with my sorted links: there are many many links (node type) which also contain the field "link\_category".

I collect them all in a view and sort them by "link\_category".

It works like a charm and looks like this:

```
link 1 | Category 1
link 2 | Category 1
link 3 | Category 1
link 1 | Category 2
link 2 | Category 2
link 3 | Category 2
link 4 | Category 2
link 1 | Category 3
link 2 | Category 3
link 3 | Category 3

```

but now I want to hide the link\_category on each item and instead, show one title above them like:

```
*Category 1:

link 1
link 2
link 3

*Category 2:

link 1
link 2
link 3
link 4

*Category 3:

link 1
link 2
link 3

```

Is it somehow possible with Views or do I need some extra modules?

# Answer
> 2 votes
You can use the group by field option.

The process would go as follows.

In Fromt section next to the Format you have settings click on that.

You will find **Grouping field Nr.1** Select the category Field from the list.

This would group the fields with the Category. But Now you would see both category as well as Link. Now you can go to the Category field settings and select exclude from Display so that only the links would be shown.

---
Tags: views
---


title: Link path auto url to view field

text:
# Question
Title: Link path auto url to view field
Does anyone know if its possible to attach a link to a specific node in a custom view and have that link be the path auto link?

I have a custom view that pulls in a title text field from an article. I want to have that text field be a link to go to that article and I only seem to be able to create a link to the node via a token the references the 'Content: nid' which outputs my link as www.site.com/node/66. I instead need the path to be my pathauto link.

Is this possible?

# Answer
Add a field **Content: Path** This would add another token which would be the aliased path of the node you can use that.

Please note that to use a token with in view the field should be above the field being used.

By the if you just want to Link the Title to its node then you can simply tick **"Link this field to the original piece of content"** This would link it to the article that the Title points to with the aliased url
> 2 votes

---
Tags: 7, views, tokens, path-aliases
---


# Question
Title: Can a Calendar, based on two different content types, output different html based on content type
I built a calendar based on two different content type, let's call them A and B. For each type I output the Title field and, along with it, I'd like to have a link to the node if the Title field belongs to type A and just plain text if it belongs to type B. Is there a way to do this?

# Answer
You could use the Views PHP module.

Then add the content type to the view. You can exclude both content type and title from the the view only display the title through the Global PHP field. With in that you can place a condition to display the complete link if it is of Type A and only the Title if it is of Type B. You could also add the path to the node as a views fields if you prefer so that it can be used in the as href for the link in php field.
> 1 votes

---
Tags: views, datetime
---