# Question
Title: How can I add a simple node creation form to a page?
I'm trying to add a formspring-like page to my website. This looks like an easy task for Drupal 7: create a new content type, create a new view to list the questions and answers, add another view to the backend to view the unanswered questions, and you're ready to go.

But I have one remaining problem: how can I add a simple form to ask a new question? I want to have a simple form on top of the list-page, with just 1 input box where a visitor can ask his question and a submit button.

I've already found the "form block"-module, but I can't trim the output of the form to just 1 input box. Is there an off-the-shelf solution, or do I have to create a custom module/block that programmatically creates a new node?

# Answer
the only way I can see this being possible, would be creating a custom node/add page for your content (see How can I theme the template for edit or add a node for a specific content type?) and then using Panels to create a custom page with your node on top and then your view directly below.

I would be interested to know if anyone else has any better/easier suggestions of course. +1 for question :)
> 1 votes

---
Tags: 7, nodes, forms
---


title: Any alternative for webform_mysql_views

text:
# Question
Title: Any alternative for webform_mysql_views
I am using postgresql as database. I want to create views of webform submissions. is there anything similar to webform\_mysql\_views for postgresql.

# Answer
Maybe you could use the Data module.

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

---
Tags: views, 6, webforms
---


title: How to import Excel file to CCK nodes?

text:
# Question
Title: How to import Excel file to CCK nodes?
Is there a way to import a Excel file into CCK nodes?

* Each Excel file contains only a single sheet
* First row of there sheet is header
* Data are only strings, numbers, and decimal numbers
* It's a daily task which will be performed by a user

# Answer
You'll probably have to save your Excel file to CSV format to be able to import more easily. Two options:

* **Node Import**: You can certainly import CSVs with this, and I've used it successfully for huge spreadsheets before -- it's powerful, helpful and quite easy.
* **Feeds**: Much more complex to get going than Node Import, but Feeds can in theory do everything you want and *much* more. Can also update existing nodes.

Either of these will allow you to import CSV data (exported from your Excel document) to nodes and their CCK fields.
> 2 votes

# Answer
I use iMacro as a general solution to fill a lot of forms.

It is an addon for firefox that allows one to record and play macros.

Here is a link that explains how to fill forms from csv files: http://wiki.imacros.net/Form\_Filling.

The advantage of this method is that the form filling will follow all the flow a normal user filled form would. Javascript formatting, for instance, will be applied to the user input.

The disadvantage is that it is a rather slow method. It takes some time to prepare the macro and it may take a lot of time to perform the operation if you have a very large set of data.
> 0 votes

---
Tags: nodes, 6, importing-exporting
---


title: Sort by taxonomy term name in Views?

text:
# Question
Title: Sort by taxonomy term name in Views?
So I feel like I must be missing something obvious, but I can't find a solution to my situation. I'm trying to sort some nodes by the chosen taxonomy term name. This is Drupal 7, Views 3.

I have a taxonomy vocabulary 'Country' that is setup something like:

```
Asia
--Bangladesh
--India
--Vietnam
Afria
--Algeria
--Libya
--Nigeria

```

On the content type ('Partners') I have a taxonomy field called field\_country. I happen to be using the Hierarchical Select module to make sure that, for this field, only the deepest levels are chosen (countries, not regions).

So all of that works and I can display the country chosen as a field in the view.

But I can't seem to figure out the correct way to sort by that country name. When I add the field\_country field to the sort criteria, the ordering doesn't make sense. When I check the SQL statement it actually shows that it is sorting by field\_data\_field\_country\_field\_country\_tid. So it seems to be sorting by the tid rather than the actual term value. Although, a quick scan of the tid values shows that it isn't even sorting correctly by tid!

Here is what the SQL looks like:

```
SELECT DISTINCT node.nid AS nid, node.title AS node_title, field_data_field_country.field_country_tid AS field_data_field_country_field_country_tid, 'node' AS field_data_field_location_node_entity_type, 'node' AS field_data_field_country_node_entity_type, 'partners:block' AS view_name
FROM
{node} node
LEFT JOIN {field_data_field_country} field_data_field_country ON node.nid = field_data_field_country.entity_id AND (field_data_field_country.entity_type = 'node' AND field_data_field_country.deleted = '0')
WHERE (( (node.status = 1 OR (node.uid = 1 AND 1  0 AND 1 = 1) OR 1 = 1) AND (node.type IN  ('partner')) ))
ORDER BY field_data_field_country_field_country_tid ASC
LIMIT 9 OFFSET 0

```

Any suggestions? Is there a magical relationship I have to activate to get the correct sort option available?

Thanks!

# Answer
> 14 votes
Wow do I feel stupid today. I've done this before, but just seemed to have a brain issue.

Very simple:

1. Add a relationship for "Taxonomy: Terms on node". Select the country vocabulary.
2. In the sort criteria, select "Taxonomy term: Name" (I believe this gets added by step 1) and make sure the correct relationship choice is selected.

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


# Question
Title: How can I allow users to search for other users based on profile information
I have two profiles for my users. First, is "Infomation" machine name "main" and second "About Me" machine name "about\_me" and I want to create a page where other users can search for users with specific attributes in their "Information" or "About Me" profile. I'm just starting out with drupal 7.10 so any help would be appreciated.

# Answer
> 1 votes
I achived this by making a view called "Search Users". I couldn't figure out contextual filters so I tried using "Fields Criteria."

I first selected that I wanted the field to show users. Then I added the fields that I wanted. Then I added the field criteria that I wanted to filter by and check "Expose this filter to visitors, to allow them to change it." That was all I needed to do.

# Answer
> 1 votes
You can achieve this by using views contextual filters.

or you can use advanced search for users

```
http://www.yoursite.com/search/user

```

set the user permission accordingly to view advanced search

---
Tags: users
---


title: How can I use field_attach_load()

text:
# Question
Title: How can I use field_attach_load()
> **Possible Duplicate:**
> Listing entity fields

I want list fields of my content type(example: blog), so as described at Drupal API reference, I should pass $entity\_type and $entities to this function.

I know $entity\_type is 'node', but how can I fill $entities? I should fill $entities with bundle of "blog" so I should know the bundle ID. How can I know bundle ID for blog?

# Answer
> 3 votes
If you want the list of fields per content type (now bundles in Drupal 7), you should use `field_info_instances()`.

```
//List all fields of bundle "your_content_type" using devel module
dsm(field_info_instances('node', 'your_content_type'));

```

---
Tags: 7, entities
---


# Question
Title: How do i use hook_menu to add a menu item into an exisiting menu
as the title says i'm trying to add a menu item to the user-menu. I'm using the following code:

```
function sawqr_menu() {
    $items['user/%user/qr'] = array(
            'title' => t('QR Code Management'),
            'page callback' => 'sawqr_view_embed',
            'page arguments' => array('qr_codes', 'page'),
            'access callback' => 'user_access',
            'access arguments' => array('Administer SAWQR'),
            'menu_name' => 'user-menu',
            'type' => MENU_SUGGESTED_ITEM,
            'weight' => 0
    );

    return $items; /// forgot to add this from my module
}

```

# Answer
> 2 votes
If this is your real code, then you're missing the `return $items;` line at the end, looks good otherwise :)

Edit: You are using `'type' => MENU_SUGGESTED_ITEM` which means that the menu item needs to be enabled manually in the administration. And when you do, it will show as a sub menu item of /user/%user, which basically means it is invisible because there the default secondary menu position only displays top-level menu items. Try MENU\_LOCAL\_TASK instead to have it show up as a local task.

P.S.: permission strings are usually all lowercase (they are a technical identifier, not a user facing label or so).

# Answer
> 0 votes
`hook_menu()` needs to return `$items` in order to work.
I get tripped up by that a lot.

---
Tags: routes, hooks
---


# Question
Title: Modules needed to create the best WYSIWYG experience?
What do you use to give the end user (editor) the best WYSIWYG experience, considering the following requirements (besides basic input):

* Insert images/flash and align then left/center/right with optional caption, choice of sizes
* Easily upload files and add links to them
* Add custom css classes to content
* Add custom buttons that provide custom/special formatting
* Be truly WYSIWYG, i.e. using styles/typography that the end user will see

From a developer/maintainers point of view:

* Keep front-end theme styles in-sync with styles used in WYSIWYG editor

Thanks, Egil.

# Answer
You will need the Drupal WYSIWYG module http://drupal.org/project/wysiwyg and the TinyMCE Library here http://www.tinymce.com/

TinyMCE supports plugins and you can make that "best WYSIWYG experience" that you are looking for. You can hook it up with your theme CSS and apply styles to the text aeras and see them in the WYSIWYG. Also check the WYSIWYG plugins page http://drupal.org/node/1197256
> 1 votes

---
Tags: input-formats, wysiwyg
---


title: Change "Add to bag" to "Add to cart"

text:
# Question
Title: Change "Add to bag" to "Add to cart"
In the following website, I want to change the string from "Add to bag" to "Add to cart." I am using Drupal 6 and Ubercart.

How could I change it?

# Answer
You can change this in Ubercart settings using no extra modules...

Go to `/admin/store/settings/products/edit/general`, which is in **Store administration -\> Configuration -\> Product settings -\> Edit -\> Product settings** in the menu.

The text for 'Add to cart' is editable in the `Add to cart button text` section.
> 5 votes

# Answer
You can also try the String Overrides module for tweaking the label from any Drupal module or theme.
> 2 votes

# Answer
Install the Theme Developer module, and point and click on the text. You'll get the theming method or template you have to overwrite/create to tweak the UI to your needs.
> 1 votes

---
Tags: 6, theming, ubercart
---


# Question
Title: What is the best method to customize the display of author information on a node of a certain type?
Requirements: For nodes of a certain type (blog), I need to show the author information with the author image using a specific Image Style, the user name, the user profile description, and another custom user field.

The method I'm currently using is implementing theme\_preprocess\_node() to create a variable to pass to my node--blog.tpl.php file that includes the elements I need themed. This means I have calls to theme\_image\_style() in my theme\_preprocess\_node() function.

Is this the best method, or is there a "more Drupal" approach I'm missing?

If it helps, here is a snippet of code:

```
/**
 * Hook theme_preprocess_node
 */
function hotness_preprocess_node(&$vars) {
  // for blog posts, style date and show intro image
  $node = $vars['node'];
  if($node->type == 'blog') {
    // nice date
    $vars['date'] = format_date($node->created, 'custom', 'F j, Y');

    // use image style for blog image
    $vars['blog_image'] = NULL;
    $blog_image = isset($node->field_blog_image['und'][0]) ? $node->field_blog_image['und'][0] : FALSE;
    if($blog_image) {
      $vars['blog_image'] = theme_image_style(array(
        'style_name' => 'introduction-image',
        'path' => $blog_image['uri'],
        'width' => $blog_image['width'],
        'height' => $blog_image['height'],
        'alt' => $blog_image['title'], // to make it easier to the end user I just show title
        'title' => $blog_image['title'],
         'attributes' => array('class' => 'blog-image')
      ));
    }

// I use user_load() because the node object doesn't have the user description.
$author = user_load($node->uid);

$author_image = '';
if(isset($author->picture->uri) && !empty($author->picture->uri)) {
  $author_image = theme_image_style(array(
    'style_name' => 'blog-author-image',
    'path' => $node->picture->uri,
    'width' => NULL,
    'height' => NULL,
    'alt' => t('User .') . $node->name,
    'title' => t('User ') . $node->name,
    'attributes' => array('class' => array('author-image')),
  ));
}

$author_name = l($node->name, 'user/' . $node->uid);
$author_desc = isset($author->field_description['und'][0]['safe_value']) ?
  '<div class="author-description">' . $author->field_description['und'][0]['safe_value'] . '</div>': '';

// put it all together
$vars['author_block'] = $author_image . $author_name . $author_desc;

```

} }

# Answer
In your code at

```
 $node->field_blog_image['und'][0]

```

this is still an array so you need to access the value of the field one more level deep in to that array you can access it as follows.

```
$node->field_blog_image['und'][0]['safe_value']

```

Rest of code looks good to me.
> 1 votes

---
Tags: 7, theming
---


# Question
Title: How to make a region available to a non-page tpl file?
I'm working with a custom theme (which I did not develop.) We're wanting to add a block to a specific node type, which has a template called node-session.tpl.php. This template prints out all kinds of internal html and php, but is framed by the page.tpl.php file. The node-session.tpl.php contains the code that's printed by the $content variable in page.tpl.php.

I have a new block (created by the AddThis module) that needs to be positioned on the page such that it's nested inside a div created in the node-session.tpl.php. Unfortunately placing the region inside that file doesn't work, and in fact just testing for the variable $add\_this itself returns false. According to all the documentation I can find, region variables are available to page template files only. Is there a way I can make the variable available to the node-session.tpl.php file so that I can position the block correctly?

# Answer
Sure, you can use a node\_preprocess() hook to create the variable much like this:

```
function mytheme_preprocess_node(&$variables) {

   // whatever else you are doing goes here

   $block = module_invoke('AddThis', 'block', 'view', 0);
   $variables['mynewblock']=$block['content'];

}

```

which would call the AddThis module to invoke it's block hook and return block with delta 0.

Lots more detail can be found here: http://www.pixelclever.com/how-insert-a-block-a-tpl-or-content-programmatically-with-drupal
> 1 votes

---
Tags: blocks, theming
---


title: Ubercart add custom price product?

text:
# Question
Title: Ubercart add custom price product?
I want to add a Gift Card product to my Cart but assign a value the user typed in (so for example Product ID 3 would be gift card for $1, and I would then make it $25,$50, and so on).

How can I do this? I looked at uc\_cart\_add\_item but it is just NID, and I don't want to make 500 different products for each amount possible.

Any help!?

# Answer
Have you looked at the Variable Price module? http://drupal.org/project/uc\_varprice

It's ostensibly for donations, but I think it might be customizable for your purpose.
> 0 votes

---
Tags: 6, hooks, ubercart
---


# Question
Title: I added a new module and it breaks Javascript from my theme. How can I fix?
I have recently installed a new module, "Views Nivo Slider", and it is breaking the javascript on my web site that I have added via my theme. I'm at a loss as to what I should do to fix the issue.

**By Break, I mean that the code from my theme no longer executes. It also throws no errors. It just acts like the code no longer exists**

In my custom theme, I add javascript by adding this line in the theme:

`scripts[] = js/js.js`

I had added the code by using the onready event:

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

```

Now I read online that perhaps this was not the best method to add code and that I should bind with drupal events. I tried to change my code to use this method to see if it would make a difference:

```
Drupal.behaviors.addMenu = function (context) {

```

My code always works **IF** this module is not being used. However, whenever I turn this module on, it breaks all of my javascript. I've spent about 2 hours looking around and searching for articles and I have had no luck so far.

The articles I was looking at to learn more about behaviors were:

http://www.phase2technology.com/node/663/

http://mydrupalblog.lhmdesign.com/drupal-theming-jquery-basics-inc-drupal-behaviors

The javascript code being used by this module is:

```
// $Id: views_nivo_slider.js,v 1.1.2.5.2.2 2010/06/18 15:04:17 pedrofaria Exp $
Drupal.behaviors.views_nivo_sliderBehavior = function (context) {
  $('.views-nivo-slider').each(function() {
    var id = $(this).attr('id');
    var vns = $(this);
    var cfg = Drupal.settings.views_nivo_slider[id];

    // Fix sizes
    vns.data('hmax', 0).data('wmax', 0);
    $('img', vns).each(function () {
      hmax =  (vns.data('hmax') > $(this).height()) ? vns.data('hmax') : $(this).height();
      wmax =  (vns.data('wmax') > $(this).width()) ? vns.data('hmax') : $(this).width();

      vns.width(wmax).height(hmax).data('hmax', hmax).data('wmax', wmax);
    });

    vns.nivoSlider(cfg);
  });
};

```

The only error on the page is from jqeuery reading the minified javascript. I don't think this is causing the issue b/c the rotator (what uses this) still works.

Can someone please provide me with some guidance?

# Answer
> 7 votes
The screenshot in your question shows an error regarding the jQuery `live()` function, this was added in jQuery 1.3 and Drupal 6 comes with 1.2.6.

If you want to use a newer version of jQUery (needed by some modules), you can user the jQuery update module or see this tutorial: Using Newer Versions of jQuery with Drupal 6.

# Answer
> 2 votes
I have a custom theme with javascript and the Nivo Slider working together fine on a d6 site. The only thing I did with my javascript in the theme was wrap it in:

```
 Drupal.behaviors.THEMENAME = function () {

     // ALL of my theme javascript here

 }

```

Looking at your examples above, it *appears* that you might be wrapping individual js functions in your theme that way instead, so if that's the case, just stuff them inside the drupal behaviors wrapper function.

ADDITION: Re: question below regarding THEMENAME, I used it just to avoid any potential namespace collisions, but, from http://drupal.org/node/304258...

**Any function defined as a property of Drupal.behaviors will get called when the DOM has loaded.** drupal.js has a $(document).ready() function which calls the Drupal.attachBehaviors function, which in turn cycles through the Drupal.behaviors object calling every one of its properties, these all being functions declared by various modules as above, and passing in the document as the context.

...so I guess any random name could be put there.

---
Tags: javascript, 6
---


# Question
Title: Translating fields in node.tpl.php file with drupal 7
I have a drupal English/French website. I have a custom content type called 'ad' with all sort of fields. I have created the file 'node--ad.tpl.php' in my theme directory to customize the display of the 'ad' content. I use pixture reloaded theme and DRUPAL 7. In node--ad.tpl.php fields are displayed with this code: print render($content\['field\_my\_field\_name'\]);

I am trying to translate fields (both labels and values) by using 'field translation' module.

Field translation works when I CREATE or MODIFY a content via admin.

However, when I DISPLAY a content of type 'ad', fields are not translated. This is because drupal calls to 'node--ad.tpl.php' and the translation module is probably not invoked. When deleting 'node--ad.tpl.php', drupal calls the default node.tpl.php with a similar results.

Any help would be appreciated, Thanks in advanced,

Notes :

1. I correctly activated every dependencies for the module.
2. User interface translation correctly works.

# Answer
> 2 votes
OK, I found out myself how to do this:

1. Translate field labels and values in "*Configuration \> Regional and language \> Translate \> Import*". You should import the values as 'User Interface', not as 'Fields'. Do not specify a URL, only `msgstr` and `msgid`.
2. Now, you need to add your `t()` function in node.tpl.php for the translation to be effective, like so:

* In the `node.tpl.php` file, to translate field label write something like this: `$content['field_my_field']['#title'] = t($content['field_my_field']['#title']);`
    * To translate field's value, use: `$content['field_my_field']["#items"][0]['value'] = t($content['field_my_field']["#items"][0]['value']);`

You can now render your field:

```
print render($content['field_my_field']);

```

---
Tags: 7, entities, theming, i18n-l10n
---


# Question
Title: Drupal Views: Contextual Filters for certain fields
I'm having a little trouble understanding contextual filters on Drupal Views and was wondering if I could have a hand solving this problem.

I've got a content type and which allows me to add a Title, Body and a Featured Image. I want this featured image to be displayed through a Drupal View, but only when it matches the current node. If I view the Product 1 node, I only want to show the Featured Image for Product 1 and not all the other products too.

I've got a Featured Image view set up as a Block and I can successfully display this block for my allocated content type. It reads the Content: Title and the Content: Featured Image fields where the Title field is excluded from display.

How do I configure the contextual filter to restrict the Featured Image only where the currently viewed node matches the Title. Is this possible?

# Answer
Sure - that's a lot easier in Drupal 7 / views 3 than it used to be. You're displaying this block on a node page, correct? All you need to do is add a contextual filter of 'Content: Nid' and then add a 'default value' of type 'content id from url'.

That will pull the node id from the current url and pass it as an argument to this filter, restricting the output of your view.
> 4 votes

---
Tags: views
---


# Question
Title: Display a (view) block for everyone except one role
I have a block which has been generated by a view, and would like to show this block to all users except people who have been granted a particular role, is this possible, and if so how, exactly?

Many thanks in advance.

-Sniper

# Answer
In the Blocks Admin page, you can use PHP to display/not display the block, so you could put something like this in there:

```
<?php

global $user;

if (in_array('ROLETHATSHOULDNOTSEETHISBLOCK',array_values($user->roles))) {
  return FALSE;
} else {
  return TRUE;
}

?>

```

OR just check all the roles BUT the ROLETHATSHOULDNOTSEETHISBLOCK in the other part of the form :)

ADDITION:

With respect to PHP and security, I presume JoeS is referring to these paragraphs within **The Definitive Guide to Drupal 7**...

**Avoid Using the PHP Filter Module**

Although it’s handy to be able to write PHP code directly into your Drupal web interface without having to create a module, it’s also very dangerous! All PHP code should live in the form of modules or themes. Writing PHP in Drupal’s web interface is a bad idea for the following reasons:

• It’s unfriendly to edit and debug (no syntax highlighting and no proper error reporting).

• It makes code reviews difficult and versioning impossible.

• A trusted user might inadvertently damage your site with malformed PHP code. • If your site was to be compromised, a hacker could penetrate and damage your server using well-crafted PHP code. Keeping the PHP Filter module turned off (or even better, removing it entirely from the filesystem) could help contain such intrusion to the Drupal level only.

• In terms of performance, storing PHP code in the database will prevent any opcode caching mechanism from working on this piece of code

Note that some contributed modules might offer a functionality similar to that of the PHP Filter module; they will suffer from the same flaws noted previously.

```
                                   **and**

```

■ Tip If the PHP Filter module is enabled, try to disable it. PHP Filter module should not be used to provide functionality on node (content) pages. Avoiding that is a good idea from both code quality and deployment perspectives. For placing functionality, rather than content, on a page or part of a page, use Drupal’s hook\_menu(), hook\_block(), or hook\_page\_build().

...which refer to the PHP Filter Module, not the admin interface. This module allows users to enter PHP code into a node directly and I wholeheartedly agree that this opens far too many doors.

However, in this case, I am talking about using an option given to the administrator of a site by the drupal admin interface, one that hopefully is used by someone with far more PHP experience than casual users of the system.

Furthermore, using this option is most probably a one shot deal and would be properly tested, unlike the Filter option, which would allow a user to change the code at will, opening further doors to mayhem.

In any case, this discussion does highlight the fact that running a drupal site has many facets, security being a large part, and knowledge is key, but all I can hope is that there isn't a security hole that has gone unnoticed for several releases in the admin interface that would allow any code injection into the 6 lines of code suggested here.
> 1 votes

# Answer
You can set the access seetings for a block to specific roles. By default, the block is accessible for every user with the permission "View published content" (or something like that). To restrict a block for a specific role, change the "Block Settings" / "Access" to "Role" and tick the roles which can see the block.
> 1 votes

---
Tags: views, blocks
---


# Question
Title: When and where is calling menu_link_save safe and appropriate?
From what hooks (or "types" of hooks) is it appropriate to call menu\_link\_save?

I have a situation where I would like to add a bunch of entries to `{menu_links}` where an entry already exists in `{menu_router}`. To state this another way, I would like to add direct links to a menu for which another module has defined a wildcard entry via hook\_menu.

A concrete example would be that I would like to add a menu item to a menu for "taxonomy/term/123". In this case, there is already a router entry for "taxonomy/term/%" which the taxonomy module created.

I know how to use this function. I am just not sure where I can (or should) call this from. This isn't a situation where a user is saving a node, or something else that would be considered an event. Essentially, I just want my module to create a bunch of links so the end user doesn't have to.

Would this be best done by a hook\_enable? Are there any popular modules that I can take a look at for examples / use cases?

# Answer
> 1 votes
Yes, hook\_enable() sounds correct.

To find examples, on way is look at what's using the function on drupalcontrib.org. That points to menu\_enable(), which is even a core function.

---
Tags: 7, routes
---


# Question
Title: Find if the drupal node is published or not published in node_save()
I am trying to find if the user has set the node to be published when creating a node. Upon hitting save, the call to `node_save()` is done; I tried to call `print_r($node)`, but nothing seems to show up in the data which relates to the publishing status of the node.

How would I find out if the node is set to be published? Is there a way I can find out if an alias is set?

# Answer
You are looking for `$node->status`. The Node module defines two constants which you can use instead of 0/1 to make your code more readable:

```
/**
 * Node is not published.
 */
define('NODE_NOT_PUBLISHED', 0);

/**
 * Node is published.
 */
define('NODE_PUBLISHED', 1);

```

Example:

```
if ($node->status == NODE_PUBLISHED) {
  // Node is published.
}

```

Note that you should *not* alter `node_save()`. Instead, implement hook\_nodeapi() to do something either before (`$op` is "presave") or after (`$op` is "insert"/"update") the node is saved.
> 7 votes

---
Tags: 6, nodes
---


# Question
Title: How to conditionally show a views field?
I'm using the video and video embed field modules to display uploaded video and embedded youtube videos. I've added a video field and video\_embed field to the video content type.

The user either uploads a video or embeds a video with the node. A custom form validation makes sure that either a video is uploaded or embedded. I have a template override for the video content tpl.php to hide an empty field on the node display page.

I'm using views to show various video previews. Both fields are added to the view and it shows up fine to the user. However, I'm getting a lot of "Unable to find the video thumbnail for ..." in the log. Those are errors when I have a youtube video embedded and nothing uploaded.

To come to the point: How can I suppress the video thumbnail from showing in the view when no video is provided. The "Hide if empty" no results setting isn't doing the trick here.

# Answer
You could do this by creating a views row template for your view and then adding in logic to test whether or not a thumbnail exists. This also lets you style the row output differently so you don't have a gap where the image would have been.

Here's the handbook section on views theming:

http://drupal.org/node/352970

but your logic in the views template would be something like:

```
  if ($fields['field_<video thumbnail field name here>']->content) {
      <output image>
  }

```
> 2 votes

---
Tags: 7, views, files
---


title: Auto sign-in to Organic groups homepage

text:
# Question
Title: Auto sign-in to Organic groups homepage
I have setup a site where users can register as a certain type of user. Once registered, an organic group node is created for them and they can then invite other users into their group.

Can anyone advice me how the group owner and the invited members to automatically login to the group page and how to restrict users to a single group?

# Answer
> 0 votes
The way I accomplished this was to use Rules to detect when a user logs into the site and also when content is about to be viewed.

Rules provides a programmatic area in the "DO" feature of the Rule. I execute some php code to detect the group the user belongs to and redirect using drupal\_goto.

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


title: trouble with a view template

text:
# Question
Title: trouble with a view template
I created a block view and am having trouble controlling the out put. Theme developer tells me the candidate template file is views-view-fields.tpl.php that file doesn't look like any of the others I have worked on. I have found the only control I have over the output is through the view settings itself. Why can't I format the output like any other block or page?

# Answer
In a nutshell, once you have your view fields ordered in the view itself, you would override views-view-fields.tpl.php to change the row. In there, it has something like this:

```
<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <?php print $field->wrapper_prefix; ?>
    <?php print $field->label_html; ?>
    <?php print $field->content; ?>
  <?php print $field->wrapper_suffix; ?>
<?php endforeach; ?>

```

which just cycles through each of those fields and outputs them. So, if you wanted to wrap two fields in a div, you would put some logic like this in there:

```
<?php if ($id=="MYFIRSTFIELD"): ?>
  <div class="mini_text">
<?php endif; ?>

```

and put that before the wrapper\_prefix php, and put something like this before the closing endforeach:

```
<?php if ($id=="MYLASTFIELD"): ?>
  </div>
<?php endif; ?>

```

which would create that mini\_text div you mentioned. Anyways, hope this helps, I cut and pasted and coded quickly here, but this should give you an idea of how to do it, even if there are typos in there ;)
> 1 votes

# Answer
I've experienced the same issues with my conversion from D5.x to D6.x and what I ended up doing was to install the Semantic-Views module. It allows, at a row/field level the ability to add classes to each field. Not only does this work well it is a heck of a lot easier than creating and maintaining a tpl.php file. Try it, you'll like it.
> 1 votes

---
Tags: views, theming
---


# Question
Title: Passing a node refernce id to a form via hook_form_alter()
using Drupal 7

I'm trying to write a module that alters the node add form of a certain content type. This content type has a node reference field that normally displays as a drop-down. I'm also attaching this node add form to the bottom of the content it references, what I'm trying to do is populate the node reference field by using `hook_form_alter()` and passing in `arg(1)` of the page (passing it the nid of node I want it to reference).

I'm trying to figure out exactly how to do this. I've tried to do a `drupal_set_message('<pre>'. print_r($form, TRUE) .'</pre>');` on the form to see how exactly to pass in the node reference, but it just prints out a huge nested array, and I'm unable to really figure out how I would format that as input I know it's going to look something like this;

```
function mymodule_form_alter(&$form, &$form_state, $form_id){
    if($form_id == "my_node_form")
    {
        $form['title']['required'] = FALSE;
        $form['node_reference_field_name']['nid'] = arg(1);
    }

}

```

but I'm still really confused on the actual syntax

# Answer
> 1 votes
ok, figured this out incase anyone is interested, may only work for my use case but perhaps it will help someone else.

```
function mymodule_form_alter(&$form, &$form_state, $form_id){
    if($form_id == "rating_node_form")
    {
        // dont require title
        $form['title']['required'] = FALSE;
        // validate
        $form['#validate'][] = 'mymodule_form_validate';
        // call after form is built
        $form['#after_build'][] = 'mymodule_after_build';
    }
}

function mymodule_after_build($form, &$form_state) {
       //set the nid to the argument of the nide you are viewing
       $form['field_bar_name']['und']['nid']['#value'][0] = arg(1);
       //set the default value
       $form['field_bar_name']['und'][0]['nid']['#default_value'] = arg(1);
       //set form value
       $form['field_bar_name']['und'][0]['nid']['#value'] = arg(1);
       return $form;
}

```

---
Tags: 7, forms, hooks, nodes
---


# Question
Title: How to extend default user registration page in Drupal 7?
I would like to extend the default user registration page by adding more fields that will be stored in the same `users` table of database with the default fields.

What is the easiest way to do that? Could explain how to achieve this?

# Answer
In Drupal 7, you just add the fields to the user entity in "Administration » Configuration » People » Account settings » Manage fields."
Then, for every field there is the "Display on user registration form" checkbox.
> 3 votes

# Answer
If you want different registration profiles for different roles on Drupal 7, try these two modules:

**Profile 2:**

> Designed to be the successor of the core profile module \[...\] this module provides a new, fieldable 'profile' entity - leverage the power of fields!

**Profile2 Registration Path:**

> This module enables administrators to set unique registration paths per Profile2 profile type.
> 2 votes

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


# Question
Title: I have a block that I need to show in two regions.
How do I show the same block twice? I have a multiple blog site that is created using views. One half is the mens other is the womens. I created specific regions to be shown on only on specific gender--page.tpl files. I just realized I cannot show the same block twice. How will I get this to work. I am also finding that the block may have to be another view as well.

# Answer
> 1 votes
One solution is to use MultiBlock. Another would be to use Panels which would also have value if you wanted to have different layouts for the gender specific pages.

---
Tags: blocks, theming
---


# Question
Title: Views Page Showing Root Title in Window (not views title + root title)
My views page title is set to "The Title" but my window title shows as "Website" rather than "The Title | Website". This is only for my views. Any ideas what would cause this? I have a few other modules installed but not Page Title, that's disabled.

# Answer
> 1 votes
The title for a view does not show up in window title. The Window's title is determined by the browser, independent of Drupal. The view title is used as the title before the body of your content in the content display area of the window provided you have configured the view to display the title.

---
Tags: views, 7
---


title: Can't show custom user field on nodes

text:
# Question
Title: Can't show custom user field on nodes
This is a follow up question to: How do I show user attributes on articles?

I still can't get the "Twitter URL" field to show up on articles, and got tired of reading through the Fields API docs; I figured I couldd ask if anyone can look at my template files, and tell me why the twitter URL is not output, as I know it is being set.

This is the node preprocess function from node.tpl.php:

```
function blogbuzz_preprocess_node(&$vars, &$variables) {
  if ($vars['view_mode'] != 'full' && $vars['id'] == 1) {
    $vars['classes_array'][] = 'node-first';
  }

  if ($vars['view_mode'] == 'full' && node_is_page($vars['node'])) {
    $vars['classes_array'][] = 'node-full';

  }
  // Even though there's a user object in $variables['user'], we need to
  // load a new copy because the preloaded one doesn't have have field data
  $user = user_load($variables['uid']);

  // Retrieve the data and its value for the Twitter URL field
  // Replace field_twitter_url with the short name of the field
  // found at admin/config/people/accounts/fields
  $items = field_get_items('user', $user, 'field_twitter_url');
  $field = field_view_value('user', $user, 'field_twitter_url', $items[0]);

  // Get the rendered output of the field for use in the submitted line
  $twitter_url = drupal_render($field);

  // If you wanted to get more fields, repeat the last three lines, replacing
  // field_twitter_url with the names of the other fields.
  $variables['twitter_url'] = $twitter_url;
}

```

And here is the template.tpl where I use `$twitter_url`:

```
<div class="<?php print $classes; ?>">
  <div class="node-inner clearfix">
    <?php print render($title_prefix); ?>
    <?php if (!$page): ?>
      <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
    <?php endif; ?>
    <?php print render($title_suffix); ?>

    <div class="meta">
      <?php if ($display_submitted): ?>
        <?php print t('Published by '); ?><?php print $name.t(' on ').$date; ?>
         <?php print t('Twitter '); ?><?php print $twitter_url; ?>
      <?php endif; ?>

      <?php if (!empty($content['field_tags'])): ?>
        <?php print ' in '.render($content['field_tags']);  ?>
      <?php endif; ?>

    </div>
    <div class="content clearfix">
    <?php
      hide($content['comments']);
      hide($content['links']);
      hide($content['field_tags']);
      print render($content);
    ?>
    </div>

    <?php if ($content['links']): ?>
      <div class="extra-links">
        <?php if (!$page): ?>
          <div class="read-more"><?php print l(t('Read more'), 'node/' . $nid, array('attributes' => array('class' => t('node-readmore-link')))); ?></div>
        <?php endif; ?>
        <?php print render($content['links']); ?>
      </div>
    <?php endif; ?>

    <?php print render($content['comments']); ?>
  </div>
</div> <!-- /node-inner, /node -->

```

# Answer
> 1 votes
You are trying to render the twitter\_url twice. First in then preprocess function and then again in the template.

If that's not the problem, start debugging. Install devel.module if you haven't already and add dpm($variable) statements on the relevant places, e.g. dpm($twitter\_url) in the preprocess function.

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


# Question
Title: Processing data sent from drupal 7 webform
I've inserted a webform in a node's template like so:

`<?php print render($content['webform']); ?>`

and created the webform in the admin panel for that page. The form shows up fine and I've styled it correctly. I would now like to know the Drupal way of grabbing the data from the form. Most likely a preprosses function from what I've researched.

The form is very simple, just an email address and a submit button. I'm good with PHP but still getting used to drupal's backend functionality. Any help or direction is greatly appreciated. Cheers!

# Answer
I am not clear about your question. But here is the answer from what i understood.

Try creating a new module and use the hooks to process the data http://api.drupalize.me/api/drupal/group/webform\_hooks/7
> 2 votes

---
Tags: webforms, theming
---


# Question
Title: How to change the HTML Output of a view?
This view is a black book directory that will have a long list of links to static pages. The problem I am having is the output isn't coming out as an unordered list like I have set. Each link is set in a span and a row. Is it possible to output a simple ul with an id on it. I am having trouble matching my design. Thanks

# Answer
Set the view style to "HTML List," then the style option to "Unordered list."
> 3 votes

# Answer
Drupal likes to put `<span>` and `<div>` around every item. When you don't like that, you can override the PHP file that's causing this.

Look in the `sites/all/modules/views/theme` folder at the `views-view-list.tpl.php`, `views-view-field.tpl.php` and `views-view-fields.tpl.php` files.

Save a copy of these files in your own theme's 'templates' folder. Then you can edit the copies to strip code that makes `<span>` and `<div>` etc. You should also rename your version of these files according to the view's template suggestions so the changes only affect your view.

I used this for a view where I wanted to make 3 columns, so I wanted the classes li\_1, li\_2 and li\_3 (in file `views-view-list.tpl.php`)

```
<?php
// $Id: views-view-list.tpl.php,v 1.3 2008/09/30 19:47:11 merlinofchaos Exp $
/**
 * @file views-view-list.tpl.php
 * Default simple view template to display a list of rows.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $options['type'] will either be ul or ol.
 * @ingroup views_templates
 */

global $cnt_ul;
global $cnt_li;
$cnt_ul++;

$classNameUl = (($cnt_ul % 3) == 0)? "ul_". $cnt_ul ." last" : "ul_". $cnt_ul;
?>
<ul class="<?php print $classNameUl ?>">
<?php
foreach ($rows as $id => $row): $cnt_li++;
$className = (($cnt_li % 3) == 0)? "li_". $cnt_li ." last" : "li_". $cnt_li;
?>
<li class="<?php print $className ?>"><?php print $row; ?></li>
<?php endforeach; ?>
</ul>

```
> 7 votes

# Answer
You should also take a look at the Semantic Views module, which allows you to change the HTML output of the view from within the Views UI and largely avoid getting involved in template files.
> 3 votes

# Answer
sure you can style the lists.You probably have just one field in views that is Tittle so just add this to style.css in theme css folder

```
.view-view-name .views-field-title
{

}

```

Where view-name is a machine name of your View(you can find that in views settings )
> 0 votes

---
Tags: views
---


# Question
Title: Re-enable forum commenting on a topic 24 hours after an admin has disabled them
I would like an to have my Drupal forum set up so that an administrator can disable comments (by selecting *disable comments* in *forum topic*) for a particular topic, but then 24 hours later have comments opened up again automatically.

Can anyone help?

# Answer
> 1 votes
Your friend here is hook\_cron().

Furthermore, you would need to check how to find the nodes that have had comments switched off in the last 24 hours. There's something useful you can check (perhaps it is the node's change time), or you have to keep a record yourself by implementing hook\_nodeapi().

# Answer
> 0 votes
You could you use the Rules module, and set up a rule that re-enables comments after x amount of time.

* Install Rules
* Create a new rule
* When you get to midnight (or whenever), then enable comments on posts that have comments disabled.

There's not really much more I can say. The Rules module is really self explanatory when you create a new one.

The only issue you may have is whether or not Rules has the option of enabling comments. If it doesn't, then you're looking at creating a custom module that hooks into Cron.

---
Tags: 6, nodes, cron
---


title: Dates to effect dynamic form behavior

text:
# Question
Title: Dates to effect dynamic form behavior
I want a form to display an error if someone is not 18 years old, or display the next form item if they are.

After exhausting a lot of time searching for a way to do it, I believe AJAX does not work directly on "date\_select" fields. I was thinking there might be some kind of use for "#states" here.

# Answer
In either case, the Conditional Fields module sounds like it could help you here... from the module page:

> Define dependencies between fields based on their states and values. Conditional Fields for Drupal 7 is an user interface to the new States API, plus the ability to modify fields appearance and behavior on certain conditions when viewing content.

The alternative is harder because you'd need to write your own little module that implements hook\_form\_alter() that can do custom validation and insert a snippet of jQuery to hide/show elements according to the age being 18 or over.
> 2 votes

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


# Question
Title: Creating a View feed: Do not summarize, but show whole post
I've created a feed in a view, and it seems to automatically summarize the info. I'd like the entire post to be available.

How do I go about doing that?

# Answer
> 1 votes
from the sounds of it your view will be set to display teasers.

on your view edit page, under format, you have show, if set to "content | teaser" it is only displaying the teaser to display the full node click on teaser and then set the view mode to full content.

---
Tags: views, 6, feeds
---


# Question
Title: Relating content types to be used in Views filters
I have two content types:

* **Games**, which have a list of *Developers* that worked on it.
* **Developers**, which don't store the games they've worked on.

I need:

* a view that lists *Developers* that you can filter by *Game*, but "Exposed Filters" only let me filter on fields on the *Developer*, so I'm not sure how to do this.
* to be able to add to a list of people that worked on the *Game* when editing/creating, rather than have to update each *Developer*'s list of *Games* they worked on.

How can I make an exposed filter which selects *Developers* where the *Game* has that *Developer*?

# Answer
> 3 votes
Nikit's response about using Relationships in the view is correct, but it's not clear you've have already set up the correct 'node references' between *Games* and *Developers*.

So, rather than maintain your own lists of *Developers* for a *Game*, you need to use the References module to add a field that allows 'connections' between these content types. You might also want the Corresponding node references module to auto-update the reference field on a *Developer* when you edit a *Game*, and *vice versa*.

From here you can properly relate *Games* and *Developers*, so Views can use these relationships and allow you access the associated *Games* from your Developers view.

# Answer
> 2 votes
You should use Relationships in Views, and attach second content as required.

---
Tags: 7, views
---


# Question
Title: rendering node $content but not all $content is there
node `$content` variable does not contain all node elements

On my local test site the `$content` variable contains around 10 elements which I used to build my custom node template.

but now on the live site I only have 2 elements in the `$content` array.

I can't figure out why and looked everywhere but can't find where `$content` is set and or why the the other 'elements' of my node are not loaded in the `$content` variable.

using the normal 'view' all content is available. using my `node--teaser.tpl.php` not on the live site.

Both sites have the same modules enabled and are using similar node types.

# Answer
Check your display options for that content type to make sure that those fields are set to display in teaser mode.

Drupal 6: `admin/content/node-type/NAME-OF-CONTENT-TYPE/display`

Drupal 7: `admin/structure/types/manage/NAME-OF-CONTENT-TYPE/display`
> 3 votes

---
Tags: nodes, theming
---


# Question
Title: How can I create a View to give me a list of nodes that share a nodereference with the User's profile?
I have a "Company" node type and a "Content" node type.

In my User profiles I have added a nodereference to the appropriate Company node, and in the Content nodes, I have also added a nodereference to the Company owning the content.

What I am trying to do is to construct a view that will present the logged-in user a list of all Content nodes owned by (i.e. with references to) the user's company.

Pseudo-sql would be something like this:

```
SELECT n.title FROM node n,user u WHERE
n.company_reference = u.company_reference AND logged_in_user.uid = u.uid

```

There ought to be a way to do this via Views, I just have been unable to figure out how, so any suggestions or pointers will be greatly appreciated

# Answer
> 1 votes
did something similar using panels and view panes. Without panels I'm not sure how I would approach it. You can create a view that lists all the content nodes. then create a display of that view that is a "content pane" (requires panels). Go into advanced, and create a "contextual filter" based on the criteria you want (in your case it would be your node reference to the company). Then click "argument input" under pane settings. you should now be able to add this pane to a panel and pass it the correct argument. I know it's a little confusing written out .... but with this setup you could for instance make a panel that shows the user, the users company, and a list of the content nodes owned by that company.

I've posted this a couple times here, only because it really helped me understand contextual filters and how you can build some pretty awesome things just using them with views and panels

http://dev.nodeone.se/en/learn-page-manager-part-5-views-content-panes-basics

---
Tags: 7, views, nodes
---


# Question
Title: Need tags to update taxonomy list terms automatically?
I'm not sure how this should work but I have a view that spits out taxonomy terms. I would like to create an article and add tags to the article that will update the taxonomy terms. I was also thinking it would make sense to update the path so the terms links to the article. Is this possible or how is this done? I have already created a tags field on my custom data type.

# Answer
> 1 votes
A path is the name for the term or article. Giving a tag an alias that matches an article (or vice versa) is not creating an override to reroute the display. To link a term to an article, you will want to add a field to the content type (article) that is based upon the vocabulary. You access this through admin/structures/content type/manage fields/add.

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


title: How to limit the length of a tag?

text:
# Question
Title: How to limit the length of a tag?
I'm using the default taxonomy tags with nodes. If users forget to enter the commas to separate the words it will generate one really long tag.

What's a good way to do a validation?

# Answer
> 2 votes
You want to use hook\_form\_alter for this to add custom validation to core forms

http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook\_form\_alter/7

Create a form\_alter\_hook in your module and add a validation function to the taxonomy field in your form:

```
function yourmodule_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == "<your contenttype>_node_form") {
        $form['#validate'][]='yourmodule_taxonomy_length_check';
    }
}

```

Then just create a validation function to implement your logic, ex:

```
function yourmodule_taxonomy_length_check($form, &$form_state) {
    if (strlen($form_state['values']['<taxonomy_field_name>']) > <your value>) {
        form_set_error('<taxonomy_field_name>', 'Term is too long');
    }
}

```

For your taxonomy\_field\_name, you want to use the 'name' value of the taxonomy field in your target content type.

# Answer
> 1 votes
thank you schnippy for the detailed example.

For future reference the code I used is:

```
function yourmodule_taxonomy_length_check($form, &$form_state) {
  $tags = $form_state['values']['field_disc_tags']['und'];
  foreach ($tags as $tag) {
    if ((strlen($tag['name']) > 15) || (substr_count($tag['name'], ' ') > 1)) {
      form_set_error('field_disc_tags', 'Please enter tags separated by commas');
    }
  }
}

```

The tags are in an array and I'm checking to make sure no tag is longer than 15 characters or has more than 1 space in it.

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


# Question
Title: VBO showing error when using Drupal Commerce
I am getting the following error on a white page after using VBO and Drupal Commerce \-

> \*Call to a member function aggregate() on a non-object in
> .../sites/all/modules/contrib/views\_bulk\_operations/views\_bulk\_operations.module on line 764\*

I upgraded to Drupal Commerce 7.x-1.x-dev and am running the latest version VBO and Commerce Stock

Whenever I try to perform any Bulk operation, like deleting a bunch of products or changing the order status, I get the error

I have looked at the issue, which discusses an issue with Commerce Stock and empty fields, but the solution found doesn't apply because all the stock levels have values.

Does anybody have any suggestions?

PS: I am not sure if this is a red herring, but I also am occasionally getting this message on the module admin page:

> \*Notice: Undefined index: step in views\_bulk\_operations\_form\_validate() (line 621 of /var/www/html/nidadev/sites/all/modules/contrib/views\_bulk\_operations/views\_bulk\_operations.module). Notice: Undefined index: step in views\_bulk\_operations\_form\_submit() (line 664 of /var/www/html/nidadev/sites/all/modules/contrib/views\_bulk\_operations/views\_bulk\_operations.module). Notice: Undefined index: select\_all\_pages in views\_bulk\_operations\_form\_submit() (line 711 of /var/www/html/nidadev/sites/all/modules/contrib/views\_bulk\_operations/views\_bulk\_operations.module). Notice: Undefined index: operation in views\_bulk\_operations\_form\_submit() (line 713 of /var/www/html/nidadev/sites/all/modules/contrib/views\_bulk\_operations/views\_bulk\_operations.module).\*

# Answer
> 1 votes
I flushed out the database, and started with a new fresh version of VBO.

---
Tags: commerce, views
---


# Question
Title: Displayng menu description under main-menu links
I am trying to display the menu description under menu links for the main-menu in my custom theme. I have tried overriding the function as given in this post http://fusiondrupalthemes.com/forum/using-fusion/descriptions-under-main-menu #10 comment, but it doesn't work.

Can anyone help me on this?

# Answer
It worked when I used the Main Menu block in header region.

It wasn't working before because the Main Menu was directly being output in the page.tpl.php file by a call to `theme('links_system_main_menu')`. I followed the instructions on "Descriptions under main menu" at the Fusion Themes forum, and enabled the Main Menu block to get the desired effect.
> 1 votes

# Answer
The changes must be done in the "Main Menu" block, not in links\_system\_main\_menu.
> 0 votes

---
Tags: 7, routes, theming
---


# Question
Title: Help to understand and fix this entity error message
I get this error message:

> Error: Notice: Undefined index: label en EntityDefaultMetadataController::bundleOptionsList() (línea 113 de/Applications/MAMP/htdocs/rooms/sites/all/modules/entity/entity.info.inc).\**

The line causing the error message is contained in the following function:

```
 /**
   * A options list callback returning all bundles for an entity type.
   */
  public static function bundleOptionsList($name, $info) {
    if (!empty($info['parent']) && $type = $info['parent']) {
      $entity_info = $info['parent']->entityInfo();
      $options = array();
      foreach ($entity_info['bundles'] as $name => $bundle_info) {
        /* LINE 113 */ $options[$name] = $bundle_info['label']; /* LINE 113 */
      }
      return $options;
    }
  }

```

I don't know what other information I can include in this question because I have no idea what the cause could be. I think it is related to the Entity module because the file is inside Entity module.

Why am I getting that notice message? Is there a way to stop getting it?

# Answer
> 2 votes
Looking at the code of the Entity module, I noticed that the `$info['parent']->entityInfo()` method is the one defined in entity.inc, and it returns the value obtained from entity\_get\_info(). The reason you are seeing that error is that there is a module defining an entity type and which forgets to define the label for its bundles. The core modules always define the label for their bundles.

```
  /**
   * Set up the object instance on construction or unserializiation.
   */
  protected function setUp() {
    $this->entityInfo = entity_get_info($this->entityType);
    $this->idKey = $this->entityInfo['entity keys']['id'];
    $this->nameKey = isset($this->entityInfo['entity keys']['name']) ? $this->entityInfo['entity keys']['name'] : $this->idKey;
    $this->statusKey = empty($info['entity keys']['status']) ? 'status' : $info['entity keys']['status'];
  }

  /**
   * Returns the info of the type of the entity.
   *
   * @see entity_get_info()
   */
  public function entityInfo() {
    return $this->entityInfo;
  }

```

The Rooms module should give a value for the *label* property for its bundles, or the Entity module should not assume the label is always given. I don't see anything that says the bundle label is always present, even though I suspect it is a required property.

# Answer
> 0 votes
In the preceding line you use a variable `$name => $bundle_info` to use in the iteration, but do not use it. Instead you use `$name`. I would drop the array reference ( `=> $bundle_info`) in line 112

```
foreach ($entity_info['bundles'] as $name)
    $options[$name] = $bundle_info['label'];

```

---
Tags: entities
---


# Question
Title: Duplicates b/c of Node References, Views "Group By" not helping
I have a view that displays all 'parent' nodes referenced from 'child' nodes. I just want to list the titles of the referenced nodes, but because there can be multiple 'child' nodes referencing the parent nodes, my view displays the 'parent' node titles multiple times (depending on how many child nodes refer to the parent).

I was trying to use Views 3.x's new 'Grouping' feature to group all nodes by nid, but that didn't seem to make a difference. I tried using an nid that was grouped in the filters section, and an nid that was grouped in the fields section, but it didn't matter.

I could do a views\_pre\_render and just remove the duplicates manually, but that's messy, and would also screw up the pager. (See here for something along those lines: http://capellic.com/blog/cure-duplicate-nodes-in-a-view).

Is there a better way to do this, or something I'm overlooking?

I also tried using the following hook\_views\_query\_alter() hook:

```
/**
 * Implements hook_views_query_alter().
 */
function custom_views_query_alter(&$view, &$query) {
  if ($view->name == 'my_subscriptions' && $view->current_display == 'my_networks') {
    $query->groupby[] = 'node_field_data_field_list_network_nid';
  }
}

```

But still no dice...

Here's the query being generated by views:

```
SELECT DISTINCT node_field_data_field_list_network.nid AS node_field_data_field_list_network_nid, node_field_data_field_list_network.title AS node_field_data_field_list_network_title, node.title AS node_title, node.nid AS nid
FROM
{node} node
INNER JOIN {flag_content} flag_content_node ON node.nid = flag_content_node.content_id AND (flag_content_node.fid = :views_join_condition_0 AND flag_content_node.uid = :views_join_condition_1)
LEFT JOIN {field_data_field_list_network} field_data_field_list_network ON node.nid = field_data_field_list_network.entity_id AND (field_data_field_list_network.entity_type = :views_join_condition_2 AND field_data_field_list_network.deleted = :views_join_condition_3)
INNER JOIN {node} node_field_data_field_list_network ON field_data_field_list_network.field_list_network_nid = node_field_data_field_list_network.nid
INNER JOIN {users} users ON node.uid = users.uid
WHERE (( (node.status = '1') AND (node_field_data_field_list_network.type IN  ('network')) AND (users.uid = '1' ) ))
ORDER BY node_title DESC
LIMIT 3 OFFSET 0

```

# Answer
> 1 votes
Well, as it turns out, I avoided this issue by adding another filter, on the 'list' nodes (the children), and I'm lucky that I have one child 'list' node per network that has a unique flag (a 'master' checkbox field that can only be checked on one child per parent 'network' node).

I filtered to only child 'list' nodes that contain that flag, and this means that my parent 'network' nodes only show once.

I still wish I didn't have to do it this way, though. If anyone else can think of a way to actually get a distinct set of nids/titles without my having to use the 'master' flag on the child nodes, I'll definitely mark that answer correct.

# Answer
> 0 votes
Try the Views Field View module.

> This module allows you to embed a view as a field in a view. A new field handler is made available, so this can also be used in area (header/footer/empty) handlers as well as rows.
>
> This view handler can accept arguments from fields of the parent view using tokens and pass them into the child view for each row. Raw or rendered token values can be used, as well as static values.

It can fix issues with stubborn duplicates that result from the use of Node References by splitting the work of a single Views' query into two separate queries performed by two separate Views. The results of one view can then be embedded as a *field* in another. This simplifies a view that may otherwise need to use complex Relationships and Contextual Filters.

In this case, you'd do something like this:

1. Install and enable Views Field View.
2. Create a new View:
    * Add a Contextual Filter for the node reference field that references the parent node.
    * Add a Field to display the title of the node.
3. Edit your original View:
    * Add a field: "Content: Nid" (if it isn't there already)
    * Check the box to exclude it from display if desired and apply the settings.
    * Add another field: "Global: View." and edit its settings.
    * Under 'View settings-\>View,' select the view you just created.
    * Under 'View settings-\>Contextual filters,' add a token: "\[nid\]".
    * Apply the settings.
    * Ensure that Content: Nid appears before Global: View in the 'Fields' list.
4. Save the view.

Now on your original view you should see a list of referenced parent nodes without duplicates.

---
Tags: 7, nodes, views
---


# Question
Title: How to modify a view's empty text to show a different message depending the user viewing it
I have created a view displaying a user's blog entries. In view's empty text i have put the simple php code showing below

## You have not created any blog entries.

You can create a Now i want to modify it to implement the following scenario. 1. When a user visit his/her profile page the above empty text should be appear. 2. If a user visit an another user profile page then i want the empty text to have the following value \[username of the user that own's the profile page\] hasn't created any blog entries. Can anyone help me to achieve this? Thanks in advance.

# Answer
Do you have the php filter input format turned on for your site? You can do this by adding the following code into your empty text field with the input format 'php code' enabled:

```
//get the current $user object to determine the logged in user's id
global $user;

//now load the user id from the profile page into another object by pulling it from path
$usertmp = user_load(array('uid' => arg(1)));

if ($user->uid == $usertmp->uid) {
     //we're on the logged in user's page
     print "You need to write more stories..";
} else {
     print $usertmp->name." needs to write more stories.. ";
}

```
> 2 votes

---
Tags: 6, views
---


# Question
Title: Form API: Hiding form option on node forces node to be unpublished
I'm using Drupal 7

I'm creating a node through a node add form. The settings are such that it should by default be published. I'm trying to hide some of the options from the user, but when I

```
hide($form['options']);

```

for some reason the node does is no longer published by default. I've tried tracing out the value of that portion of the form

```
drupal_set_message('Options'.'<pre>'.   print_r($form['options'], TRUE) .'</pre>');

```

and I get the same values when the field is visible as when it is hidden. Seems like perhaps something is fishy?

# Answer
I was able to hide it and still get it to work correctly. I had to dig into the options object and set a number of parameters to true. Not sure if I needed to do this to them all, but here is the code.

```
    $form['options']['status']['#default_value'] = TRUE;
    $form['options']['status']['#input'] = TRUE;
    $form['options']['status']['#return_value'] = TRUE;
    $form['options']['status']['#value'] = TRUE;
    $form['options']['status']['#checked'] = TRUE;

```

This is inside the hook\_form\_alter() function in a custom module
> 0 votes

# Answer
When you hide the form\['options'\] array you essentially set it to 0. Which means the published field will always be 0 (unpublished). Try hiding the fields with CSS or JS if you need it to be conditional.
> 0 votes

---
Tags: 7, forms, nodes
---


# Question
Title: Specify a single node to load a stylesheet on
> **Possible Duplicate:**
> Any way to add CSS for a single page/node?

How do I make it so that when a specific node loads (a page with path /some/page) that it also loads a specific stylesheet?

# Answer
> 4 votes
There are several very good solutions, please see the question "**Any way to add CSS for a single page/node?**"

---
Tags: theming, 7
---


# Question
Title: How to list subpages on separate menu per page
Say I have a structure like this:

```
Mammals
  Rodents
     Mice
     Gerbils
  Felines
     Ocelots
Birds
   Songbirds
   Raptors
       Eagles
Reptiles
    Lizards

```

Etc

I would like for the main menu to display: Mammals, Birds, Reptiles.

But when you are on, for instance, Mammals, or any of it's children. I wish for there to be an additional menu that shows all of the main parent and children (so in this case mammals, rodents, mice, gerbils, felines, ocelots).

Is there any way to set this up or a module that would help? I guess that the first step would be page groups, but I don't see reference to this hierarchy other than creating automatic menus.

(using drupal 7)

# Answer
> 3 votes
Have a look at the Menu Block Split module.

> With this module you can split any menu block into two different blocks: a first block with the first level menu entries only and a second block with any second level and sub level menu entries. You can have as many splitted blocks as you need.

There is a Drupal 7 development version, just posted this evening.

# Answer
> 0 votes
It may be that modules such as Nice menus or Superfish Menus do not meet your need, but both of these allow for creation of multi-level menus that show the top level, but expand as you hover over a menu item with children.

---
Tags: routes, navigation, 7
---


title: Theming forms on alter with Drupal 7

text:
# Question
Title: Theming forms on alter with Drupal 7
I'm having issues customizing a radio button for a specific form using hook\_theme. Below is the piece of code I have on my module; see my comments elaborating the issue I encounter:

```
// Implementation of hook_form_alter().
function mymodule_form_alter(&$form, $form_state, $form_id){
  // e.g form id: commerce_cart_add_to_cart_form_u6onPJSgS7pOgw0Tlo7zHy42LTQzbV913taANkYQKTo
  if (strpos($form_id, 'commerce_cart_add_to_cart_form') !== FALSE) {
    // Alter add to cart form
    mymodule_commerce_cart_add_to_cart_form_alter($form, $form_state, $form_id);
  }
}

function mymodule_commerce_cart_add_to_cart_form_alter(&$form, $form_state, $form_id) {
  // Change the field type to radios.
  $form['attributes']['field_artwork_ref']['#type'] = 'radios';
  // Apply my custom theme for radios.
  $form['attributes']['field_artwork_ref']['#theme'] = array('custom_radios');
}

// Implementation of hook_theme().
function mymodule_theme() {
  return array(
    'custom_radios' => array(
      'variables' => array('element' => NULL),
    ),
  );
}

function theme_custom_radios($variables) {
  // Custom theme should go here.
  // However, $variables are empty, print_r gives me "Array ( [element] => )."
  // I am at least expecting to see my radio element here.
  print_r($variables);
}

```

# Answer
> 3 votes
I found this answer for Theming forms on alter with Drupal 7 on Stack Overflow:

> Themes for Drupal 7 form elements need to use the new `render array` key instead of `variables` in the theme definition:
>
> ```
> function mymodule_theme() {
>   return array(
>     'custom_radios' => array(
>       'render element' => 'element',
>     ),
>   );
> }
>
> ```
>
> Once you've made the change, clear Drupal's caches and your code should work (I've just tested the above and it works fine).

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


# Question
Title: Problem with enabling the Optimizing js files
I have installed the events and signup modules. The events appears in a calender. All were working fine. But when I enabled the optimizing JS files on the performance page Now the events does not display for the anonymous and authentication user. Now they are only available for the administrator. I again the disabled the optimizing JS files on performance page but still events are not displaying.

Can someone tell me what is the problem? I am using drupal 6.

# Answer
> 1 votes
Give AdvAgg a try. If JS Aggregation doesn't work, go to admin/reports/status and see what AdvAgg says; it has tests for just about every scenario that would cause JS optimizations to not work.

# Answer
> 0 votes
Is you `sites/default/files` directory writable by the webserver?

If you enable JS opt, view source, do you get valid output when you try to view the JS itself?

Does http://whatever/admin/reports/status list anything unusual?

---
Tags: 6, performance
---


# Question
Title: How to obtain raw field value from db table in a view?
In Views 2 I am rewriting a field to generate a link that has arguments appended.

One of those fields is referenced as `[field_name_value]` but outputs 'public' (and translated) value of the field. In the database the value is stored as `0` or `1` but it outputs `No` or `Yes` respectively. The `No`/`Yes` must be coming from the content type template which provides a pair of radio buttons, where 'No' is 0 and 'Yes' is 1.

Is there any way to obtain the raw database (0 or 1) value? Thanks.

# Answer
One of the last things Views does when it renders a view is to process all the fields raw data and format them according to settings, then theme according to the default or your own custom views templates.

So, if the 'Output format' options in field's settings on the view don't provide what you need, you can get the raw values - before formatting & theming - like so:

1. Install Views PHP so you can run code from within views fields, arguments etc.
2. Check the "Exclude from display" option on the fields you want 'raw' to stop them appearing in the output, but still ensure they're in the view data.
3. Add one "Global: PHP" field for each field for each hidden field.
4. In the "Output code" at the bottom of the field settings on the new Views PHP field, add something along the lines of `print $row->field_you_want_raw`.

Since you've got full PHP in these new fields you can format, tweak and merge any raw field data you need.
> 1 votes

# Answer
Exactly what Jim Kirkpatrick said but at step 4 note the following changes.

* When inserting values in **Output code** you must enclose them in
* You can use a combination to display node information use **print $row-\>created;**
* To display database information use

**print $data-\>\_field\_data\['nid'\]\['entity'\]-\>field\_YOURFIELD\['und'\]\[0\]\['value'\];**

The module (7.x-1.x-dev) does not currently work as the documentation says or as you would expect.

Please refer to the following thread and comment for updates and a good example of how to figure out how to construct the code to print out your values. http://drupal.org/node/1061388#comment-4943984
> 1 votes

---
Tags: database, views
---


title: Upload Image on form submit

text:
# Question
Title: Upload Image on form submit
I have a form with an image field, I want to remove the upload button and submit the image while the form is submitted. I not able to find out how to proceed further with this. Any help is greatly appreciated.

# Answer
Look at the HTML of the page, find the `id` of the input/upload button, then hide it via a `display:none;` in your css will get you going quickly; otherwise, you will have to do a form\_alter() in drupal to remove it from the form.
> 2 votes

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


title: Access callback for blocks

text:
# Question
Title: Access callback for blocks
We have "access callback" and "access argument" for defining the access to pages.

What is the way to restrict showing blocks? Can "access callback" also be defined in `hook_block_info()`, or through any other way?

# Answer
> 5 votes
The array returned from the implementations of `hook_block_info()` doesn't contain a property equivalent to the access callback for the menus. If you have a module that implements a block, then you can implement hook\_block\_view() using code that checks if the user has a specific permission. The following code is used from a Drupal module; as you see the block is "rendered" only when the user has the "access content" permission.

```
case 'recent':
  if (user_access('access content')) {
    $block['subject'] = t('Recent content');
    if ($nodes = node_get_recent(variable_get('node_recent_block_count', 10))) {
      $block['content'] = array(
        '#theme' => 'node_recent_block',
        '#nodes' => $nodes,
      );
    }
    else {
      $block['content'] = t('No content available.');
    }
  }
  break;

```

You can use similar code, but checking a different permission, even a custom one your module uses for checking if the user can see the block.

# Answer
> 2 votes
You can also control access to other blocks by implementing hook\_block\_list\_alter(), just remove the blocks which you don't want to be displayed on the current page from the array.

# Answer
> 1 votes
You can add a PHP snippet in the block configuration, and check whether the current user has enough permissions to see the block.

---
Tags: users, routes, blocks
---


# Question
Title: Adding a custom Token so i can use in Webforms
I am having the smart-ip module installed. It allows me to get User country, city etc very easily like this:

```
echo $_SESSION['smart_ip']['location']['country_code'];

```

I want to use this as a token replacement in webforms field. But I have no idea how to do it. Got confused after googling. I should do the hooking in template.php? How do i do it? :/

# Answer
> 6 votes
Create your own tokens!

You could create a small module that implements the token hooks (D6, but D7 should be similar), like so:

```
function YOURMODULE_token_list($type = 'all') {
  $list = array();

  $list['smart-ip']['smart-ip-country-code'] = t("The Country code");
  // ...etc

  return $list;
}

function YOURMODULE_token_values($type, $object = NULL, $options = array()) {
  $tokens = array();

  $tokens['smart-ip-country-code'] = $_SESSION['smart_ip']['location']['country_code'];
  // ...etc

  return $tokens;
}

```

Or, even better, add these hooks to the smart\_ip.module file and submit a patch to the module maintainer :-). Tokens are really great, and it would certainly be a good addition to the smart\_ip module.

# Answer
> -1 votes
install a module called webform\_tokens

and what u can do after that is adding your custom token to the module by altering it.

---
Tags: hooks, webforms, tokens
---


title: Help with displaying views with EVA

text:
# Question
Title: Help with displaying views with EVA
I am struggling with displaying a view in a node. I have installed EVA module and have created a view of products categorized for that node (Restaurant Type).

The entity displays in the node but I'm having trouble contextualizing the view. How do I dynamically provide the context when the page containing the entity is viewed.

I am normally a PHP programmer and a newbie recently thrown into the Drupal framework. I have been able to print out the criteria (in php template) and display the entity but I am failing in making them play together.

I presume that the "Criteria" I am able to pry out of the template is the long way round solution to my issue, how do I configure my "entity view attachment" to display a contextualized list. my file structure always contains the variable and resolves as "***.com/restaurants/steak\_houses" where "restaurants" is the node and "steak\_houses" is the context criteria.

I need help in feeding that data to the entity.

# Answer
> 12 votes
== Updated. Rewrite the answer, provide step by step screenshot ==

P.S. you also need References, I apologize that didn't mention it.

1. Create a Content Type called Restaurant, everything by default, save.
2. Create a Content Type called Product

Add Node Reference field for Product Content Type.

Create an instance of Restaurant content.

Create an instance of Product content, set the node reference field to the resturant just created.

Next, create a new EVA view.

Add filter =\> Content type =\> Product

Set Entity to node, Bundle to Restaurant

Add Contextual filter, select the node reference field created.

Provide default value =\> Content ID from URL

So you overall EVA view set up should be something like this:

Next, an important step: clear the cache, then refresh the restaurant node page to see the change:

You can see the Product One has been attached to the Restaurant.

You will get it. :)

---
Tags: views
---


# Question
Title: Any way to flag users who previously submitted a webform on revisit?
My business team needs users who submitted a specific form to be flagged in order to allow them to gain access to a certain piece of content, which we've hidden behind a conditional check on whether they have the flag or not. I understand how to set up a form action to raise a flag on a given user. Unfortunately, I didn't know there was a requirement to flag users until most had already submitted the form.

I'm wondering if there's anything I can do, now that the horse is out of the barn and a number of users have already submitted the form without getting flagged, to ask users to revisit the form and, if they've already submitted it once, just:

a. get the flag raised b. get redirected to the page with the restricted content

# Answer
The table `webform_submission` has everything you need. The webform nid and the uid.

You could implement hook\_user\_login and set a flag in the current $user object if the form has been submitted. Then check for this flag where ever you need it.
> 1 votes

# Answer
You might be able to crawl through your drupal logs (admin/reports/hits) and do something.
> 0 votes

---
Tags: webforms, flags
---


title: Simple block module

text:
# Question
Title: Simple block module
I'm trying to create the simplest block module possible. For the start, I want it to be visible on admin blocks page.

I've read few articles and browsed drupal block API and here is my code:

```
function module_block($op = 'list', $delta = 0, $edit = array()){
    switch($op){
        case 'list':
            $blocks["delta"] = array(
                'info' => t('Admin title on list')
            );
            return $blocks;
        case 'view':
            if($delta=="delta"){
                $block['subject'] = t('Default title');
                $block['content'] = module_get_html_function();
            }
            return $block;
    }
}

```

This code is placed in my custom drupal module in sites/default/modules and it's enabled on admin modules page. Here's what i've done:

Save module file -\> Clear cache -\> Enable module -\> Clear cache

But! I'm not able to see this `Admin title on list` block on my admin blocks page. Can you tell me what am i doing wrong ?

Any help would be appreciated

# Answer
Just like any hook implementation, hook\_block() needs to be prefixed with the name of your module instead of `module_`. That's how Drupal finds them, by looping over every enabled module and checking if a corresponding function exists.

While not technically required, it is also strongly recommended to prefix all other functions of your module with the module name to prevent conflicts with other modules.
> 3 votes

---
Tags: 6, blocks
---


# Question
Title: Can I change the default URI scheme in media.variables.inc?
The default URI scheme is public://, and I want to change it.

So, can I override the following code contained in media.variables.inc?

```
define('MEDIA_RESOURCE_URI_DEFAULT', 'public://');
define('MEDIA_TYPES_DEFAULT', '*');

```

What should I change at `MEDIA_RESOURCE_URI_DEFAULT` and `MEDIA_TYPES_DEFAULT`?

# Answer
> 1 votes
Changing the code in a third-party module is never a good idea: All the times that module is updated, you should download the new version, edit it to change the code you altered, and update the copy used in your site. This means that, in Drupal 7, you could not use the Update manager module to automatically download, and update, the copy of that module.
If then the module code is changed not to use those constants, you should look at the new code, and see how changing it.

Those constants are probably used as defaults for Drupal variables. If those variables can be altered using the settings page of that module, then altering the constants is not necessary.

There are other ways to alter the output of third-party code:

* If the module is using those values for a form field shown in a form, another module can alter that form by implementing hook\_form\_alter(), and associate a different value to that form field.
* If the module is using those values in a theme function, another module can override the function used for that theme function, implementing hook\_theme\_registry\_alter(). In Drupal 7, it is also possible to implement `hook_preprocess()` to alter the variables passed to that theme function.
* If the module is using those constants to set a variable used in a preprocess function, another module can implement hook\_preprocess() to alter that variable.

---
Tags: 7, media
---


# Question
Title: Prepopulate CCK ImageField with existing images
I have two types of node:

* **Building**, with a CCK imagefield
* **Apartment**, which has a node reference field to a *Building* node, where one building has many apartments

My goal is to to grab the images from the *Building* node being referenced. Is there a way to reuse the images uploaded on the Building node and use that on Apartments node?

# Answer
There are several ways to do this.

I'm supposing that you **just want to display the images on the node page**, not necessarily filling imagefields on the Apartment node (right ?).

The easiest way is to change the way your reference field is rendered. By default, it should render a title. If you go to *Content Management \> Content Types \> Apartment \> Display Fields*, you can change the display for the node reference field from a "title" to "teaser" or even "full node". That way you can display the images in your apartment node.

Another way, if you really just want the images and not the rest, is to do some coding. For example, in your theme template.php file, you could add the following code (Drupal 6 - because you mention CCK, I guess you're using D6, right ?):

```
function YOURTHEME_preprocess_node(&$vars) {
  if ($vars['node']->type == 'apartment') {
    $building_nid = $vars['node']->field_YOUR_REF_FIELD_NAME[0]['nid'];

    $vars['images'] = array();

    // If your imagefield can have multiple values OR only one value BUT the same field is present on
    // another content type
    $result = db_query("SELECT f.* FROM {files}
                          LEFT JOIN {content_field_YOUR_REF_FIELD_NAME} cf ON cf.field_YOUR_REF_FIELD_NAME_fid = f.fid
                            LEFT JOIN {node} n ON n.vid = cf.vid
                        WHERE n.nid = %d", $building_nid);

    // If your imagefield can have only ONE value and is ONLY present on this content type
    $result = db_query("SELECT f.* FROM {files}
                          LEFT JOIN {content_type_building} cb ON cb.field_YOUR_REF_FIELD_NAME_fid = f.fid
                            LEFT JOIN {node} n ON n.vid = cb.vid
                        WHERE n.nid = %d", $building_nid);

    while ($image = db_fetch_array($result)) {
      $vars['images'][] = $image;
    }
  }
}

```
> 1 votes

# Answer
If you don't want to get your hands dirty in code...

Since you have a node reference from *Apartment* to *Building* which Drupal knows about already, another approach is to use Views, Panels and CTools to override the rendering of the *Apartment* nodes to pull in the related *Building* node, and thereby allowing you to drop in the image field or a view that contains it.

Also, if you want quick and easy references between Apartments and Buildings to help you when editing nodes or building views, add a Node Reference to the *Building* content type that points at (many) *Apartments*, then use the Corresponding Node References to automatically keep these reference fields mirroring one another.
> 0 votes

---
Tags: 6, entities, media
---


# Question
Title: Views - Change view based on number of results
With Views, can you change the display of the view depending on the number of nodes being displayed?

For example: Let say you are using views to override a taxonomy page. If the taxonomy page has only one node present, then the one node should be displayed in full. However, if the taxonomy page has more than one node, then a list of nodes should be displayed (so the user click on the node they want.)

Is this possible with views?

(This question applies to Drupal 7).

# Answer
The only way I can think to do this will require some views, and a little code:

1. Build view that gets the list of nodes as Node IDs (nids) for a given taxonomy term.
2. Then build a view that gets your nodes and has filters as needed. It should take multiple, comma separated nids as an argument.
    * a: Add a display (block, pane, whatever type you need) that shows nodes in full, but limit it to one row.
    * b: Add another display that handles the list version.

With these building blocks you can call the appropriate Views display using some code. You can write this and either put it in in your own module, custom theme or simply add PHP snippet into a node or custom Panel pane.

The pseudocode looks like this:

The above has most of the core functions you'll need... I'll leave it to you to turn this into proper code!
> 2 votes

# Answer
afaik there is no built in functionality to do this automatically.

You could do it by creating a view page for multiple and single's but would have to manually update them, which is alot of work to maintain so not really feasible.

You would have to look for a module that handles taxonomies or have one created for you.
> 1 votes

---
Tags: 7, views
---


title: Cannot save any modules

text:
# Question
Title: Cannot save any modules
Whenever I want to enable/disable modules I am given different errors like the one below. These error messages change every time disable/enable a module.

"Fatal error: Out of memory (allocated 31981568) (tried to allocate 311296 bytes) in /homepages/4/d364988985/htdocs/sites/all/modules/views/modules/node.views\_default.inc on line 278"

I have already done the following steps:

* created a php.ini file with the following line:

```
memory_limit = 512M

```
* put it into the Drupal root folder

This fixed the major problem of the whole site showing an error.

The host that I am using is 1and1. Is there a way that this can be fixed?

# Answer
> 1 votes
If you are getting that error is because you are probably using a shared host instance at 1and1, and these instances are mostly better for simple static HTML sites of the kind you would create by hand in Dreamwweaver, for example.

If you are hosting a small Drupal site with a few modules, a small database, and a few visitors, then perhaps 1and1's cheapest (shared host) package will suffice. But as your sites grow bigger, shared host packages tend to not cut it (regardless if they are hosted at 1and1, godaddy, dreamhost, etc).

---
Tags: debugging
---


title: External database

text:
# Question
Title: External database
How can one pull data from an external database on a shared host in Drupal 6

Got date-nodes and a view1 with database1 for mysite.com and need that view1 also on sub.mysite.com running with database2 without the need to import every date-node in database2

Drupal core 6.22
Calendar 6.x-2.4
Date 6.x-2.7
Views 6.x-2.16
Rotor Banner 6.x-2.8

I tried it with Views 3.x but didn't succeed AND Rotor Banner doesn't work with Views 3.x

# Answer
> 1 votes
Do you have the external database setup in your settings.php file?

```
$db_url['default'] = 'mysqli://user:password@localhost/db';
$db_url['external'] = 'mysqli://user:password@localhost/db2';

```

You're not attempting a join or create relationships across the databases (more complicated process still under development) so to set this up you can use the Table Wizard module to connect the two. Install the module, and then navigate to "Content Management -\> Table Wizard -\> Relationships"; you should be able to connect to tables in the 'external' database and use their fields in creating views.

---
Tags: 6, database
---


# Question
Title: Getting my paths/breadcrumb right with views
Is it possible to get SEO friendly URLs when using a view? I have a site I am building that has a homepage which leads to two main views ("Homme" and "Femme"). I need the URL and breadcrumb to read "Home \>\> Homme \>\> name-of-the-article." Then, on the article page, I need "Homme" to be a link. Pretty straight forward and what you would expect in a site, right? I did download and install the Pathauto module, but I can't seem to get it working. I have a custom content type called "Men's blog post" and I set the path to be: "homme/\[node:title\]"; something similar is for "Femme."

This is not working. Do you have any idea?

# Answer
Does the node title in the url include spaces? IF so, know that the spaces in the name which do not work well in urls. You should set the title to have dashes to be a machine readable title. To do so change the configuration settings in pathauto to use a '-' separator.
> 1 votes

---
Tags: 7, path-aliases, uri, breadcrumbs
---


title: Manual about modules confusing me

text:
# Question
Title: Manual about modules confusing me
I'm reading in Apress' Definitive guide to Drupal 7 and I'm trying to understand what they're saying. For those who have the book, on page 404 paragraph it says - and I quote - "Every path ultimately matches up to a menu item with a page callback function that has chief responsibility for displaying the page at that path."

But aren't there paths that don't match up to menu items? Or are menu items in this content different things to begin with? And menu items containing functions? How do menu items contain functions?

Maybe The Definitive Guide is a confusing book and there are better resources for understanding how module development works? (I've searched the web for many resources already and they've all been just as confusing as Apress's)

# Answer
> 3 votes
I have the book, but page 404 does not include the quote in mine (the beginning paragraph is "The switch statement does...", so I cannot interpret the exact context of the quote. In general, every page is assigned a path and drupal determines the display from its 'menu' of path options. Think of the displayed menus as a subset of the available options in drupal's list.

Drupal stores information about each site in the database and callback functions are associated with the each master menu option. When a URL is requested, it queries the database, finds the associated function and executes it.

I found parts of 'The Definitive Guide...' confusing to begin with too, but it is actually pretty good overview and quite useful. The problem is that Drupal is very large and a complex system to get your head around at first. The learning curve seems enormous at first (I know), but soon parts begin to fall into place and you begin to "GET IT".

This site is a great place to expand your understanding and begin to put it together. Your question was well written (clear) and there are plenty of people here to answer (although traffic is slow this week with the holidays).

# Answer
> 3 votes
The part you quoted is at page 392, in a section titled, "Drupal Turning Paths into Pages: hook\_menu()."
What the book reports is exact, if you exclude the path to files existing on the server, such as update.php, or cron.php; apart those paths, in Drupal every path is defined in the implementation of `hook_menu()`.

The term "menu item" is not referring to the menu items you can add to the menus using the user interface, as those don't generate an internal path; if I set a link to Drupal.org in the main menu for my site, that link is not associated with an internal path such as http://example.com/drupal.org.

---
Tags: 7
---


# Question
Title: jsmin+ causes high server load in drupal 6
I have the JavaScript aggregator module on my site. Whenever I check the jsmin+ checkbox (so it uses jsmin+ instead on jsmin), the server becomes really slow. I have to use jsmin+, instead of jsmin, because jsmin doesn't group JavaScript files correctly, and I get JavaScript errors (Ckeditor and Vertical Tab are breaking).

* Drupal 6.20
* JavaScript aggregator 1.6
* jsmin+ 1.4

# Answer
Give AdvAgg a try. It works around the limitations of jsmin+
> 1 votes

---
Tags: javascript
---


# Question
Title: mediafront module showing thumbnails instead of original image
I am doing the annoying crosspost thing but I can't get any answers on drupal.org so hoping somebody here can answer this.

I'm using the mediafront module to display images or videos in a slider. it shows videos just fine and if the first slide is a image it shows up correctly. However the subsequent slides the images show up as thumbnails. It is putting in specific styling in the image tag to make it a thumbnail. I really need an answer for this and hope somebody knows what is going on.

Thanks.

# Answer
Here is the installation guide.

Step 4 shows how to set up your fields, now just make sure you go to the "Manage Fields" for the content type you created, click edit next to the image field. Check the page for a dropdown for "image style", set it to none and define the dimensions of the image.
> 1 votes

---
Tags: 7, media
---


# Question
Title: How do I use webform tokens in my PHP code for the form submission page?
I see this in webforms, but I don't know how to use these in my result page, as `print_r(%value)` doesn't print anything.

> Submission tokens
>
> `%sid` \- The unique submission ID.
> `%value[key]` \- A value without additional formatting. Elements may be accessed such as `%value[fieldset_a][key_b]`. Do not include quotes.

# Answer
These won't show up in the results page. I think these are only useable when the form is submitted. One thing that confused me for a while was the \[fieldset\]. If the value you are trying to access is not in a fieldset it is \[Root\].

Name: ***_*_**

%value\[Root\]\[name\] would be most likely way to access that value after the form is submitted by the user.

(%email works also if you are going to send an email, but that also shows the label)

Hope this helps and is actually what you need help with.

-Marc
> 1 votes

# Answer
Tokens are not PHP variables. Using PHP functions won't have any effect.

Not sure how current this information is, but this page tells how to get the webforms submitted data in 6.x.

http://drupal.org/node/236515
> 1 votes

---
Tags: 7, webforms
---