# Question
Title: Where to start looking up if there's something wrong with cck field variables?
**in short:** Something in my zen-based custom theme is keeping a couple of cck fields from being display on my page. Basically my question is where to get access to the variables that are supposed to contain the html for the cck fields (which are missing when I was looking them in firebug).
Below I explain why I think it's looking up the variables that might bring me closer to a solution

So I made this custom node type (events) with cck fields added. Also made some content using those fields. Added some css and it all displayed fine.
Later the taxonomy terms below the title and some metadata bugged me so I followed along with a 'theming cookbook' pdf book that taught me how to make a node-events.tpl.php and simply deleted php variables like $terms. This worked great.

Obviously this also means that all this time, the view permissions of those fields have been checked and also that the display options under 'display fields' have been set to standard all the time. I also ruled out that the issue could be anything else than theme related as my cck fields do show up in a stock Drupal theme. The theme for my site is a zen-based custom theme.

So then even later, after I made a view for this node type and started adding css to that view I noticed at some point that my image field and two other fields are missing. It's hard to tell if they disappeared because of things that I did when creating the view and adding css (which would surprise me)

# Answer
to test if the value of your CCK field is inside node content, I think that you can use `print_r($node);` in your custom node.tpl.php (in your case `node-events.tpl.php`) file of your theme directory, to see the list of the CCK fields (or if you use Devel module, is best use `dsm($node);`)

For example, I have a CCK field called `field_test_text`, see this screenshot using `dsm($node);`

And this is the way to test the specific value of the test field:

```
  <div class="content clear-block">
    <?php print $content;
    dsm($node->field_test_text['0']['value']); //dsm way
    echo $node->field_test_text['0']['value']; //echo way
     ?>
  </div>

```

I hope information be useful.
> 0 votes

---
Tags: 6, entities
---


title: How to remove certain meta tags?

text:
# Question
Title: How to remove certain meta tags?
How can I remove these tags from my pages in Drupal 7?

```
<link rel="shortlink" href=" .... " />
<meta name="Generator" content="Drupal 7 (http://drupal.org)" />
<link rel="canonical" href="...." />

```

**Update**: I have the code for template.php, which removes the generator and canonical tags.

```
function program_html_head_alter(&$head_elements) {
  unset($head_elements['system_meta_generator']);
  foreach ($head_elements as $key => $element) {
    if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {
      unset($head_elements[$key]);
    }
  }
}

```

Can anybody add something to remove the short link tag?

# Answer
> 10 votes
This is displayed in html.tpl.php in the variable $head. $head is added to the variables in template\_process\_html by using drupal\_get\_html\_head(). In that function, you can see that hook\_html\_head\_alter() is called.

There can you remove these.

However, note that these links can be important for SEO, to avoid that a search engine thinks that you have duplicate content on your site, if for example a node is available through node/nid and the alias.

# Answer
> 5 votes
I use the following function within my template.php file:

```
/**
 * Used to remove certain elements from the $head output within html.tpl.php
 *
 * @see http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_html_head_alter/7
 * @param array $head_elements
 */
function YOUR_THEME_NAME_html_head_alter(&$head_elements) {
    $remove = array(
        'system_meta_generator',
        'metatag_canonical',
        'metatag_shortlink'
    );

    foreach ($remove as $key) {
        if (isset($head_elements[$key])) {
            unset($head_elements[$key]);
        }
    }

    // Use this loop to find out which keys are available.
    /* -- Delete this line to execute this loop
    echo '<pre>';
    foreach ($head_elements as $key => $element) {
        echo $key ."\n";
    }
    echo '</pre>';
    // */
}

```

# Answer
> 4 votes
I solved shortlink too, modyfying your code.

Someone could tidy it up properly, because I don't know how to put it properly, and neither if it has side effects in this way or not. It makes the unwanted links disappear from the head, though.

```
function nameof_mytheme_html_head_alter(&$head_elements) {
  unset($head_elements['system_meta_generator']);
  foreach ($head_elements as $key => $element) {
    if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {
      unset($head_elements[$key]);
    }

    if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'shortlink') {
      unset($head_elements[$key]);
    }
  }
}

```

Yes, it's a butcher's attitude towards canonical links, but until no better sulotion comes up, this is still better.

THAT'S WHY: you need canonical links shown ONLY on the duplicate pages, the ones that are not the preferred version. Original pages should be left alone: none canonical should be showing there! That's why I still butcher around.

---
Tags: 7, meta-tags
---


title: How do I display my products?

text:
# Question
Title: How do I display my products?
I have managed to create a product type and import my product data, so I now have a list of products.

How do now go about getting the products to display? Do I have to build a content type from scratch and add the fields manually, or is there a way to generate the content type?

# Answer
> 29 votes
As pjskeptic mentioned, you can build a generic display mechanism using Views (or potentially Panels), but the primary way to establish one piece of content as a product display is to use a custom content type with a *Product Reference* field using the *Add to Cart form* display formatter. This has some distinct advantages:

1. Your product display node gets multiple view modes (i.e. teaser vs. full page vs. RSS) and can receive comments (i.e. user reviews and ratings if you set it up).
2. Product fields will be rendered and displayed in the node, including the product's Price field by default but also accommodating custom fields you add to products (i.e. an Image field).
3. A single product display node can reference multiple products through the Product Reference field, which turns the add to cart form into a product selection form and/or an Ubercart style attribute selection form. However, unlike Ubercart attributes, the product attribute selection form here accommodates dependent attributes, only shows valid attribute options based on the products you have referenced, and dynamically updates any product fields displayed on the node to show the currently selected product. This results in allowing unique images based on product or attribute selection, as seen in the mug product on the demo store.

There are some other advantages her, too, but it's worth noting that we understand this introduces complexity into the product display creation process. We made the decision early on to build what we thought was a sound architecture (separating the product definition from its point of display) and to simplify the store administration aspect through the use of installation profiles and contributed modules. To whit, you can use the Commerce Kickstart installation profile to create an installation of Drupal 7 + Drupal Commerce that includes a pre-configured *Product display* content type and adds an Image field to the basic product type. (Unfortunately, you'll have to know Git to grab this, as installation profile packaging is currently non-functional for Drupal 7 profiles.) Additionally, we're working on projects that allow you to bulk create products / product displays and to add / edit products directly in the node edit form using a custom Product Reference field *widget*.

To set this up manually, follow these steps:

1. Add a node type called *Product display*. Submit using the *Save and add fields* button.
2. Add a Product Reference field that uses an *Autocomplete text field* widget. Make the field required and allow an unlimited number of values (even if you only intend to use a single value for now).
3. Click over to the *Manage display* tab and ensure this field uses the *Add to Cart form* display formatter. You might also want to move around the product fields you see listed here.
4. Create a *Product display* referencing one of your products and examine the node's teaser and full page views. You may want to change the way product fields are displayed. To do this, you actually have to browse to your product type's *Manage display* page and update the display formatter settings there. You can only adjust the sort order and visibility of product fields through the content type edit pages, not the formatter settings.

There's more to it, but this should get you started. This process is actually the topic of an article I wrote for the first issue of Drupal Watchdog. I hope to be a regular contributor on the topic of Drupal Commerce, so I encourage you to get a subscription if you weren't at DrupalCon when the magazine was released. It may be the articles appear on the website eventually after printing.

For further support, I'd encourage you to browse the forum posts and documentation on this topic on DrupalCommerce.org and check out the #drupalcommerce IRC channel on irc.freenode.net. If you find any bugs or want to contribute to the usability discussion, we'd love to get your feedback as a site builder in pertinent issues in our issue tracker.

Oh, and if you're a visual learner, I walk through this process and explain how the architecture works in my session video from DrupalCon Chicago. It's the best video to date, though I'd love to see smaller screencasts targeting specific steps of Drupal Commerce site building get produced in the future.

Best of luck!

# Answer
> 4 votes
In Drupal Commerce, products are not displayed like nodes. You can display them using views.

Create a new view and select Commerce Product as the View Type. To display a single product, setup the view to accept a Product ID or SKU argument. Then, you will have access to all of the product's fields. To display multiple products, add a filter or argument for category or any other criteria by which products should be listed.

You can also display products by creating a content type with a product reference field and then creating a node for each product, but that would definitely be a pain if you have a lot of products.

# Answer
> 1 votes
Checkout Commerce (Product Display Manager) for easier product to product display node managing!

# Answer
> 1 votes
Once you have products in Commerce, you can combine Ryan Szrama's structure (i.e., creating a "product display" content type) AND the power of views.

First, create the product display CONTENT TYPE (Admin\>\>structure\>\>content types\>\>add content type). Follow Ryan Szrama's instructions from his answer on this page.

Second, create your first product display for one of your products.

Third, create a new View (Admin\>\>structure\>\>Views\>\>Add new view). Set the view to display content of type "Product Display." Adjust the view to suit your tastes. You now have a product list.

---
Tags: commerce
---


title: How to create footer links in drupal 6

text:
# Question
Title: How to create footer links in drupal 6
I am doing a site in Drupal 6, and I need to create footer links which needs to be displayed in the footer.

How can I create it?

# Answer
Create secondary links in admin/menus/secondary links.

Once completed, go to blocks/list/, look for your secondary links, and place them in the footer block region.
> 2 votes

---
Tags: 6
---


title: Tracking user contact form submissions

text:
# Question
Title: Tracking user contact form submissions
How can I track user contact form submissions on Drupal 6?

I'm thinking of something similar to the webform results table but for user contact forms.

If not something that complex, then just simple statistics on contact form use, e.g. "UserX received 10 emails this month."

I'm pretty sure I'll have to create my own module which is fine, I just need to know how to go about this.

Do you have any ideas?

# Answer
> 2 votes
What you could try is:

use hook\_mail\_alter() to check when mails have been send and store the information you need in a special table of your own module. Maybe the information in the `$message` is enough for you. If not you could try:

hook\_fom\_alter() to add an extra submit-handler to the contact form like this:

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

```

Inside `my_custom_submit_handler($form, &$form_state)` you should have full access to the form fields and store everything you need like you want to.

# Answer
> 1 votes
The Maillog / Mail Developer module will show you a log of all emails sent.

---
Tags: forms, users, nodes
---


title: How to include jplayer.js on all pages

text:
# Question
Title: How to include jplayer.js on all pages
I am using module - jplayer (http://drupal.org/project/jplayer), in the jplayer.module i've found this piece of code, since i am very weak in php i need a help :)

```
/**
 * Add the jPlayer library to the page.
 *
 * @param $add
 *   By default this function will add jPlayer to the page JavaScript array
 *   directly. If wanting to store the jPlayer file as an #attached property,
 *   set this to FALSE and jplayer_add() will only return the needed array
 *   suitable for use as an #attached property.
 */
function jplayer_add($add = TRUE) {
  static $added = FALSE;

  $directory = variable_get('jplayer_directory', 'sites/all/libraries/jplayer');
  $return = FALSE;
  if (file_exists($directory . '/jquery.jplayer.min.js')) {
    $filepath = $directory . '/jquery.jplayer.min.js';
  }
  elseif (file_exists($directory . '/jquery.jplayer.js')) {
    $filepath = $directory . '/jquery.jplayer.js';
  }

  if (isset($filepath)) {
    $jplayer_js = jplayer_get_file_path('jplayer.js');
    $jplayer_css = jplayer_get_file_path('jplayer.css');
    $settings = array('jPlayer' => array(
      'swfPath' => base_path() . variable_get('jplayer_directory', 'sites/all/libraries/jplayer'),
      'autoPlay' => (int) variable_get('jplayer_autoplay', ''),
    ));
    if ($add) {
      drupal_add_js($filepath);
      drupal_add_js($jplayer_js);
      drupal_add_css($jplayer_css);
      if (!$added) {
        drupal_add_js($settings, 'setting');
        $added = TRUE;
      }
    }
    $return = array(
      'js' => array(
        array('data' => $filepath),
        array('data' => $jplayer_js),
        array('data' => $settings, 'type' => 'setting'),
      ),
      'css' => array(
        array('data' => $jplayer_css),
      ),
    );
  }

  return $return;
}

```

What should i modify in this code to show .js files on every page, not only when a node with a player loaded.

**UPDATED.** The question is - what to modify in this code to attach jplayer js files on every page, not when im viewing a node with a jquery player.

# Answer
> 2 votes
The easiest way to add a JS file to your theme is to add it in the `.info` file:

```
scripts[] = js/my_script.js

```

Be sure to put your js file in a js folder inside your folder's theme.

**Reference**: Adding JavaScript to your theme or module *(works in D7 too)*

# Answer
> 1 votes
Use hook\_init()

> this hook is a typical place for modules to add CSS or JS that should be present on every page. This hook is not run on cached pages - though CSS or JS added this way will be present on a cached page.

---
Tags: javascript
---


# Question
Title: Change page title on user-profile using a field value from Profile2
Normally the /user/uid page shows the username as page-title. I'm using the Profile2 module to leverage more fields to my users, including a 'full name' field which I'd also like to use as the page title.

How would I go about this?

# Answer
If you actually seek to always use the *full name* for the user's Profile2 when his/her *username* is displayed, then you should implements `hook_username_alter()`. Any well behaving module (contrib and core) should use it.

```
function MODULE_username_alter(&$name, $account) {
  // Get the user profile
  $profile = profile2_load_by_user($account, 'profile_type');
  if ($profile) {
    $fullnames = field_get_items('profile2', $profile, 'field_fullname');
    if ($fullnames) {
      $name = $fullnames[0]['value'];
    }
  }
}

```

If you only want to override the *username* when used as title of the user page, you can alter the menu entries for `user` and `user/%user` to change their `title callback` to a custom one.

```
function MODULE_menu_alter(&$items) {
  $items['user']['title callback'] = $items['user/%user']['title callback'] = 'MODULE_user_menu_title';
}

function MODULE_user_menu_title($account) {
  if (is_object($account)) { // Updated here
    $profile = profile2_load_by_user($account, 'profile_type');
    if ($profile) {
      $fullnames = field_get_items('profile2', $profile, 'field_fullname');
      if ($fullnames) {
        return $fullnames[0]['value'];
      }
    }
    return user_menu_title($account);
  }
  return '';
}

```
> 4 votes

---
Tags: users
---


title: Error 310 after Drupal installation

text:
# Question
Title: Error 310 after Drupal installation
I've installed a fresh copy of Drupal 7.8 on an FTP server. For some reason, I am unable to run install.php, receiving the error:

> Error 310 (net::ERR\_TOO\_MANY\_REDIRECTS): There were too many redirects.

The files have not been altered in any way.

What could be the problem?

# Answer
> 1 votes
The problem was that I didn't notice that Drupal 7 has compatibility problems while running on IIS and requires a complex (at least for me) configuration procedure to run correctly. I've reached that conclusion when I tried to install Drupal 6 on the same server, and it ran instantly.

---
Tags: redirection, installation
---


# Question
Title: How to customize exposed filter for date field?
I have a view that shows a table of members. I would like to have an option to filter by "new members", let's say members that joined in the last month.

If I expose the field I get an input box with "-1 month" which isn't ideal. It would be better to have a "select box" with "Any" and "New Members" options. A previous DA question didn't show an answer for this option.

Alternatively, links for "All Members" and "New Members" would work for me too. If I expose the field I can make the link work. But then I have to somehow hide the text field.

Any other solutions?

# Answer
You can create your own form controls to send his values to exposed filters. For example, create your own select list inside a *exposed filters* template (`views-exposed-form.tpl.php`). This select list can have your desired options with respective values, according is needed in the exposed filter, for example:

```
<select id="edit-date" class="form-select" name="date">
<option value="-1 day">New members</option>
<option value="-7 day">Members within 1 week</option>
<option value="-30 day">Members within 1 month</option>
<option value="">All members</option>
</select>

```

Also, if you need a more complex behavior, you can alter view's queries with `query_alter` hook. This answer is an example of how to use `query_alter` with a custom select list.

I hope information be useful.
> 0 votes

# Answer
for reference, I ended up hiding the exposed filter element with css and using a link in a block to get the filtered view. I used firebug to find the div of the exposed filter and then used the css\_injector module to inject this css for the view page:

```
.views-widget-filter-created {
  display:none;
}

```

Another option would be to clone your view, add the filter (without exposing it) and then linking to it.
> 0 votes

---
Tags: 7, views
---


# Question
Title: Is there a field type that offers structured entry that gets rendered as a table?
In the creation of a content type, is there a field type that offers structured entry that gets rendered as a table?

I'm creating an event node, and on the 'full content' display, there are 'sessions' at the event.

Doing a table in the CKeditor isn't enough, and referencing nodes of a different type is too much.

I need something that starts with these columns and one blank row at the bottom, where the end user/content manager can add information like "Date (datepicker) | Discussion Topic | Room | Timeslot(timepicker) | Speaker."

Adding information in each column will cause a new blank row for entry. When the whole node gets submitted, and rendered in 'full-content' display, a table is rendered with that data, as entered on the backend.

Any suggestions on where to look?

# Answer
Take a look at these modules:
> 3 votes

# Answer
This is my favorite Drupal 7 solution to this problem: Instead of "referencing" another node or entity, bring the entity to your node form. It's called Field Collection. Basically it embeds an entity creation form inside the node form.

There is also a formatter that shows the data as a table: http://drupal.org/project/field\_collection\_table.
> 1 votes

# Answer
It is probably best to create a custom module, if you have a special ordering of table and data, especially when there is a single entry form and a lot of tables where they will go.

You will find more on http://drupal.org/developing/modules.
> 0 votes

---
Tags: nodes, entities
---


title: OG view-content

text:
# Question
Title: OG view-content
Can somebody tell me, how can i restrict viewing a certain-content type in an OG group to only group admin, so no other group members can see it.

And the 2nd question, if anibody knows; you can assign a field called group\_audience. Is there an option, to not actually show the field, but assign a value of whatever group the user is in. Can I do this using hook\_form\_alter?

# Answer
> 1 votes
In your og node template you can use conditional php to show certain content.

```
<?php if (og_is_node_admin($group)):?>

 // Put whatever fields that you want viewable by the admin only

<?php endif;?>

```

# Answer
> 0 votes
> Question #2: if anibody knows; you can assign a field called group\_audience. Is there an option, to not actually show the field, but assign a value of whatever group the user is in. Can I do this using hook\_form\_alter?

Check out this comment. It shows you how to create a module that will do that.

---
Tags: forms, organic-groups
---


# Question
Title: Webform rules: compare a form field to a user field
I am trying to create a rule that will update a user piece of info from a webform. The webform is a service request form and the field I want to update is a car license plate field, present both in user fields and webform fields. I installed the Webform rules module, which exposes the webform in the rules conditions but I cannot see anything changed. No webform or webform field appears in the conditions selections. Does this module work? Am I missing something?

# Answer
I guess that you can enable Rules Forms support Submodule of Rules. This submodule shows the correct name of your form (above each respective form) to be used with Rules.

Also, see this answer, is related with Rules Forms support submodule and other steps to make a comparision form fields with rules, I think that could be useful.

**Update:** This is the address to download the module Rules Forms support for Drupal 7 http://drupal.org/project/rules\_forms

this is an screen shot in Drupal 7 about when is enabled rules for a specific webform:
> 2 votes

---
Tags: 7, users, webforms, rules
---


# Question
Title: Enabling aggregate and compress CSS files caused error on site access
I set this tick box in the performance area, and on clicking Save I now cannot access the site, even the performance area to disable this! any one know if I can directly change this in the DatabasE?

EDIT: I have refreshed the Database, thankfully no updates since it went live. This does raise the question though as I'm not the only one who has had problems with these performance tick boxes, how do you back out of an error?

I would still like the answer cause i'm trying to get to the bottom of these performance settings.

thanks for any replies.

# Answer
> 5 votes
I found this from http://drupal.org/node/782510

In your settings.php file, add

```
$conf['preprocess_css'] = CACHE_DISABLED;

```

Seemed to work for me on a quick test

# Answer
> 1 votes
If you're looking for a good alternative for core's preprocessing of CSS/JS check out the Advanced CSS/JS Aggregation module

# Answer
> 0 votes
I believe this setting is stored in the **variable** table as **preprocess\_css**

```
UPDATE variable
SET value = 'i:0;'
WHERE name = 'preprocess_css'

```

and then clearing cache should do the trick. I am also pretty certain just deleting that row should do the same thing, as the default value is 0, and variables not in the table take on their default value via variable\_get().

I should add, that if you can't clear the caches from the site itself, nor via drush, you can go in any manually clear out these tables.

---
Tags: performance
---


title: A search feature for fields?

text:
# Question
Title: A search feature for fields?
I've looked at the core search module, and from what I've been able to tell so far, it searches on the body of a node.

What's the best way to get a search feature for a site that will search on specified fields of a content type?

# Answer
You can use Views module http://drupal.org/project/views.

With Views module, you will have a flexible method to pull content according fields of your content that you want to show, and with `Exposed Filters` feature of Views module (or with modules like Better Exposed Filters), you can search/refine by field of your content.

here is a documentation about Views: http://drupal.org/documentation/modules/views

here is an example: I want to filter and search by Title of my content. Then I can add to my View a filter to search by Title, then in `Filter Criteria` I can select `Title` and expose that filter to use, for example, a text field for search Titles:

this screen shot is about where is located the Filter Criteria area, and where is the option to add filters:

this screenshot is about where you can select if you want expose a text box to search/filter, in this example, by Title. The operator is very important to filter. In this case I will select `Contains` that seek a word that is part of title:

Also remember that you can add another filter, the filter by `content type`, to filter results by list of content type desired. This filter can be not exposed, or if you want, can be exposed to allow to users filter and search, according content types:

And finaly this screenshot have the View with a text field for filter and search by titles of my content:

I hope information be useful.
> 4 votes

# Answer
For Drupal 7 try the Finder module.
> 2 votes

---
Tags: 7, search
---


title: How to create an article sharing site?

text:
# Question
Title: How to create an article sharing site?
I need to design a site which would let people write & share their articles, essays, poems, pretty much any written stuff. It should have complete Facebook integration - registration, likes & comments all from Facebook API.

I found that Drupal would be perfect designing such a site.

I've never used Drupal before. Any advise on how to go about making such a site using Drupal? Are there any contributed modules I could use?

# Answer
Because you are very inexperienced with Drupal, you don't know that your question is actually a set of several questions.

If you never have used Drupal before, you must understand a few basic things about Drupal, then learn about how to install it, and how to administrate (and customize) your Drupal to add the features that you want.

Also, Drupal has installation profiles; there are a variety of "pre-configured" versions of Drupal you can download and use for common needs. I am not sure any profile exists that is specialized for your needs, but you can search and select the most suitable and customize according your needs.

**Update:** If you have installed a Drupal version, and have reviewed the basics of Drupal administration, you can find and test several options for modules to (integrate with Facebook\](http://drupal.org/search/apachesolr\_multisitesearch/facebook%20Integration?filters=ss\_meta\_type%3Amodule). For letting people share their content, you can review that with Content Types and CCK fields (CCK is needed for Drupal 6) you can create separated types of content having custom fields according your needs.

here http://drupal.org/documentation/modules/field-ui and here http://drupal.org/node/774728 are documentation about how to create a Content Type, and here is screenshot about where you can add custom fields for Content Types:

Remember review `Drupal profiles`, can be a suitable answer that you can customize with content types and Facebook integration.
> 3 votes

---
Tags: 7, social-network
---


# Question
Title: How to include javascript code before </body>?
I want to integrate infolink code. Finally I copied this code just before print $closure in page.tpl.php file at the bottom to make it work:

```
<script type="text/javascript">
   var infolink_pid = 326015;
   var infolink_wsid = 3;
</script>
<script type="text/javascript" src="http://resources.infolinks.com/js/infolinks_main.js"></script>

```

**But why this code does not work when placed in the same place?**

```
<?php
global $theme;
$js_fl_path=drupal_get_path('theme',$theme).'/infolink.js';

drupal_add_js($js_fl_path, 'theme', 'footer');
?>

```

I'm using a subthemed Garland in sites/all/themes/ui\_garland.

# Answer
If you had had that code directly in the page.tpl.php its normal, because your page is rendered in the same time as you try to add the JavaScript.

You should add your code in one file, at the root of your theme called template.php.
> 1 votes

---
Tags: javascript, 6
---


title: Displaying field twice in same node

text:
# Question
Title: Displaying field twice in same node
I want to have two styles of a specific field. How can I display the field twice so I can style each one differently?

# Answer
Inside *node.tpl.php* instead of printing the whole content you can print fields seperately:

`<?php print render($content['field_name']); ?>`
> 1 votes

---
Tags: 7, entities
---


# Question
Title: node not listed under create content for panel page
I'm following this book called drupal 6 panels cookbook. With panels installed, the example in the book says to go to the Panel UI of the new panel, click on the content tab\> click gear icon \> click add content

Then, a windows pops up and it has a couple of links on the left side that you can click. Listitems are Activity, cTools examples, menus...

What is supposed to be listed also is 'form' and 'node' but they're missing. At first I thought it was because maybe CCK wasn't enabled but everything that has to do with the CCK module is enabled.

Honestly don't know where to look.

# Answer
Never really found a solution, just a workaround where I went with a view to display the content.
> 1 votes

---
Tags: 6, panels, nodes
---


# Question
Title: Output same content type in different format
I need to output a same content type in 2 formats : html and xml. How can I do that and what url to use o access these different outputs?

# Answer
> 2 votes
The easiest would be to use Views Datasource which allows you to output any data in XML, JSON, XHTML with different schemas. You can the set your own URLs and can have fine control over the output.

Another, rather primitive way is to use the RSS feed with full content on, but I take it that may not be what you are looking for, yet when all else fails — it is better than nothing.

---
Tags: 6
---


# Question
Title: Getting body of a node to display in a block using PHP code
I've created a block and put some php in it to display the body of a node using the code form here: http://drupal.org/node/300910#comment-4183142

```
<?php
//get the ID from the URL
$node_id = basename($_SERVER['REQUEST_URI']);
echo $node_id;
//Load the node object.
$node = node_load($node_id);
//Get the node array into memory.
node_view($node);
//Now you can parse only the body value into a variable.
$node_content = $node->content['body']['#value'];
//Printing content.
echo $node_content;
?>

```

The page I've tried this on prints the ID in the block (as expected) but not the body of the node with that ID.

My hunch is that `$node_content = $node->content['body']['#value'];` can't be used in a block.

Any thoughts? Thanks!

# Answer
> 4 votes
I found out how to do this:

```
$node_id = basename($_SERVER['REQUEST_URI']);
$node = node_load($node_id);
echo $node->body['und'][0]['value']

```

I have also found out that there is probably a better way to do this using field\_view\_value(), but I am not quite sure how that works.

# Answer
> 2 votes
Why are you calling node\_view here if not using the output.
It is better to do as under...

```
$node_content = node_view($node);
echo $node_content;

```

This should work!

---
Tags: blocks
---


# Question
Title: Google translate service not available on Translation Management module(Drupal 6)
When I using the translation management to translate my node, I got "Google translation failed to Chinese, Simplified: Google returned error #403: Quota Exceeded. Please see http://code.google.com/apis/language/translate/overview.html", anyone know what happen and how to fix it?

Thanks

# Answer
Like is said on that page http://code.google.com/apis/language/translate/overview.html access to Google Translate API is now limited.

If you still want continue to use the module you should have a look into this discussion http://drupal.org/node/1215426 where they are looking for another solution.
> 1 votes

---
Tags: i18n-l10n
---


title: Relocate Views' pager

text:
# Question
Title: Relocate Views' pager
I'd like to relocate the pager generated by views and put it, in my page.tpl.php part, in order to display it at the very bottom of the page.

Is this possible?

I tried copying this code from a view to page.tpl.php but it didn't work:

```
  <?php if ($pager): ?>
    <?php print $pager; ?>
  <?php endif; ?>

```

# Answer
> 2 votes
Copying this code snippet into your `page.tpl.php` won't help because the `$page` variable will not be defined for this template. You can only move it freely inside the `views-view.tpl.php` template.

You can add a similar `$pager` variable to your page template using your theme or module's implementation of `hook_preprocess_page()`. In this implementation, you can retrieve the current page's view (if any) using `views_get_current_view()`. See the `template_preprocess_views_view()` function in Views' `include/theme.inc` for how to generate the pager from a view object. In Views 3.x the pager is build by the query plugin.

---
Tags: views, theming, paging
---


title: Some cck fields not turning into HTML

text:
# Question
Title: Some cck fields not turning into HTML
This happens in my custom Zen-based theme where I made a custom node type 'events'. I put print\_r($node) inside of my node-events.tpl.php which gave all the ckk fields including the ones that didn't turn into HTML i.e. not displayed.

When viewing this type of node in a stock drupal theme, this problem doesn't occur so everything gets displayed as desired. This means my viewing permissions are in check and also under *admin-\>content type-\> 'events' -\> display fields* hidden is turned off (set to standard just the way it was when I didn't have the problem)

# Answer
I still don't think I'm understanding the symptom.

If something shows up in one theme and not the other I would check if you have anything wierd in your template.php or if you have overridden any of the content-field.tpl.php files
> 0 votes

---
Tags: 6, entities
---


title: Autocomplete term widget (tagging)

text:
# Question
Title: Autocomplete term widget (tagging)
I was using the "autocomplete term widget (tagging)" as widget type for a term reference field. I found out that the when I set the maximum number of allowed values to more than one (i.e multiple choices), the auto complete does not work after you have added one option.

Do you have any idea on how to work around this?

# Answer
I too am using autocomplete for a term reference field and multiples are working fine - are you sure you're putting commas between terms? e.g. I type "one, t" and as I type "t", "two" will come up as a suggestion if the term is in the vocabulary.
> 4 votes

# Answer
You can try with the "," symbol after each new word: It is working fine for me on IE 6 and Firefox 1.5.
> 1 votes

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


# Question
Title: How can I use the form control in a drupal form?
In Drupal forms API there is a control type called "form" which, I think, allows nesting forms inside other forms. There is no usage example out there and the search term is a bit tricky so Google couldn't help. Would you please tell me how can I use this control in my forms ?

# Answer
You cannot nest forms . I think the `form` element type is the implicit type of the root element (ie. the array) build by a form builder. It is included in the Form API documentation to document its properties and for completeness.

If you need to group elements inside a form together, you can use a fieldset or container element.
> 2 votes

# Answer
Forms can not be nested in HTML. Since Drupal generates HTML, this should not be possible.
> 2 votes

---
Tags: 7, forms
---


# Question
Title: How should I create a main page with a mix of dynamic and static content?
I apologize for the terribly basic question but I'm not even a particularly adept web dev. I've read that Drupal is great if you know exactly what you want to do (then the API is handy) but I don't even know what I need yet. That is what I am hoping to gain from this discussion.

I want a main content page which has a fancy content slider (using jQuery or something) which will be a selector for showing some basic information on these 2 or 3 subjects. I'm stuck on where I should be writing this mix of markup. In the template? Create "content" through a content type? Since there's a fair share of CSS and markup required to do this, I don't know if I can do that through the "basic page" content type that was there.

I'm looking for pointers that can teach me how I would become aware of what Drupal can and can not do.

# Answer
> 2 votes
There are a number of options available to customise the front page -

have a look at http://www.devdaily.com/blog/post/php/how-customize-content-front-page-drupal

I usually go the route of creating a custom page-front.tpl.php (as explained in the link above) and then use a combination of views and blocks to get in the content I need.

hope this points you in the right direction...

---
Tags: theming, nodes
---


# Question
Title: Set default value for taxonomy list using form_alter
how do I Set default value for taxonomy list? I have tried altering form with the following line included, but it didn't work:

```
$form['taxonomy'][3]['#default_value'] = 6;

```

3 is my VOC ID and 6 TID that I want to select as default

# Answer
> 3 votes
If you are using hook\_form\_alter I believe this will work

```
$form['taxonomy'][3]['#default_value'] = array(0 => 6);

```

---
Tags: taxonomy-terms, forms
---


# Question
Title: Email field does not show up when I view node, only when I edit
I have an email field in an entity. The text field is there when I edit the entity but it does not display when I view the entity. How do I get it to display when viewing?

# Answer
Check 'display fields' in your content type settings.
> 2 votes

---
Tags: 7, entities
---


# Question
Title: How to change the output of a multiple image field for a node?
I have a content type (called **Gallery**) with a image field (called **field\_gallery**) which allows to upload and show 10 images.

Now I create a node and upload the images. The output shows those images wrapped with a div tag. Like:

```
<div class="field-item even"> <img …. /> </div>
<div class="field-item odd"> <img …. /> </div>
<div class="field-item even"> <img …. /> </div>

```

Instead of this I need it to be something like:

```
<img class="field-item even"  …. />
<img class="field-item odd"  …. />
<img class="field-item even"  …. />

```

How can I accomplish this. Should I use an alter function? How? thanks

# Answer
1. You can overwrite the field output template, e.g. field--field-name.tpl.php, or a module template, if that's the case. See http://drupal.org/node/1089656.
2. You can overwrite the node template for this content type (node--type.tpl.php). Type in `<pre><?php print_r($node); ?></pre>` to find the element you want. For template information, see http://drupal.org/node/1089656.
3. You can create a page in Views.
> 3 votes

---
Tags: nodes
---


# Question
Title: Delete option 'None' of the select list of a cck field
How can I delete the option -None- of the select list in a cck field. The field is not required.

# Answer
> 2 votes
I have created a module and used `form_alter` hook to remove the `None` value of a CCK select list:

```
<?php

function MODULENAME_form_alter($form, &$form_state) {
    //dsm($form['form_id']['#id']); //dsm() used for see the ID of form
    if ($form['form_id']['#id'] == 'edit-test-content-type-node-form') {
      $form['#after_build'][] = 'change_form_values_after_build'; //call to a function
    }
}

function change_form_values_after_build($form, &$form_state) {
  $new_array = array();
  $new_array = array('Yes' => 'Yes','No' => 'No');
  $form['field_test_select_list']['value']['#options'] = $new_array;
  return $form;
}

```

In this case, I have used the function `change_form_values_after_build` (introduced by `#after_build`) to introduce the desired values in an array, but I guess that you can make a database query, to retrieve the options that you have added in the interface of field, and remove the undesired value, to return again to the form the array with correct values.

I hope information be useful.

# Answer
> 2 votes
Make the field *required* in Global Settings.

---
Tags: entities
---


title: Import multilingual node in Drupal6

text:
# Question
Title: Import multilingual node in Drupal6
Suppose I have 100 nodes in language of English, I am going to import another 100 nodes with different language but same content.

I want to ask is there any module can establish the relationship between two node(with different language), as a result I can change to another language of the existing node by clicking the language switch button?

Thanks

# Answer
> 1 votes
Found a article at drupal.org and trying to implement it

http://drupal.org/node/907542

---
Tags: i18n-l10n, importing-exporting
---


# Question
Title: How to change dropdown field function to buttons in privatemsg module
I am using private message module.

In that there is a option to mark the messages as read and unread using drop down.

Here it looks like : http://drupal.org/node/709180

**Instead of that i need to place two buttons called "Mark as Read" and "Mark as Unread" and needs to perform the same action.**

How can i do it?

Any help will be grateful.

Thanks in adavnce...

# Answer
> 0 votes
It can be achieved by the following way:

```
function yourmodule_form_alter(&$form, &$form_state, $form_id) {

switch ($form_id) {

    case 'privatemsg_list':

    // Removing Adding  Dropdowns and adding button for the "Mark as read" and "Mark as unread" function
    $form['actions']['#prefix'] = '<div style="display:none">';
    $form['actions']['#suffix'] = '</div>';

    $form['mark as read'] = array(
      '#type'   => 'submit',
      '#value'  => t('Mark as Read'),
      '#weight' => 15,
    );

    $form['mark as unread'] = array(
      '#type'   => 'submit',
      '#value'  => t('Mark as UnRead'),
      '#weight' => 15,
    );

    $form['delete'] = array(
      '#type'   => 'submit',
      '#value'  => t('Delete'),
      '#weight' => 15,
    );
    break;
}

```

And it's done..

# Answer
> 1 votes
You can implement `hook_privatemsg_thread_operations_alter(&$operations)` (unfortunately not documented but called in \_privatemsg\_action\_form()) to change the mark as read and mark as unread operations to use a button, as does delete. They are defined in privatemsg\_privatemsg\_thread\_operations().

Something like this:

```
<?php
function yourmodule_privatemsg_thread_operations_alter(&$operations) {
  $operations['mark as read']['button'] = TRUE;
  $operations['mark as unread']['button'] = TRUE;
}
?>

```

Note: This requires Privatemsg 6.x-2.x

---
Tags: 6, privatemsg
---


# Question
Title: The link/button "Add content set" was disappeared (Drupal6)
According to the post http://drupal.org/node/907542, It mentioned \[Go to Admin \> Content Management \> Migrate and click on "Add content set"\].

However, I can't find the link/button of "Add content set", I have install migrate module to another test server, but not works. Could someone advise how to fix it?

Thanks

Reference:

# Answer
> 1 votes
Solved by installing the migrate module of version with 1.x

http://drupal.org/node/966190

---
Tags: migrations
---


title: How to debug Drupal Forms

text:
# Question
Title: How to debug Drupal Forms
Sometime back I'd gone through a Lullabot video that showed me how to simply click a form and see all its elements using Krumo using Devel module.

But I've searched all internet I'm not able to find this feature. How do I simply click a form and see all of it's elements in Krumo?

# Answer
> 3 votes
You need just to implement the `hook_form_alter` in a test module this way:

```
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'taxonomy_form_term':
      dpm($form);
      break;
  }
}

```

where `$form_id` is form identifier (in the example code I captured the new taxonomy term entry form) which you can find through firebug.

# Answer
> 1 votes
Try the Drupal For Firebug module.

# Answer
> 1 votes
It has been a while since I touched this, but you may be referring to Devel Themer. Devel had this functionality, but it had been spun off separately to Theme Developer.

# Answer
> 1 votes
Krumo is a replacement for print\_r() and var\_dump(). Have you tried Devel + Theme Developer module? They are a must.

Krumo is included inside Devel module as stated here: http://drupal.org/project/krumo

If you have drush installed alread the commands are:

```
$ drush dl devel devel_themer
$ drush en devel devel_themer

```

Otherwise you need to download them via drupal.com and manually install and activated them.

Here is a screencast about debugging: http://ftp.drupal.org/files/videocasts/moshe-theme-developer.mov Good Luck!

---
Tags: 6, debugging
---


# Question
Title: Drupal 7 views contextual filter (taxonomy: summary display), displaying a readable term-name instead of term-id
Within my view, I'm using a **contextual filter**—with a default "**summary output**"—to filter my results by **taxonomy term**.

The problem is that the **summary-result** is grouped by a listing of taxonomy **term-id's** (including a node count) and not human readable term-id names.

* (21)
* (16)
* etc.

Is it possible to change (or hook) the view output of the summary, by not listing its term-id's, but the term-id-name?

* Term name A (21)
* Term name B (16)

(It doesn't bother for me if the actual request URL stays the same.)

My goal is to create a more readable output-format of my taxonomy-term summary, which an end user can understand.

# Answer
> 7 votes
1. Set your view to fields and expose the field that contains the associated taxonomy term.
2. Set your contextual filter to filter for a taxonomy term and select to include a validator.
3. Set the validator to taxonomy term and check the box for your vocabulary.
4. Select the option for filter value type as ' Term name converted to Term ID.
5. Save the filter and go to the preview box. If you enter the text name of your term, you should see the desired content.

If you are passing the information from the URl you may have to select the 'Transform dashes in URL to spaces in term name filter values' checkbox as well since the machine name uses dashes

# Answer
> 5 votes
Copy the "views\_view-summary.tpl.php" file your "modules/contrib/views/theme" folder. (You can make it view or block specific by adding a filename-suffix.)

**Note:** If you use this as a admin view-display, make sure you copy this file within the admin theme folder, not your default theme folder!

You don't need any changes in your display-settings. Just adjust your tpl-override to the following lines, and your Term-ID's are converted to readable Term-names:

```
<div class="item-list">
  <ul class="views-summary">
    <?php foreach ($rows as $id => $row): ?>
    <li>
      <a href="<?php print $row->url; ?>"<?php print !empty($row_classes[$id]) ? ' class="'. $row_classes[$id] .'"' : ''; ?>>
        <?php
        /* begin replacement */
        $term_object = taxonomy_term_load($row->link);
        print  $term_object->name;
        /* end replacement*/
        ?>
      </a>
      <?php if (!empty($options['count'])): ?>
       (<?php print $row->count?>)
      <?php endif; ?>
    </li>
    <?php endforeach; ?>
  </ul>
</div>

```

# Answer
> 1 votes
There is an article on Drupal easy: Using display attachments to provide a consistent summary in Views 2.

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


# Question
Title: Is it possible to set up preferrential IPs when in maintainance mode?
I've previously worked on Prestashop and there I had the choice to set my site in offline/maintance mode and then edit one ore more IP addresses in order other people to view the sites but not the commmon users and stills no login require and no additional host file settings.

Thanks

# Answer
> 1 votes
No, it is not possible by default. The feature can be however extended via a module.

# Answer
> 4 votes
Actually on Drupal you can create a new role and assign permission to this role to login in maintenance mode (Add permission "System \> Use the site in maintenance mode").

If this is not what you want, then you can filter IP addresses on firewall /linux level. Please ask on https://serverfault.com/ if you need this kind of solution.

# Answer
> 0 votes
Not that I know of. Maybe there is a module for that. I would do it with an .htaccess host file.

---
Tags: maintenance-mode
---


title: add unpublished content to pane

text:
# Question
Title: add unpublished content to pane
As the maintainers of panels are not really reacting, my questions here:

I am creating panel-nodes which should be filled with existing content. I need to have a preview functionality, so the user can add the panel-node and the unpublished content, review it, and finally publish everything.

as admin (user/1) I can do so without any problems, but other authed user with the permission to add all content-types etc. cannot. they can open the dialog add content to pane \> exisiting node. they can choose the unpublished node in the autocomplete field. but after submitting the form (Finish) they get the message "Invalid node". this happens only with the unpublished nodes.

Is that a bug or am I missing something?

update: http://drupal.org/node/1294792

# Answer
I only could solve it by giving the user the `administer nodes` permission. any permission control modules wouldnt help.

update: this wont be fixed :(

-\> http://drupal.org/node/1294792#comment-5193104
> 0 votes

# Answer
I've never used panels, but it can be a permission problem. As far as I know, to view and publish unpublished content you need to have set the "administer nodes" permission. To let some roles manage certain unpublished content types without granting them more than they needed, once (in D6) I successfully used the view\_unpublished and Publish content modules.

Hope it helps.
> 0 votes

---
Tags: 7, users, panels, chaos-tool-suite
---


# Question
Title: Hooks and preprocessor confusions. A few important questions
I've been using Drupal now for a pretty long time, but this whole hooks and preprocessor thing still gets me confused. And I can't seem to really find a structured documentation to help.

Intuitively it feels like changing a contrib module is not part of theming, but more of module extending / modifying, but it is also theme-specific, so it's confusing to know if this topic is indeed related to the above or not.

Here are some of my questions that I am still left with:

***1. are function hooks used in modules the same as theme hooks used in the theme?***

***2. if a contrib module uses a "hook" is this something i can override or extend in my theme?***

***3. if a contrib module uses a hook, say: hook\_block() can I then hook the hook to change the module's output?\***

example: inside the contribmodule.module file:

```
contribmodule_block() { $variables['foobar_item'] = 'foobar item'; }

```

can this be overriden by the following in the template.php file?

```
contribmodule_preprocess_block() { $variables['foobar_item'] = 'new item'; }

```

Is there a guide for all the fundamental concepts? All i can find is the API for hooks, but that says really nothing at all about it other than giving a list of available hooks; zero theory there.

***4. if a contrib module has a function which I can NOT override with a hook onto a hook, then how do i change what the contrib module does for my theme? am I forced to hack the code of the contrib module?***

# Answer
1. Not quite. Generally speaking, normal hooks are used to control the behavior (functionality) while theme hooks are used to control the appearance of your site. If you want to understand more about hooks, you may want to read What are the different types of hooks?.
2. Since Drupal 7, you can implement hooks in your theme. That said, the best practice is to put alterations to the site behavior in a custom module, and use your theme only for alterations to the appearance.
3. That depends on the hook. The output of a block can be altered by implementing hook\_block\_view\_alter.
4. All modules that are built 'the Drupal way' should use theme hooks and render arrays to generate their output. You can always implement a preprocess function in your template.php to alter variables before they go to a template, or override a theme function or template to make it do what you want. See the Theme guide, more specifically Overriding themable output to learn more.

I hope that answers your questions.
> 6 votes

---
Tags: hooks, theming
---


# Question
Title: What is the hook to alter workflow access permissions?
In the *Workflow* module, How can I programmatically change permissions? In addition to roles I want to check against a proflie value to allow or not allow users see or edit a node in a specific workflow state.

# Answer
> 3 votes
There is no single hook that allows you to control who can see or edit a node in a specific workflow state. You might want to implement hook\_node\_access\_records() to give out grants for a specific node and hook\_node\_grants() to check whether a specific user has that grant.

The result of your `hook_node_access_records()` implementation is stored in the database and checked via your `hook_node_grants()` implementation. Have a look at node\_access() to see how the latter is done.

I cannot tell you off-hand what to use as realm and what to use as grant ID. The most important restrictions are:

* the grant ID is an integer,
* `hook_node_access_records()` does not know which user tries to access the node,
* `hook_node_grants()` does not know about the node that is being accessed.

In your case, it seems reasonable to put the expected profile value into the "realm" (along with the module name for disambiguation) of your `hook_node_access_records()` implementation. Your implementation of `hook_node_grants()` would then check whether the user has that profile value and return the appropriate realms. Still you need to accommodate for the workflow state somewhere.

---
Tags: 6, workflows
---


# Question
Title: How to access Field-settings in the widget formatter
I am writing a cck-widget/field and formatter. My field-settings contains a "base\_url" setting. If I draw that out:

`http://example.com/ [_some/path/to/a/file.avi________]`

`http://example.com` is the base\_url. `some/path/to/a/file.avi` is what user provides and gets stored in database.

The formatter should append that base\_url to the user-supplied values:

```
function theme_video_url_formatter_embed($element) {
   return "$element['base_url']/$element['#item']['safe']";
}

```

How can I pass the variable from field-setting `$base_url` along, so it ends up in that formatter-theme-function?

# Answer
> 2 votes
You can take number.module from the CCK package as an example; it allows prefix and suffix values in the field settings that are rendered in the formatter.

In `theme_number_formatter_generic()` the field settings are retrieved using this code.

```
$field = content_fields($element['#field_name'], $element['#type_name']);`

```

The values are then taken from `$field`, sanitized, and added to the output.

---
Tags: 6, entities
---


# Question
Title: views with different content types case studies
For my first Drupal site ever I was thinking of filling the frontpage with a view that has different content types. I'm even mixing page content type with a custom event content type so now I have problems with styling the view because of different content fields in different view items.

Does anybody know of case studies where people have succesfully mixed custom with stock content types because this is becoming a nightmare.

# Answer
Views gives you enough power to maintain your custom styling. Please check for Views for `theme information`.

You can theme your different fields, rows, general theme.

You can style your node.tpl.php for general and for specific type node-\[type\].tpl.php
> 1 votes

---
Tags: views, 6
---


title: Drupal module not getting menu blocks?

text:
# Question
Title: Drupal module not getting menu blocks?
I have a drupal module creating a new page using a menu hook. And I have menu blocks (menus displayed as blocks) that SHOULD be showing up on the drupal module page. But I cannot seem to get them to display? How can I get these menu blocks to show up? I tried added it to a menu and that did not work.

Create Menu

```
  $items['gift_cards'] = array(
    'title' => 'SELECT A CARD',
    'page callback' => 'uc_gift_certificate_order_page',
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

```

This is the function to make the page, it is simply a drupal form.

```
function uc_gift_certificate_order_form($form_state) {
    // This is the function that generates the required page for ordering the gift card.
    // Load the required datepicker JS/CSS
    drupal_add_css(drupal_get_path("module", "uc_gift_certificate").'/datepicker/css/datepicker.css');
    drupal_add_js(drupal_get_path("module", "uc_gift_certificate").'/datepicker/js/datepicker.js');

    // We already have the block part (gift card rotator)
    // Display the form
    $form['#attributes'] = array('class' => 'gift-card');
    DRUPAL FORM API STUFF
}

```

# Answer
> 2 votes
Page callback should be `drupal_get_form` in your hook\_menu and form definition handler should be passed as argument.

```
$items['gift_cards'] = array(
   'title' => 'SELECT A CARD',
   'page callback' => 'drupal_get_form',
   'page arguments' => array('uc_gift_certificate_order_page'),
   'access callback' => 'user_access', // no need to define in case of user_access
   'access arguments' => array('access content'),
   'type' => MENU_CALLBACK,
);

```

---
Tags: 7, routes, hooks
---


# Question
Title: Advice needed on approaching to Drupal 6 and jQuery Mobile
I'm pretty new to this 'world of Drupal', and I've got this project, where I need to build a jQuery Mobile site based on an existing Drupal 6 site.

The mobile site is somewhat different in it's structure, but needs to get some data/content from the original site.

What is the best approach to his project? Should I build the mobile site based on the same Drupal-installation, as the original site? Or should I build a new site using Drupal 7 and then somehow export/distribute content from the original site?

I've read a couple of articles claiming it's quite difficult to upgrade jQuery to version 1.4.4 in Drupal 6, which is needed to run jQuery Mobile. Is that so?

My concern is, that I'm not a PHP Jedi Master (though I know some PHP), and therefore it would be great, if some could tell me, what the best approach is to this.

I found this articles yesterday: http://www.adyax.com/en/tutorials/make-mobile-version-your-drupal-site-using-jquery-mobile-and-some-magic/lets-get-started. Is this what I should be doing?

# Answer
I personally don't recommend splitting the project in 2 sites but rather in 2 themes. If the project is slightly different (I assume you however use the same database) then try to customized it via theme (and theme functions).

I suggest you use the Omega/Fusion Theme which are responsive themes. A responsive theme doesn't need a special redirection.

However if you need more customization in additional install Mobile Tools Module.

Then create a domain called m.domain.com in additional to your site domain.com and set inside the Mobile Tools Module based on a agent to switch to the theme needed.

There's indeed no need to install Drupal again. You should ask your host to treat the m.domain.com as an alias for domain.com. That way it points to the same Drupal installation and the theme switch can take place.

If you don't have a mobile to test install Firefox addon: https://addons.mozilla.org/en-US/firefox/addon/user-agent-switcher/
> 1 votes

# Answer
I would stick to one code base and use a module like ThemeKey to switch themes based on useragents. Themekey is available for both Drupal 6 and 7 so you might be best going the Drupal 7 route for a newer version of jQuery.

If you would like to only use one theme then like Onirio says you can use Omega theme for reactive design. Omega is pretty powerful but from what I've seen it has a fairly steep learning curve.
> 0 votes

# Answer
Didn't realize how that you had to use two patches, one to core and one to jquery\_update http://echodittolabs.org/blog/2010/08/drupal-6x-jquery-142-new-possibilities, to get jQuery 1.4.4. Personally haven't needed to use that version yet. If the sites are not sharing that much content to make them use the same codebase then the domain module is not needed.

It seems to me that it would be less trouble to create another site in drupal 7 that is the mobile version and then create the proper redirects for mobile devices. You could still share content between sites through the feeds module. At least with this route you wouldn't have to hack around just to get the right jquery version.
> 0 votes

---
Tags: 6, javascript, theming
---


# Question
Title: In terms of performance, is it better to lazy load, inline, or hook_init a Javascript library?
I'm working on a module to embed Highcharts into nodes. Other chart modules provide a PHP helper function to trigger the necessary library loading. To avoid enabling the PHP module, I tried creating an input filter with a token for loading the Javascript library. Unfortunately, filter output gets cached, so calls to drupal\_add\_js within a filter function don't get called on every page load.

I can think of a few workarounds:

* a small inline script to load the library, after a node containing a chart has loaded
* embed the whole library file inline, on pages where it's needed
* load the library on every page, via hook\_init

From a performance perspective, what is my best option?

For what it's worth, the compressed Highcharts library is 81k. The site I plan on using this on has Javascript aggregation enabled, but few content items will have charts, especially initially. Plus, I'd like to contribute the module on d.o, so I'd like to solve this in a way that would make sense on most sites.

# Answer
You could also hook into the node's presave, check whether the body contains whatever it is, then set a flag on the node (perhaps using flag or taxonomy) if it does. Then on view, you look for the flag and use drupal\_add\_js if necessary. This will survive the cache and let you aggregate the script if you want to. If you'd prefer, rather than storing the flag in the DB, you can check for highcharts on every view (via hook\_nodeapi()) and just add the JS there directly.

Btw, strongly recommend against the hook\_init() approach - there are definitely better ways imho. hook\_init is called on every full bootstrap, which includes eg. 404s and imagecache generation (as well as every normal node view). Generally it's a good idea not to use this if your code is only needed in specific circumstances (eg. only when there's Highcharts code embedded). In those situations, you want to find a way to add your code only to appropriate pages.
> 3 votes

# Answer
That's kind of a toss-up. Note that 81kB is the "minimized" size - when gzipped it's further reduced to 32kB. Still, I'd lean towards inline - adding `<script src="...highcharts.js" />` in the filter output. This tag will survive the filter cache, and you won't inflate the aggregate on pages that don't display charts. The browser will cache the file after the first load.

For size comparison, a default Drupal 7 install includes about 50k (gzipped) of scripts on the home page.
> 2 votes

# Answer
I don't know exactly how will be your implementation of embeding, but I think filter solution is too intrusive. If later on you decide to stop using this module, you will have those tags in the content of your nodes

Probably a good intermediate solution would be to use the hook nodeapi view, to add the js needed with drupal\_add\_js, and have an admin settings page to enable this feature per content type.

Once that the user has downloaded first time the library, it's cached by the browser, so not big deal.

Inline script tags can't be aggregated by Drupal core. And they will block the browser (rendering the page) to start downloading the library. It's better to load the library in the bottom of the page or async way. Mikeytown knows more about this. ;)
> 1 votes

---
Tags: javascript
---


# Question
Title: Getting fields of a content type in template file - creating a slideshow
I need to add a slideshow *(each slide containing headline, image & html text)* in my frontpage. I've decided to create a custom `content type` named *slideshow* which should have above *fields*.

I've figured out the necessary `.tpl.php` file (*page--front.tpl.php*) in which I'll add codes to go for the slideshow.

## What I've done already

* Created a custom `content type` named *slideshow* with all the appropriate `fields`
* Added all the necessary html for the slideshow in the `.tpl.php` template file - with necessary javascripts already included using the `.info` file of my theme.

## Now the problem:

* I think I'll fetch data from database & populate the variables needed in `.tpl.php` file in: `preprocess` function of `template.php` file of the theme. **How do I retrieve the `fields` of *slideshow* `content type` from database?**

Please help!

# Answer
> 3 votes
If I understand well your question, I guess that node.tpl.php is more suitable for use templates per content types an control over individual fields:

page.tpl.php: Default theme implementation to display a single Drupal page.

node.tpl.php: Default theme implementation to display a node.

About **how to name your templates** according your needs, see this documentation: Drupal 7 Template Suggestions http://drupal.org/node/1089656. Regarding your case, I guess, a template for content type, the name could be `node--slideshow.tpl.php`. see this answer that have information related with node.tpl.php.

and about how to see your fields, the same link to the answer have one example:

I have a field called `field_demotext1`, then this is the way that I can use to call their respective value inside any custom html zone of a node layout:

```
print $content['field_demotext1']['#items'][0]['value'];

```

whit `print_r($content);` (or `dsm($content);` if you use Devel module) you will see fields that can be pulled. this screenshot is using `dsm($content);` related with the example;

Render Drupal API is an alternative to the previous way. In this way you does not need seek the file using `dsm()` or `print_r()`

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

```

Also, seems that field\_view\_field is another alternative to render Drupal fields. see this related document:

I hope information be useful.

# Answer
> 2 votes
## First solution :

Use the function "db\_select" and make a SQL query

## Second solution :

Utiliser the function "node\_load" but it will get the node you want.

---
Tags: 7, entities, database, theming
---


# Question
Title: How to output a screen from a submit handler? (D7)
Based upon a form's values In my submit handler I build the output screen and display it with a `drupal_set_message();`. I'm trying to figure out how to display the information on a page. I can't find any examples. I've created a theme, which is probably unnecessary, but again, I don't know how to display it.

# Answer
You want output form values after form on submit?

```
function mymodule_myform($form, $form_state) {
  $form['mytextfield'] = array(
    '#type' => 'textfield',
    '#title' => 'My Textfield',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  if (isset($form_state['values'])) {
    $form['page_output'] = array('#markup' => 'Submitted value: ' . $form_state['values']['mytextfield']);
  }
  return $form;
}

function mymodule_myform_submit($form, &$form_state) {
  $form_state['rebuild'] = TRUE;
}

```
> 2 votes

# Answer
Please elaborate, what you want to achieve. Output what exactly? What the user filled in the form? What does the form do? Email? Maybe https://drupal.org/project/webform is what you need?
> 0 votes

---
Tags: 7, forms
---


# Question
Title: some cck fields of content type not displayed (corresponding elements also not showing in devtool)
Out of the blue it happened that a custom content type won't display some of the cck fields I constructed for the custom content type. This happens when I just visit the a full node of that content type. When I go see in firebug, I also notice that the HTML elements to those custom made fields are entirely missing.

* I checked the display options under admin-\>content type-\>customcontenttype and everything looks the way it should.
* I checked view permissions and those are also set for anonymous and
admin roles.

Does this sound familiar to someone that cck fields cease to be displayed in full node?

# Answer
I wrote an advanced version of this question that's supposed to be more clear. It's here
> 1 votes

# Answer
You say you enabled all modules under CCK which means you probably have `Content Permissions` enabled.

`Content Permissions` module gives you per-cck-field view/edit permissions (which are all off by default!). Check that you have the correct permissions set for your fields or disable the module if you don't need that granular control.
> 1 votes

# Answer
Navigate to admin/content/node-type/my-node-type-name/display, and check that "Exclude" is enabled for "Full node".
> 0 votes

---
Tags: 6, entities
---


title: Show unique full content on front page

text:
# Question
Title: Show unique full content on front page
How do you do this in Drupal 7? I would like to place the following items that are unique to the home page:

1. A views\_slideshow
2. A row of 3 large images
3. Some normal typed content
4. 3 most recent Articles

I could manage this on a normal page, but I'm not sure how to put it on the home (front) page.

# Answer
You may be interested in the Panels module. You can create custom layouts, include views/custom content, and more.

From the project page:

> **An Overview of Panels**
> The Panels module allows a site administrator to create customized layouts for multiple uses. At its core it is a drag and drop content manager that lets you visually design a layout and place content within that layout. Integration with other systems allows you to create nodes that use this, landing pages that use this, and even override system pages such as taxonomy and the node page so that you can customize the layout of your site with very fine grained permissions.
> 1 votes

---
Tags: 7, nodes
---


# Question
Title: Submitting a form with only a text field
I may be missing something obvious, but it appears my form's submit function isn't being run by simply submitting text into my textfield (via. enter). Do I need to add the submit button to get this behavior? Is there a workaround so I don't have to?

# Answer
> 0 votes
Yes, for basic forms you need to include a submit button for the submit function to be called.

Read more about the Form API for Drupal 7

---
Tags: 7, forms
---


# Question
Title: Difference between theme preprocessor & processor function?
The question is is self-explanatory!

**Another question**, suppose I have a template file named `a-b--c--d.tpl.php`

What would be the preprocessor function for this template file? I suppose `themename_preprocess_a_b__c__d(&$vars)`?

Sorry for my poor knowledge. I'm newbie to drupal & started with drupal 7.

# Answer
> 0 votes
## For the template

If the page is "/my-node", the page template will be "page--my-node.tpl.php".

## For the Prepocess

But you cannot using it "themename\_preprocess\_my\_node(&$vars)" because my-node isn't a hook ! You can find differents hooks with this page http://api.drupal.org/api/drupal and with the search box, type 'theme\_'. You can see the differents hooks for the preprocess

---
Tags: 7, theming
---


# Question
Title: Unlimited values field in Drupal 7 - how to show extra field in page.tpl.php
I know how can I retrieve the first file name

```
$fileupload = $node->field_fileupload[$node->language][0]['filename'];

```

but how can I retrieve the other unlimited file names

# Answer
The best solution would be to run a foreach:

```
foreach($node->field_fileupload[$node->language] as $fileupload) {
  echo $fileupload['filename'];
}

```
> 2 votes

---
Tags: theming
---


# Question
Title: I backed-up my site and now my views are broken
My site recently got deleted by a possible hack. I backed up the database and the folders, but now my views are not working; everything else works.

The fields are showing this in admin/build/views/edit/nameofview:

> Broken/missing handler: node\_data\_field\_guru\_photo \> field\_guru\_photo\_fid
> Broken/missing handler: node \> title
> Broken/missing handler: views \> nothing
> Broken/missing handler: node\_revisions \> body
> Broken/missing handler: node\_data\_field\_guru\_link \> field\_guru\_link\_url

# Answer
> 1 votes
It looks like it is looking for fields that do no longer exists? Have you changed anything in your content types maybe?

---
Tags: views
---


# Question
Title: Getting info from an external database - Base table or view not found
Currently working on getting some info from an external application's database onto my user profile page as a test.

I've run into a snag that I can't seem to get past. This is probably something so simple, but I'm pulling my hair out over it.

I have 2 databases - one is Drupal, and the other is from SocialEngine. These are both hosted on the same server(not localhost).

My error is this: Base table or view not found: 1146 Table 'uitv.engine4\_users' doesn't exist: SELECT email FROM {engine4\_users} WHERE enabled = :enabled; Array ( \[:enabled\] =\> 1 )

Awesome. Okay, well I think I can see the issue here... engine4\_users is actually in the uitv\_social database, while my Drupal installation is in the 'uitv' database. I've used db\_set\_active($social); which relates to my database settings in settings.php - and I've set it back to the default database after I query the social one.

What am I missing here? (Drupal 7 database documentation seems to be blank on this subject)

\[EDIT: I did something silly - use db\_set\_active('yourdbkey'); - and make sure your query is right. Hope this helps a Googler. Curiously, I had done this several times before, but since the query was incorrect it wasn't giving me anything, obviously.\]

# Answer
I know you answered your own question with a solution -- here is additional info.

The helper functions db\_select(), db\_update(), db\_insert(), db\_merge() all use the default database connection defined in settings.php. As you pointed out you can use db\_set\_active() to set an active database within a given scope of code. I personally dont like this approach, because X months from writing the code you will forget that, "oooohhh I used db\_set\_active X lines above" and run into annoying maintenance issues.

There is another solution, dont simply use the helper db functions. Use their parent Objects, which they are wrapping ... as in below:

```
    // 'remote_database' is a 2nd db connection defined in settings.php
    $query = Database::getConnection('default', 'remote_database')->select('survey_item', 'si');
$query->fields('si', array('item_id', 'presentation_order', 'question_type', 'stem', 'choice_1','choice_2', 'choice_3', 'choice_4', 'choice_5', 'choice_6', 'choice_7', 'choice_8'));
$query->condition('survey_id', $current_row->survey_id);
$query->orderBy('presentation_order', 'ASC');
$current_row->form_items = $query->execute()->fetchAll();

```

So you can create a Query as I have above by specifying the connection first. You may do this for all -\>select() or -\>update() or -\>insert() functions which drupal supplies wrappers for.

Or, you can even pass as a 3rd argument to a SelectQuery() constructor the connection to use for the query, see the docs here:

http://api.drupal.org/api/drupal/includes--database--select.inc/class/SelectQuery/7

```
  // This is the constructor for SelectQuery() from select.inc
  public function __construct($table, $alias = NULL, DatabaseConnection $connection, $options = array()) {
$options['return'] = Database::RETURN_STATEMENT;
parent::__construct($connection, $options);
$this->where = new DatabaseCondition('AND');
$this->having = new DatabaseCondition('AND');
$this->addJoin(NULL, $table, $alias);

```

}

So you can also start a db\_select() query as follows to tie it to a non default connection in another means:

```
$query = new SelectQuery('my_table', 'table_alias', Database::getConnection('default', 'remote_database'));
// other things you build onto your query
// $query->addJoins(...); $query->fields(...); ...
return $query->execute()->fetchAll();

```

So in a nutshell -- the db helper functions are convenience when talking to 1 database. Beyond that, you can specify per-query what connection to use ... if you like more fine control of your queries and not use db\_set\_active() all over the place.
> 1 votes

---
Tags: 7, database
---


# Question
Title: How do i create a payment method+gateway with a custom function called by the gateway to determine whether payment is successful?
We're looking to use a payment gateway - SecurePay in this case - that allows merchants to save credit card details in their system and then trigger payments against that credit card again for future checkouts by sending a token representing that credit card, without the user re-entering the details, and we don't need to store credit card numbers in our database.

The native handling of credit cards by UberCart, along with the uc\_securepayxml module was great for the initial transaction, and storage of credit card number + token with SecurePay but the validation step on the checkout screen meant that it looks like I'll have to set up an alternative payment method + gateway to manage the sending of tokens for payment.

The problem that I'm having is getting Ubercart to fire the function that is supposed to either return success or failure when the order is finally submitted when I don't use the 'credit' payment method.

To be clear, the issue isn't (so far :P) sending the data off to SecurePay, it is convincing UberCart to use the return value of my custom function to determine whether a payment is successful or not, without using the supplied Credit Card module.

Here is all the relevant code (I think) that I'm currently using, so some advice on what needs to change or even just a working example would probably be enough to answer my question!

Using Drupal 6 and UberCart 2, and I cleared the Drupal cache a few times, btw.

```
<?php
/* This function creates a new payment method */
function uc_securepaytoken_payment_method() {

  $methods[] = array(
    'id' => 'sptoken',
    'name' => t('SecurePay Token'),
    'title' => t('SecurePay Token'),
    'desc' => t('Pay by triggering a tokenised payment through Secure Pay.'),
    'callback' => 'uc_payment_method_sp_token', /* I believe this callback function just sets some strings for display in various places and the validation when submitting on the checkout page, is that right? */
    'weight' => 1,
    'checkout' => TRUE,
  );

return $methods;
}

/*
* This function sets up the payment gateway,
* I believe that if the 'sptoken' key in the $gateways array matches the ID of the payment method,
* the function named in the value should be fired when I want to process a payment
* (NB - This doesn't actually seem to be happening)
*/
function uc_securepaytoken_payment_gateway() {

  $gateways[] = array(
  'id' => 'securepay_token',
  'title' => t('SecurePay Tokens'),
  'description' => t('Process credit card payments using SecurePay Tokens.'),
  'settings' => 'uc_securepaytoken_settings_form',
  'sptoken' => 'uc_securepaytoken_charge',
);

return $gateways;
}

function uc_securepaytoken_charge($order_id, $amount, $data) {

  /*
  * This is the function that I want to use to process a payment
  * and return success or failed, at the moment it doesn't seem to be working
  * and dpm() doesn't display anything, Ubercart simply always completes checkout without doing this
  */

  }

?>

```

# Answer
> 0 votes
The answer, is that `uc_payment_process()` needs to be called in `hook_order()` when the `$op` variable is 'submit' with the payment method ID as the first argument.

The missing link to bring payment methods, gateways and actual payments together is as follows:

```
<?php

/**
 * Implements hook_order
 * This is the bit that actually gets the method/gateway-combo into gear
 * when an order is submitted in the checkout process.
 */

  function uc_securepaytoken_order( $op, $arg1, $arg2 ) {

    switch( $op ) {
        case 'submit':

          if($arg1->payment_method == 'sptoken') {

            // Attempt to process the payment
            $pass = uc_payment_process( 'sptoken', $arg1->order_id, $arg1->order_total, $data, TRUE, NULL, FALSE);

            // If the payment failed, store the data back in the session and
            // halt the checkout process.

            if(!$pass) {
            $message = 'We were unable to process this payment. Please verify your details and try again. If the problem persists, contact us to complete your order';
            return array(array('pass' => FALSE, 'message' => $message ));
            }

          }

        break;
    }
}

?>

```

The next "gotcha" is that the return value from `uc_payment_process()` is only `TRUE` if your callback function defined by the *gateway* returns an array that looks something like this (but with success = `TRUE`). Check out the uc\_credit module for more clues.

```
<?php
$result = array(
    'success' => FALSE,
    'comment' => 'Invalid transaction type',
    'message' => 'Invalid transaction type',
    'data' => array(
        'module' => 'uc_securepaytoken',
        'transaction_id' => 0,
    ),
    'uid' => $user->uid,
    'log_payment' => 0,
);
?>

```

For further reading check:

---
Tags: 6, ubercart
---


# Question
Title: How can I set a View contextual filter fallback?
Ok I have 2 content-types:

* Page
* Video

I have a block in the sidebar that shows videos embed by youtube.

In the Video content-type, I have a Node References field that can reference any Page-type node.

I would like to set up the sidebar block View so that it can output a random video-type tagged with the current page-type node, however if there are no video-type nodes referencing the current page, or if the current page is not a page-type node, then it would select ONLY video-type nodes that are either (depending on what is simpler to implement):

* Have another field on the video-type which can tag the node as "global" (this would be preferable)
* OR Not referencing any page-type nodes

I was hoping to try and make use of the Context module, but I'm wondering whether the module is quite so granular or conditional?

Thanks!

# Answer
> 3 votes
Ok, decided to write my own context condition plugin for this, all in a single file for a custom module that would be called `custom_context`:

```
function custom_context_context_registry() {
  $registry = array(
    'conditions' => array(
      'views_result' => array(
        'title' => t('Views Results'),
        'description' => t('Set this context when one of these views returns a result.'),
        'plugin' => 'custom_context_condition_views_result',
      )
    )
  );
  return $registry;
}

function custom_context_context_plugins() {
  $plugins = array();
  $plugins['custom_context_condition_views_result'] = array(
    'handler' => array(
      'class' => 'custom_context_condition_views_result',
      'parent' => 'context_condition',
    ),
  );
  return $plugins;
}

function custom_context_init(){
  if ($plugin = context_get_plugin('condition', 'views_result')) {
    $plugin->execute();
  }
}

class custom_context_condition_views_result extends context_condition {

  /**
   * Generate a list of database and module provided views.
   */
  function condition_values() {
    $enabled_views = array();

    $views = views_get_all_views();
    ksort($views);

    foreach ($views as $view) {
      if (!isset($views[$view->name]->disabled) || !$views[$view->name]->disabled) {
        $displays = array();
        foreach ($view->display as $id => $display) {
          $displays[$view->name . ":" . $id] = check_plain("{$view->name} : {$display->display_title}");
        }
        $enabled_views += $displays;
      }
    }
    return $enabled_views;
  }

  function execute() {

    $view_name_displays = array();

    // Gather all required views for checking, to prevent duplicate checking
    foreach ($this->get_contexts() as $context) {
      foreach ($context->conditions['views_result']['values'] as $view_name_display){
        $view_name_displays[$view_name_display] = $view_name_display;
      }
    }

    foreach($view_name_displays as $view_name_display){
      list($view_name, $view_display) = explode(':',$view_name_display);
      $view = views_get_view($view_name);
      $view->set_display($view_display);
      $view->build();
      $view->execute($view->current_display);
      if(count($view->result)){
        foreach ($this->get_contexts($view_name_display) as $context) {
          $this->condition_met($context, $view_name_display);
        }
      }
    }
  }
}

```

Just to explain how this works, it loads all the views which context module should check on hook\_init and checks whether each view has rows or not. I've combined this with certain views which obtain their contextual filters from the current node ID.

---
Tags: 7, views
---


# Question
Title: Approach to adapting a traditional PHP solution into a Drupal module
I find that traditional PHP development strategies don't help a great deal when trying to mould Drupal into areas it isn't directly built for and I'm hoping for assistance in how I might approach Drupal module development starting with a traditional approach.

I specifically have a project where I know pretty much how I would tackle it in PHP but am a babe in the woods trying to get this to work in Drupal.

I have new tables that I'm adding to the database that reference the 'user' and 'node' Drupal tables. The data used in the site from these tables will have some fairly complex SQL joins etc.

I will be needing a block or two; some summary pages; various admin pages; and permissions and access control for different items.

I've generated my rough wireframes but now I need to get this working in Drupal!

My traditional approach would be to create a class file for the data handling and then build pages or classes to handle the various views and controllers. Template files would be used for individual pages/blocks.

With this in mind what is the best approach to make this work in Drupal - or do I really need to think differently?

For my development environment I'm using PhpEd and running DrupalForFirebug in Firefox. I also use the Devel module and Themer where I need to. Building themes in Drupal is not a big issue for me but modules are something I've avoided.

Thanks :)

# Answer
> 1 votes
Here is what I would do (Drupal 7 assumed):

* Look into http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook\_schema/7 for defining your tables. You don't need to do anything special to reference node and user; Drupal doesn't make heavy use of foreign keys. Look into the database abstraction layer to get an idea of the functions you can use to interact with the database. `db_select` is particularly cool and naturally supports joins.
* You may also want to look into Data and Views. Through the use of these modules, you may be able to cut down on the amount of custom code you have to write.
* For the blocks, it depends on if they have dynamic or static content. If dynamic, look into Example: Block. If static, check out the Boxes module. Also look into Context as an alternative for placing the blocks instead of using the block visibility settings. This is assuming I understood your use of terminology when you said blocks.
* For the pages, look into hook\_menu. You can define your own this way; of course, you can also just create pages through the interface...so it depends again on what you meant.
* Your development environment sounds fine. You'll find the tools you like as you go along.
* There'll be a learning curve, but what you learn will be *extremely* reusable across future sites you build. It's worth it.

---
Tags: 7
---


# Question
Title: List of favorite articles based on number of visitors
I am working at a magazine type web project. I would like if someone would suggest me a way to display in a block the list of favorite articles based on numbers of visitors.

I assume views can do that but I need a counter for visitors who access the articles.

Thank you. Any idea is welcomed.

# Answer
> 2 votes
In the module list, you've a module named Statistic enable it and you'll have a block that show the articles most visited in the past 7 days or 24 hours.

Also, with Views you'll able to create blocks/pages as you want.

---
Tags: views
---


title: Looping Rules without Lists

text:
# Question
Title: Looping Rules without Lists
I have an online store using `commerce` and `rules`, with products that can be bought in different quantities. Commerce stores the line-items in an order as a list, but it stores the quantity-per-line-item as a flat number.

I have a rule that needs to fire once for each tangible product- ie. `number of line-items` x `quantity`.

Rules can loop over lists, but I don't have a way of representing the quantity as a list. Is there a way to loop using just a number? Is there a way to turn a raw number into a list Rules can loop over?

# Answer
I ended up doing this with the 'execute custom PHP code' action. I created a 'Do Foo Once' component with the UI, and then added this to 'Do Foo N Times':

```
for ($i = $quantity; $i > 0; $i--) {
  rules_invoke_component('rules_do_foo_once', $i, $bar);
}

```
> 4 votes

---
Tags: rules, commerce
---


# Question
Title: How call a custom function after input got validated in hook_form_alter?
I want to call custom functions for doing some profile filed updation on user registration. So i used to implement my custom functions in hook\_form\_alter. The code is here

```
<?php
function calculation_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'user_register':
$form['#validate'][1] = 'do_database_updation';
break;
}
return $form;
}

function do_database_updation($form, &$form_state){
/* perform database updation here... */
}

```

It works fine, but the problem is when the validation fails, the database updation cannot be retrieved back. I want to call the custom function after validate the input values. How it to do ?

# Answer
You can add your function in the `[#submit]` key. For example :

```
if ( empty($form['#submit']) ) {
  $form['#submit'] = array();
}
array_push($form['#submit'], 'do_database_updation');

```

The submit handler is called after the validation.
> 3 votes

---
Tags: 6, hooks, forms
---


# Question
Title: How to get real thumbnails (not onthefly scaled down large originals) in grid from media gallery depending on certain tag using views
I would like to use Views to display, in a block, real thumbnails of images uploaded using tools based on the Drupal 7 Media Gallery module in a grid of images with a certain tag.

By real thumbnails, I mean either cropped small images of the original or the entire original reduced in size. This kind of thumbnail is efficient at loading. I do not want thumbnails which are simply the browser's on-the-fly scaling down of the original.

# Answer
I worked it out: here's my solution: http://groups.drupal.org/node/183909 credit to Drupal Gardeners Moderator Staff @mstef, @Jeannie.Finks, @Sara.Roy @mongolito404 (on groups.drupal.org/media ) for providing the basis and hints.
> 1 votes

---
Tags: 7, views, media
---


title: Should a module file look like this?

text:
# Question
Title: Should a module file look like this?
I've been having problems with one of my Drupal sites and have narrowed the problem down to the Views module. In my Apache error log, I see this:

> \[Tue Oct 18 09:57:08 2011\] \[warn\] mod\_fcgid: stderr: PHP Parse error: syntax error, unexpected T\_ENCAPSED\_AND\_WHITESPACE, expecting '\]' in /home/lakedistrict-holidayideas/public\_html/sites/all/modules/contrib/views/handlers/views\_handler\_filter\_in\_operator.inc on line 206

Looking at the views\_handler\_filter\_in\_operator.inc file, I see this on line 206:

```
 $form['value']['#dep

```

Does that appear to be a normal line of code? To my untrained eyes, it looks incomplete.

I've reinstalled the module, but the problem remains.

If it appears to be that there's a problem with the module, I'll make a post on the Views issue queue on Drupal.org.

# Answer
> 4 votes
Since you're using Views module version 2.12, I looked up that file in the repository viewer: http://drupalcode.org/project/views.git/blob/42fe4029ca7d7410f15933032a17e979bb0957c4:/handlers/views\_handler\_filter\_in\_operator.inc

Looks like line 206 should be:

```
$form['value']['#dependency'] = array($source => $this->operator_values(1));

```

I'd try re-downloading the entire Views module. Maybe your copy got corrupted along the way.

---
Tags: views, 6
---


# Question
Title: Permission creating taxonomy terms per vocabulary
Is there a module that will allow me to allow a specific role to create/edit/delete terms in a specific vocabulary without allowing them to edit the taxonomy itself or terms on another vocabulary?

The only taxonomy permission I see is "administer taxonomy", which is decidedly more than I want to give those users. My google-fu turned up numerous modules that will permission the nodes by terms, but none that allow permissioning of the vocabulary itself.

thanks!

# Answer
> 2 votes
For Drupal 6, this looks like the module for you: Vocabulary Permissions Per Role

---
Tags: 6, taxonomy-terms, users
---


# Question
Title: How to programmatically set custom display settings for an RSS feed?
I am using Drupal 7 and Views 3.0-RC1.

I have defined an RSS feed for a view, but the full node content keeps showing up instead of the teaser. I believe it is because of these two issues:

The steps that appear to work are to:

* Enable a custom display for RSS,
* Configure the RSS custom display truncate the teaser and hide extra fields,
* Enable the view to display full text for RSS.

I need to make this work programmatically as part of a features module.

The first step is easy. I do it with the following code in my .module file:

```
    function mymodule_entity_info_alter(&$entity_info) {
      $entity_info['customtype']['view modes']['rss'] = array (
        'label' => t('RSS Feed'),
        'custom settings' => TRUE,
      );

```

The last step is easy, as I can export the view.

The middle step has me stumped. I can't figure out how to set the display properties on the RSS display. I suspect it has something to do with field settings, but I can't seem to pull the pieces together. Any suggestions?

# Answer
@JeremyFrench pointed out that the Features Module correctly exports the field settings for the view-mode, which fulfilled the middle step. No extra API calls is necessary.

My problem was with step 1. Though field settings are defined per-content-type and per-view-mode, the actual definition of view modes is independent of content-types. All content types share the same set of view modes, though each can implement their own field settings for that view mode.

This means that in my call to `hook_entity_info_alter()`, I should not have referenced customtype, I should just reference 'node'. That simple change enables everything to work.
> 1 votes

---
Tags: views, feeds, entities
---