# Question
Title: What's wrong with my taxonomy links or my taxonomy view and contextual filter?
I have a D7 `view` displaying all items tagged "`food`" at

```
mysite.com/industry/term/food

```

But my taxonomy terms for "`industries`" link to e.g. `mysite.com/industry/food` (i.e. `without /term/`)

I thought I could update the view to make the page path: `/industry/%` instead of: `industry/term/%` but that breaks the view

so I thought I might be able to update my Taxonomy url aliasing pattern to be:

```
[term:vocabulary]/term/[term:name]

```

instead of `[term:vocabulary]/[term:name]` but that doesn't work either :( or at least, it doesn't update all pre-written aliases...

I read this: http://www.webbykat.com/2012/04/overriding-default-taxonomy-page-view-drupal-7 which pointed to a solution from 2009 here https://www.drupal.org/node/394062#comment-1953504 but if I use Name or ID (rather than "name converted to ID") in my contextual filter it breaks the view

What am i doing wrong - I'm sure it's something simple and I'm just being blind!?

# Answer
> 0 votes
You mentioned that changing the alias doesn't update all pre-written aliases. Could you pick one term, edit it, and hit "Automatic alias" under URL aliases so that it updates, then post whether that resolved the issue for that individual term?

If so, all you need is to bulk update aliases for that vocabulary, which can be done with a VBO - I'll detail how if that's the issue.

# Answer
> 0 votes
This method of overriding the taxonomy listing page with a view allows you to design a view which replaces the taxonomy listing page for all taxonomies.

It is important to note that this method only allows you to design one view which overrides all of the taxonomy term listings pages for items in any taxonomy.

As you have discovered, you can do this by creating or enabling a view which uses the special system path with exactly this text: 'taxonomy/term/%'. The views module provides an example, which by default which is disabled.

To understand what is happening, look at the addresses for each item when you edit the term. You will see these when you click 'edit' on any taxonomy term. eg. 'industry/food' the system edits this as 'taxonomy/term/15'.

You can edit the path settings for each term item individually, but it is useful to assign the pattern using Path auto from 'Configuration' -\> 'URL aliases' under the Patterns' tab. You mention trying '\[term:vocabulary\]/\[term:name\]', but that this didn't change the path for existing items.

Then next step would be to either edit each old term item separately to assign a path for each one. Or you could use the 'delete aliases' tab in URL aliases admin to delete all existing aliases for taxonomy terms, and then 'bulk update' for taxonomy terms to apply the new pattern.

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


# Question
Title: Adding Drupal field "subtitle" to page template
I have created a Content Type called "Happy Days". I have created a field in that called "subtitle".

In my template "page--happy-days.tpl.php", I want the field "subtitle" to show wrapped in an tag. I attempted:

```
<h2><?php print render($content['field_subtitle']); ?></h2>

```

but no luck. Any help would be appreciated.

# Answer
I assume you cleared the cache. Your issue is page--content-type.tpl.php override not working. Try to suggest theme hook in `THEME_preprocess_node`.

Furthermore you need to theme nodes of `Happy Day` content type, so you must use `node--CONTENT_TYPE.tpl.php`. For more information visit Theming nodes by content type page.
> 1 votes

# Answer
I think your problem is that you are using **render()** function. This function provides output with already assigned style. So that's why you can't see your changes.
> 1 votes

# Answer
You can use Fences module to change wrapping tags for fields

> Fences is a an easy-to-use tool to specify an HTML element for each field. This element choice will propagate everywhere the field is used, such as teasers, RSS feeds and Views. You don't have to keep re-configuring the same HTML element over and over again every time you display the field.
> 0 votes

# Answer
you can check specific path of field using devel using dsm(\*********\['field\_subtitle'\]); or check this link https://www.drupal.org/node/316688
> 0 votes

---
Tags: entities
---


title: Abandoned webform log

text:
# Question
Title: Abandoned webform log
I'm building a huge form with Webform module and need advice for a way to save not fully submitted forms even without **Showing** "`Save draft`" **button** options is enabled and button is visible (which is another PITA).

# Answer
You'll need to write a custom module that calls an AJAX function after each field of the Webform has been changed that fires the same function that the Save draft button does.

Shouldn't be too complicated, there is a starting point at Use AJAX to auto save a draft which should hopefully push you in the right direction, plus Webform Ajax might also help
> 0 votes

---
Tags: rules, webforms, cron
---


# Question
Title: How to calculate difference between two dates using Global PHP field?
I have a *global PHP* field provided by views php module. I tried two functions to calculate the date difference, date\_diff() and $fieldDate-\>difference() but it always gives me an ajax error. I think it causes by date format of the date field but I don't know how to fix it. What is right here?

```
$today=date("m/d/Y");
$load = $data->field_field_date_loading[0]['raw']['value'];
$diff=date_diff($load,$today);
echo $diff->format("%R%a days");

```

or

```
$today=date("m/d/Y");
$load = $data->field_field_date_loading[0]['raw']['value'];
$diff = $load->difference($today, 'days');
echo $diff;

```

# Answer
The function date() is a formatting function, if you want to use date\_diff() your code needs to be something like:

```
$today = new DateTime();
$load = new DateTime($data->field_field_date_loading[0]['raw']['value']);
$diff = date_diff($load, $today);

```
> 4 votes

---
Tags: views
---


# Question
Title: A button to delete multi images on one click from imagefield
In a content type I have an image field. For the upload I use **Multiupload Imagefield Widget**. So now it is easy to upload 10 images into one field of the content type.

If I want to remove this 10 images, I have to click remove button 10 times. Is there a module which provides a single remove button to remove all images in this field on one click?

# Answer
> 0 votes
Refer to the question about "Delete multiple images at once from one node in Drupal 7", which appears to be similar to yours.

You may also want to look at the article about Drupal 7 Unlimited Fields Remove Button, from where you can also download the Unlimited Fields Remove module.

# Answer
> 0 votes
```
<?php
/**
 * Implements hook_field_widget_form_alter().
 */
function MYMODULE_field_widget_form_alter(&$element, &$form_state, $context) {
  $found = FALSE;

  if (isset($element['#field_name'])) {
    $details = $element;
    $found = TRUE;
  }
  else {
    foreach ($element as $key => $value) {
      if (isset($value['#field_name'])) {
        $found = TRUE;
        $details = $value;
        break;
      }
    }
  }

  if ($found && variable_get('MYMODULE_' . $details['#field_name'], 0) == 1) {
    $remove_button = array(
      '#type' => 'button',
      '#value' => t('Remove All'),
      '#ajax' => array(
        'event' => 'click',
        'callback' => 'MYMODULE_fields_callback',
        'wrapper' => 'checkboxes-div',
        'method' => 'replace',
       ),
    );
    $element['remove_button'] = $remove_button;
  }
}

function MYMODULE_fields_callback($form, &$form_state) {
  $new_var = $form_state['build_info']['args'][0];
  $nid = $new_var->nid;
  if(is_numeric($nid)){

    // get all fid's attached to this node
    $get_fids = db_select('file_usage', 'fu')
    ->fields('fu')
    ->condition('fu.id', $nid, '=')
    ->execute()
    ->fetchAllKeyed(0,1);

    foreach ($get_fids as $key => $value) {
      $fids[] = $key;
    }
  }

  // delete all files
  foreach ($fids as $key => $val) {
    $file = file_load($val);
    // file_usage_delete($file, 'MYMODULE');
    file_delete($file, $force = TRUE);
  }
}

```

check this .it is taken from others posted query hopefully its help for you

---
Tags: media, entities
---


# Question
Title: How to display product attribute as filter in product listing page?
I am creating an e-commerce website using ubercart and Drupal 7. I have created product attribute size and color for the product from the "Administration » Store » Products" and assigned to product.

I have created a views page to display product listing .

Now, the problem is that I want to display product attribute as filter in the above product listing page. I have searched on Google but did not find any solution for that.

# Answer
bit late for the answer perhaps, but perhaps someone else finds it usefull.

Ubercart uses 'Attributes' and 'Options'. Filters uses 'Taxonomies' and 'Terms'. Menu modules like taxonomy filter, hierarchical select use the terms. There is no connection of these two as far as i know.

To use these filters, we have terms synchronized with options. So for every option there is a term as well. On the product edit screen, we have enabled the taxonomies corresponding to the product attributes. So on the product edit screen you can manually add terms for taxonomies. We set these tags automatically when we import the options data through a csv or cash-register connection. (And set options based on received term data as well.)

When you have this solved there is issue 2. Options without stock should (often) not be shown in menu options.

So when f.i. Shirts-\>Red-Size XL has Size XL out of stock, then term XL should no longer be visible in the filters (when this is the only product). We made small adjustment to 'order-invoice' trigger where stock is reduced, to also check and remove terms where needed.

For handling this automatically and with a nice user interface I created a custom module.
> 0 votes

---
Tags: 7, views, ubercart
---


# Question
Title: How to detect device in template file in drupal 7
I want to get the device whether is it Mobile,Tablet,Iphone or desktop based on the screen width. I know about breakpoint and picture module. But I need to change some HTML based on that condition. How can I get the condition in tpl file.

# Answer
> 0 votes
I would use Context & Context Mobile Detect

---
Tags: theming
---


# Question
Title: Time localisation - "@count hour" (ago) instead of "1 hour"?
**Short story:**

When Drupal 6 display time in format "x ago" (for example "3 hours ago"), there are two strings - for singular and plural. Singular string for hours is "1 hour", plural string is "@count hours". My question is - is this a bug? Shouldn't be there "@count hour"?

**Long story:**

Today, something strange happened to me. I went back to my site where I posted a comment yesterday around this time. However, in recent comments block, there was my comment marked as "1 hour 15 minutes ago" (in my language, not English - that's important!).

After I checked that time zone, server time and comment time are correct, I started debugging the Drupal. Finally, I found the culprit; it's the method format\_interval(). At start of the method, there are strings definitions. For hour it's `'1 hour|@count hours'` \- `1 hour` for singular, `@count hours` for plural.

I found out that my comment was posted 21 hours ago and that `locale_get_plural()` function returned 0 - which is interpreted as singular.

And that's the problem - in my language we read "21 hour", NOT "21 hour**S**"! However, the count variable is not used, so for each numeric value read as singular (1, 21, 31, 41, ..., 91, 101, 121, 131, ...) (note: yeah, 11 is not singular in my language), the displayed value will be always 1!

I'm writing about hours, but this is same for all other values - years, weeks, minutes and seconds. Experimentally, I changed translation of "1 hour" to "@count hour" (in my language, not English) and the displayed time become correct. However, this is not clean solution, so my question is: is this a bug? If not, how should I solve this correctly?

**Notes**

* I use Drupal 6
* Happening on my machine (Xubuntu 14.04) and server (some Gentoo)
* My language is Czech

# Answer
> 0 votes
The change you have made should work until you download and install an update to the drupal core language file.

The Drupal Localize site would allow you to download an check the latest versions of the core language files to see if the bug also exists latest versions of 6, 7 and 8.

https://localize.drupal.org/translate/languages/cs

Perhaps you could sign up and posting a message into the Czech language forum on the localize site. You can also find out more about contributing on the localize website.

https://localize.drupal.org

---
Tags: i18n-l10n
---


# Question
Title: views showing only 1 node with specifiec field value
Displaying problem with views. I am trying to make a ranking for my track club.

Every result by someone is a node. I can make a global ranking with views showing all results sorted by running time (lowest time is first item).

Ranking total view looks like.

```
name    - time  - place
runner1 - 12.00 - city1
runner2 - 12.01 - city1
runner3 - 12.10 - city1
runner1 - 12.15 - city2
runner1 - 12.20 - city1
runner3 - 12.25 - city5
runner4-  12.40 - city1

```

I need a ranking system with only the best performances. Curently a have used VIEWS AGGREGATOR PLUS (view first item on name) to help me filter some nodes. So my bad 'best results view' looks like:

```
name    - time  - place
runner1 - 12.00 - city1
runner2 - 12.01 - city1
runner3 - 12.10 - city1
runner1 - 12.15 - city2
runner3 - 12.25 - city5
runner4-  12.40 - city1

```

I can't seem to only select the node with the best perfomance if there is another node from the same runners result in another city.

My ranking should look like:

```
 name    - time  - place
 runner1 - 12.00 - city1
 runner2 - 12.01 - city1
 runner3 - 12.10 - city1
 runner4-  12.40 - city1

```

So my views should : Select node where 'time' is lowest per 'name'.

**How can I do this?**

# Answer
Views is a simple query builder. It is good at building 1 query, or many simple queries. There are times when relying solely on Views, and the assumption that your logic and be easily tailored to Views may fail.

This is such an example where it would benefit you to do some of this work outside of Views itself and store and compute metdata on to more easily generate reports.

For example you could install Nodequeue, Views Bulk Operations and Rules to perform the following tasks:

1. create a nodequeue for `city_fastest_times_results`. Create 1 nodequeue per city.
2. Write a Rule that upon saving of a track time examines if it is the fastest time yet recorded for that city. If so, insert it into the appropriate nodequeue.
3. Using VBO to reuse the rule you defined in  to run this processing on any previously entered data on the website.

*note:* a SmartQueue may be able to allow you to encode this logic as well, as opposed to Rules.

Instead of Nodequeue you could also use the Relation module to relate cities, runners and times.

So, the nodequeues can store the fastest times per city and self-update based on Rule logic, or occassionaly by an admin using a VBO form. To show a report you would then just have `SELECT * FROM {nodequeue_N} ORDER BY time DESC`, which is trivial using Views.
> 1 votes

# Answer
Got it working to my liking(for now)

module:Views Aggregator Plus views display as:Table with aggregation options group and compress (name)

Now display only 1 name and best result in views table
> 0 votes

---
Tags: views
---


# Question
Title: How to detect a mobile browser using PHP in content?
Using Drupal 7.14 with the PHP filter on I have the following in a Basic Page content type:

```
<?php if ($is_mobile == TRUE):?>
<div class="fb-like-box" data-href="http://www.facebook.com/a page" data-width="710" data-height="600" data-show-faces="false" data-border-color="#73AA4B" data-stream="true" data-header="false"></div>
<?php else: ?>
<div class="fb-like-box" data-href="http://www.facebook.com/a page" data-width="900" data-height="600" data-show-faces="false" data-border-color="#73AA4B" data-stream="true" data-header="false"></div>
<?php endif; ?>

```

I get the error message:

*Notice: Undefined variable: is\_mobile in eval() (line 1 of D:\websites\modules\php\php.module(80) : eval()'d code).*

I sort of understand - I'm trying to grab a variable from the Drupal system but is there any way to do this? Maybe using Tokens?

# Answer
> 5 votes
Mobile detection isn't built into Drupal or most popular themes (I think Adaptive Theme does, though). You need to install a contrib module to do this. Three options are Browscap, Mobile Tools, and Mobile Detect. Where you go from here depends on which module you are using.

# Answer
> 3 votes
I wrote a very simple module that detects mobile user agents and sets a corresponding global variable you then can access in your template.

```
function MYMODULE_init() {
  $GLOBALS['is_mobile'] = _MYMODULE();
}

function _MYMODULE() {
  // if no user agent is set
  if (!isset($_SERVER['HTTP_USER_AGENT'])) {
    $is_mobile = FALSE;
  } else {
    /**
     *  check http://detectmobilebrowsers.com for updates
     */
    $is_mobile = (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i',$_SERVER['HTTP_USER_AGENT'])||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($_SERVER['HTTP_USER_AGENT'],0,4))) ? TRUE : FALSE;
  }
  return $is_mobile;
}

```

Inside your template you'ld then use it like so:

```
<?php if ($GLOBALS['is_mobile'] == TRUE): ?>
<div class="fb-like-box" data-href="http://www.facebook.com/a page" data-width="710" data-height="600" data-show-faces="false" data-border-color="#73AA4B" data-stream="true" data-header="false"></div>
<?php else: ?>
<div class="fb-like-box" data-href="http://www.facebook.com/a page" data-width="900" data-height="600" data-show-faces="false" data-border-color="#73AA4B" data-stream="true" data-header="false"></div>
<?php endif; ?>

```

# Answer
> 2 votes
You could try using Theme Key module to check for the Mobile device.
It provides flexibility for changing the theme not only based on the type of device but also can theme different parts of site based on different conditions.
Here, is a link to a simple tutorial using themekey.

If you've just started to design the site, I'd recommend you use Omega theme to develop, as it has an option to change layout and make it responsive (according to screen size/resolution). It also supports HTML5.
It can be well combined with Omega Tools module, to create an Omega sub-theme from UI.

# Answer
> 2 votes
1. In template.php put this code

```
function mytheme_preprocess_node(&$variables){

  $useragent=$_SERVER['HTTP_USER_AGENT'];

  if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) {
    $variables['is_node'] = "mobile";
  }
}

```
2. In node.tpl.php put this code

```
if($is_node == "mobile"){
  //Add your html
}

```
3. After that clear the cache.

Source : Detect Mobile Browser

---
Tags: theming
---


title: rank position based on field value

text:
# Question
Title: rank position based on field value
I would like to display the rank position of a node based on a field value.

Let's say that in field\_A there is the node's quantity of "points" and in field\_B the node's category.

Then, I would like to display that the current node is 5th out of 15 in its category for example.

thanks for your help.

# Answer
seems you need to create a "taxonomy view" (category) then create a listing and sort them by the "points" field value.
> 1 votes

---
Tags: views
---


# Question
Title: How do I display dynamic field values in a template?
I am making a module, each time user make content type and add fields to it, all its field values get rendered into static template dynamically.

For this, I am using `noad_load_multiple()` to get all node values of selected content type and using `hook_theme()`, displaying it in a static template page.

```
$compfields = [node_load_multiple][2](array(), array('type' => $node_type));

return theme('component_fields',array('compfields' => $compfields));

```

In the template file, I am using the following code, looping over `$compfields`.

```
print '<p>' . $value->body['und']['0']['value'] . '</p>';

```

I know my content type has a *body* field which is rendered with `print '<p>' . $value->body['und']['0']['value'] . '</p>';`.

How can I render the additional fields added to a content type without knowing their field type?

# Answer
> 0 votes
You could run a 'foreach' on the items in the list. Added fields will be named 'field\_ ...' which is easy to check. The fields come with their own render functions, also available in the field object code. Although i think drupal\_render() will handle it correctly anyway.

A first step could be to use dsm($compfields) to identify the field structure and then use it. (dsm is part of the devel module and displays structures in nicely readable format)

---
Tags: nodes
---


title: Content hidden when author is anonymous

text:
# Question
Title: Content hidden when author is anonymous
I have encountered a problem in my site. When the author of the node is anonymous, his/her content doesn't appear on the front page for anonymous users. but it does when the author is the admin.

Has anyone ever met the same issue and/or has a solution?

# Answer
please check the permission in "admin/people/permissions" under the node section check **View published content** has been enabled for anonymous user
> 1 votes

# Answer
Have you checked the option **Promoted to front page** for that content type?
> 1 votes

# Answer
Are you sure the node is published? Anonymous users are often able to submit unpublished nodes but not to publish them. And Administrators usually *can* see unpublished content, but anonymous can't. (Of course all these settings can be changed per the suggestion about permissions above.)

(BTW, the word "type" in your subject is misleading as you are referring to nodes or content, not the entire content type.)
> 1 votes

---
Tags: nodes, users
---


# Question
Title: Syntax for getting plain field value in computed field
I have a couple of simple computed fields that combine other fields (such as first name and last name) but I'm not getting the right values from the fields. I sometimes get only the first letter of a text field (maybe just on the Title field), and when I call a longtext field I'm getting all the HTML markup when I really only want the plain text version of the field.

Here's an example where I'm trying to combine a pile of fields for purposes of searching them from one box:

```
$omnisearch = $entity->title[LANGUAGE_NONE][0]['value']."
".$entity->body[LANGUAGE_NONE][0]['value']."
".$entity->field_prerequisites[LANGUAGE_NONE][0]['value']."
".$entity->field_keywords[LANGUAGE_NONE][0]['value']."
".$entity->field_teachers[LANGUAGE_NONE][0]['value']."
".$entity->field_organizing_center[LANGUAGE_NONE][0]['value']."
".$entity->field_location[LANGUAGE_NONE][0]['value'];
$entity_field[0]['value'] = $omnisearch;

```

So is there a better parameter than 'value' to pull the plain/sanitized text from the field? And why am I only getting the first character of the title? I only theoretically grok arrays, so the answer may be obvious to others. Thanks for your help!

# Answer
> 1 votes
**I'd suggest you to start by understanding the structure of your entity.** You could do something like `<pre><?php print_r($entity); ?></pre>` to print on screen your entity object and understand how to reference each one of its fields.

You'll discover that you could get your title just by using `$entity->title` (in your example you are getting the first letter because you are treating it as an array). You could also find that not all your fields might be have by the 'value' key.

Once you do that, you could get the fields values using `field_get_items()`. A basic example:

```
$items = field_get_items('node', $entity, 'field_keywords', $entity->language);
$item = array_shift($items);
$keywords = $item['value'];

```

And maybe you could take it one step further and wrap that in a reusable function:

```
/**
 * Get a node field's first value.
 */
function YOUR_MODULE_node_get_field_single_value($node, $field_name, $key) {
  $items = field_get_items('node', $node, $field_name, $node->language);

  if (!empty($items)) {
    $item = array_shift($items);
    return isset($item[$key]) ? $item[$key] : NULL;
  }
  else {
    return NULL;
  }
}

```

And call it like this (assuming that this field has a single value in it):

```
$keywords = YOUR_MODULE_node_get_field_single_value($entity, 'field_keywords', 'value');

```

Please note that the above function is just an example, your field might have multiple values in it. In that case, you'll need to iterate the array returned by field\_get\_items.

---
Tags: 7, entities
---


# Question
Title: Conditional statement in custom template file using Display Suite
I've been searching and scratching my head for a while on this one. I'm working on a blog page where the user can tag posts, but it is not required. I only want to output the label 'Category' if tags actually exist, so I need a conditional statement in my node template but I can't figure out the correct logic for doing so. This is what I have so far...

```
<?= if (isset($node->$content['tags'][0]['value'])): ?>
    <p class="label"><?= t("Category"); ?></p>
    <p class="category"><?= render($content['tags']); ?></p>
<?= endif; ?>

```

This code gives the following PHP error referring to the first line of the block of code

```
PHP Parse error:  syntax error, unexpected T_IF

```

I'm a Drupal novice so I'm expecting it to be something simple that I am missing or potentially just completely the wrong code.

# Answer
> 1 votes
First, you have a syntax error. Your server might not have been configured to allow short tags.

Try using `<?php echo` instead of `<?=`

Second, you could either use the Field formatter conditions module to add display conditions to your fields or create a custom code field in Display Suite.

**EDIT: How to add a Display Suite custom code field in your own module:**

1- Create a new module and add this code in it (remember to change MY\_MODULE with the desired name):

```
/**
 * Implements hook_ds_fields_info().
 *
 * We add the code fields to Display Suite here.
 * Then we specify a callback function that will handle the display logic.
 */
function MY_MODULE_ds_fields_info($entity_type) {
  $fields = array();

  // Add a new custom code field. It should be available in Display Suite.
  $fields['node']['tags_custom'] = array(
    'title' => t('Tags (custom)'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => 'MY_MODULE_ds_field_tags_custom',
  );

  if (isset($fields[$entity_type])) {
    return array($entity_type => $fields[$entity_type]);
  }
}

/**
 * Callback to show the tags field only if it has a value.
 */
function MY_MODULE_ds_field_tags_custom($field) {
  $node = $field['entity'];

  // Get the tags field value.
  $tags = isset($node->content['tags'][0]['value']) ? $node->content['tags'][0]['value'] : NULL;

  // Return a string or nothing, depending on the tags field value.
  if (!empty($tags)) {
    return t('Category: ') . $node->content['tags'][0]['value'];
  }
  else {
    return NULL;
  }
}

```

2- Now, if you go to *admin/structure/ds* and click on the *Manage display* link, you will see your new field *Tags (custom)*. Set its label to *hidden* and publish it in the desired area.

---
Tags: entities, display-suite
---


# Question
Title: Content Type vs. Taxonomy | Example TV Series
As this is my first post here I don't know if I do everything right. Please forgive me.

So, my plan is to build a website with many categories and these than contain posts. To explain the stuff in the easiest way I decided to use Series and Episodes.

* Serie A:
    + Episode 1
    + Episode 2
    + Episode 3
* Serie B:
    + Episode 1

For my use I also want to be able to decide what exactly an episode is. For example is it an normal one or just a 20 minute special and should be displayed like this:

* Serie A:
    + Author:
    + Year:
    + (more stuff here)
    + Episodes: (Headline)
        - E1 (Link to this Episode)
        - E2 (Link to this Episode)
    + Special Episodes: (Headline)
        - E1 (Link again)
        - E2 (Link again)

The problem here is that I don't know if I should create this with Content Types or Taxonomy.

A) So one Content Type for Serie and another one for Episodes. Both with the needed fields. But the problem is here I don't know how to join/connect them properly.

B) Creating a Taxonomy called "Series" and adding all Series into it. Than a Content Type "Episodes" with setting a Tag to connect the Episode to the right Series. The problem I could get here is for example when adding something like genre. A Taxonomy would get a list of Genres like Action, Comedy and so on.

Another point would be accessibility. It should be possible to search for Series include/exclude genres and also searching for fields like year, episode-count of a series.

At last is it possible to create Custom Types where for example a javascript is loaded in the background that parses text from a input text area?

I hope you understand my goal with this example and can tell me the proper way. Thanks for everything.

# Answer
> 1 votes
I'm assuming that the series and episode are going to have fields and you need to link series and episodes together. Both A and B are technically correct approaches to your problem, but I'd lean more towards approach A(creating a content type for both series and episodes). I'll explain why in a moment.

The series and episode can be linked using the entity reference module as mentioned in an earlier answer. To add more detailx, you would add a multivalue entity reference field to series content type and add all your episodes there.

If you want to store more metadata for the series-episodes link(in Drupalspeak, make that relationship fieldable), you can create a series-episode relation and add fields to that using the relation module.

You can as well make episodes as a taxonomy term and add an entity reference field pointing to episodes(approach B), but series are a separate entity in itself and wouldn't exactly map to a taxonomy term in the grand scheme of things. They are better off as nodes(approach A).

> At last is it possible to create Custom Types where for example a javascript is loaded in the background that parses text from a input text area?

Not sure I understand this right. You want to parse some semi-structured text and create series and episode nodes out of that?

# Answer
> 1 votes
I would do it the A) way and use Entity reference module to "link" episodes to series. That way you can use watever fields you want in your content types (including taxonomy for genre for example).

> The Entity Reference Module is used to relate entities (nodes, terms, users, etc...) to one another.

After that, you can display content types with Views showing Series with list of episodes.

# Answer
> 0 votes
Have a look at field\_collection module. By default a collection (contenttype episode) is part of an entity (series) and can be managed as one bundle.

# Answer
> 0 votes
There many ways to implement this as other guys gave you a few solutions. Selecting the right choice deponds on how good you are at Drupal, which fields do you want to filter on, ... .

Searching and filtring on field collection is an almost complex process. The group views by fueld collection is an example of it. But it has the advantage of easily inserting the content. By this moduleva package of fields come together as a one unique field. It is nice.

Using entity module is very good, by this module you will need to create two content types, and link them using an entity field. Searching and filtering is easier than field collection solution.

You can also use Entity View Attachement module which assigns a view to a node. In this case nodes are Series and you assign a View of episoded to them

Anyway I recommend you to use entity module because of it's flexibility in filtering, searching, new requirements in the future and ....

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


title: userpoints reset for drupal 7

text:
# Question
Title: userpoints reset for drupal 7
I need to reset userpoints for all users to zero now that the site is live. how can I do that? there used to be a userpoints\_reset module for drupal 6, but it's not yet ported to drupal 7

thanks.

# Answer
> 0 votes
There is D7 patch if you're savvy enough with that. I wouldn't bother with it unless you anticipate reseting frequently. An easier fix is to just truncate all the tables that store the data:

```
db_query('TRUNCATE {userpoints}');
db_query('TRUNCATE {userpoints_txn}');
db_query('TRUNCATE {userpoints_total}');

```

---
Tags: 7, userpoints
---


title: Using OR with EntityFieldQuery

text:
# Question
Title: Using OR with EntityFieldQuery
I have never had the need to do this before today, but it doesn't seem like you can make OR queries with `EntityFieldQuery`, since `db_or` is used for select queries.

An example would get to all entities that has a date field where the value is null or after today.

Am I missing something or some trick or is this simply not supported?

# Answer
> 22 votes
I have seen a solution of this problem. The idea is to use `addTag()` in query and implement `hook_query_TAG_alter()`, where you have good old `SelectQuery` object.

# Answer
> 12 votes
You can sublass `EntityFieldQuery` and override some methods.

The conditions that are added to an object of class `EntityFieldQuery` (e.g. a property condition) are added to an array.

```
  public function propertyCondition($column, $value, $operator = NULL) {
    // The '!=' operator is deprecated in favour of the '<>' operator since the
    // latter is ANSI SQL compatible.
    if ($operator == '!=') {
      $operator = '<>';
    }
    $this->propertyConditions[] = array(
      'column' => $column,
      'value' => $value,
      'operator' => $operator,
    );
    return $this;
  }

```

When the query is built, that array is then used in a loop similar to the following one (the code is present in EntityFieldQuery::propertyQuery()):

```
foreach ($this->propertyConditions as $property_condition) {
  $this->addCondition($select_query, "$base_table." . $property_condition['column'], $property_condition);
}

```

`$select_query` contains the value returned from a call to `db_select()`.

# Answer
> 5 votes
You can't I'm afraid, ORs are not natively supported by the `EntityFieldQuery` class.

One way round it might be to add a tag to the query with with `->addTag()`, then implement `hook_query_TAG_alter()` to change the internal structure of the query manually for queries containing that tag.

Doing this you will be able to loop through the existing conditions and make the necessary alterations to add your `OR` logic. It's not a pretty way to do it though; you can find an example here.

# Answer
> 5 votes
No need to split queries into 2 and merge or anything like that. Just need to alter the query

Consider the scenario: I had 2 entity types with machine names: tincan statements, and tincan\_agents

5 entity reference fields on the entity

4 of them are regular entity reference fields and the 5th (tincan\_object) is a multi-entity-type reference field, each reference field references a entities of type 'Agent'.

The tincan\_object reference field can reference Agents and Activities (a third entity type). An Agent has a property object\_type, which can either be Agent or Group.

I want to find any Statement that references one of several possible Agents, in any of the reference fields. We need an OR operator between the fieldConditions, but we also need to check the object\_type of the multi-entity type reference field, and make sure it is one of two possibilities.

The code below represents the simplest possible , in our solution the query had many other conditions, fields, etc... so the code needed to not count on the order of conditions, or even if all of these fields were being queried.

```
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'tincan_statement');

    $all_agents = array(4,10); //entity_ids to search for
    $query->addTag('tincan_statement_get_agents');
    $query->fieldCondition('tincan_actor', 'target_id', $all_agents, 'IN');
    //need OR between fields conditions
    $query->fieldCondition('tincan_authority', 'target_id', $all_agents, 'IN');
//need OR between fields conditions
    $query->fieldCondition('tincan_instructor', 'target_id', $all_agents, 'IN');
//need OR between fields conditions
    $query->fieldCondition('tincan_team', 'target_id', $all_agents, 'IN');
//need OR between fields conditions
//but then nested in the OR structure we need an AND for two columns of the multientity type reference field tincan_object
    $query->fieldCondition('tincan_object', 'target_id', $all_agents, 'IN');
    $query->fieldCondition('tincan_object', 'object_type', array('Agent', 'Group'), 'IN');
    $results = $query->$execute();

```

**Solution:** Notice in the above EntityFieldQuery

```
 $query->addTag('tincan_statement_get_agents');

```

This tags the query, allowing implementation of hook\_query\_TAG\_alter()

```
/**
 * Implements hook_query_TAG_alter()
 * alters the query for finding agents with or without the related_agents flag
 * used for Statement API Get processor EntityFieldQuery
 */
function tincan_lrs_query_tincan_statement_get_agents_alter(QueryAlterableInterface $query) {
  //need to or the search for all the fields (actor, object, authority, instructor, team)
  // the object_type of the object field needs to be Agent OR Group

  $conditions =& $query->conditions();
  // dsm($conditions);  //dsm() is your friend! comes with devel module
  $agent_grouping_condition = db_or();
  $object_parameters = array();
  $x = 0;
  foreach ($conditions as $key => $condition) {
    if (is_numeric($key) && isset($condition['field']) && is_scalar($condition['field'])) {
      if ( (strpos($condition['field'], 'tincan_object_object_type') !== FALSE  ||
          strpos($condition['field'], 'tincan_object_target_id') !== FALSE ) && $condition['operator'] == 'IN') {
  //u
            unset($conditions[$key]);
            $object_parameters[$x]['field'] = $condition['field'];
            $object_parameters[$x]['value'] = $condition['value'];
            $object_parameters[$x]['operator'] = $condition['operator'];
            $x += 1;
          }

       if(strpos($condition['field'], 'tincan_actor_target_id') !== FALSE ||
          strpos($condition['field'], 'tincan_instructor_target_id') !== FALSE ||
          strpos($condition['field'], 'tincan_team_target_id') !== FALSE ||
          strpos($condition['field'], 'tincan_authority_target_id') !== FALSE ) {
            unset($conditions[$key]);
            $agent_grouping_condition->condition($condition['field'], $condition['value'], $condition['operator']);

      }
    }
  }

  // create new AND condition to nest in our OR condition set for the object parameters
  $object_condition = db_and();
  foreach($object_parameters as $key => $param) {
    $object_condition->condition($param['field'], $param['value'], $param['operator']);
  }

  $agent_grouping_condition->condition($object_condition);

  $query->condition($agent_grouping_condition);

  //By default EntityFieldQuery uses inner joins, change to left
  $tables =& $query->getTables();

  foreach($tables as $key => $table) {
    if (strpos($key, 'field_data_tincan_object') !== FALSE ||
        strpos($key, 'field_data_tincan_actor') !== FALSE ||
        strpos($key, 'field_data_tincan_authority') !== FALSE ||
        strpos($key, 'field_data_tincan_instructor') !== FALSE ||
        strpos($key, 'field_data_tincan_team') !== FALSE ) {
          if(!is_null($table['join type'])) {
            $tables[$key]['join type'] = 'LEFT';
          }
    }
  }

}

```

# Answer
> 2 votes
The OP wants to query for entities with date null OR bigger than x, I wanted to query for nodes with no language defined OR the user's language. `addTag()` is the best solution for adding an actual OR statement, but would be overkill in my case. My very simple OR can be accomplished by looking up the language property in an array using:

```
$query->propertyCondition('language', array($GLOBALS['language']->language, LANGUAGE_NONE), 'IN');

```

---
Tags: entities, database
---


# Question
Title: How to order views by taxonomy term name?
for some reason the sort criteria by taxonomy term field do not work properly.

This is the view:
Here you can see the field I order by. The options of the field is the default. Only one taxonomy term per node. And this is the result:

As you can see the '2005' node is at the end and not a the start of the view's result. I have no idea why this happened. I tryed to delete the node and create a new one, delete the taxonomy term and recreate this but nothing happned.

Can someone help me to understand what is happening? I do not want to add queue module and order the view by queue order..

NEWS

SELECT ... ORDER BY field\_data\_field\_edizione\_field\_edizione\_tid ASC
The view order by tid and not by weight T\___T Now I understand what is the problem.. how can I create a new views sort criteria?

# Answer
> 2 votes
Solved! I create a relationship beetween the nome and the taxonomy term using the term weight to order the nodes ^^ Now it works!

Thank you Mołot to let me see the SQL query ^^

# Answer
> 1 votes
Sorting (numerically) by weight is not the same thing as sorting (alphabetically) by name. Weight for taxonomy terms can be made to be equivalent to an alphabetical list, but in some cases the weight is different. (Weight also controls the order of the terms as they appear in a select list widget on a term reference field.)

To sort the view by term Name you need to add a relationship from the node to the term, and then add sort criteria for term Name.

Though the solution above is how it should work in theory, I have also been having trouble getting that to work in practice. (I suspect there is a bug in the term name views handler.)

# Answer
> -1 votes
You can also do this without creating a view. Within your template.php file, you can do the following.

```
function yourthemename_preprocess_page(&$vars) {
    if($vars['node']->field_services['und']) {
    // Create an Array
    $termresult = array();
    // Iterate through the tids, load their names and add to our array
    foreach ($vars['node']->field_services['und'] as $termobject) {
      $term = taxonomy_term_load($termobject['tid']);
      array_push($termresult, $term->name);
    }
    // Sort the returned array
    sort($termresult);
    // Print them out based on our new sorting.
    foreach ($termresult as $termobject) {
      $vars['terms'] .= "<li>".$termobject."</li>";
    }
  } else {
    $vars['terms'] = "";
  }
}

```

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


# Question
Title: Displaying a product price on Ad Push content?
Hi just started using Drupal a couple of days ago. I'm using Commerce Kickstart 2. I'm having troubles displaying the product price on the Ad Push content. I just want to know if there is a way to display the product price on the Ad Push?

Thank you very much.

# Answer
You would need to add a new Product Reference field to the Ad Push content type. This allows content editors to pick a product to reference. You can then display the price through the "manage display" tab of the Ad Push form. You'll want the "Product: Price" field.
> 0 votes

---
Tags: commerce
---


# Question
Title: Display unique text and button in nodes in a view in drupal 7
I have created a view listing 'invitation' nodes. When viewing each invitation on a full page, I have created a small block to allow people to RSVP to these invitations, but I would like to give them access to the button to RSVP directly from the view list.

Basically, if the user viewing the node in the list was invited to the event, something like this would show:

'You have been invited. RSVP here \[button\]'

Or if they have already RSVP'd: 'You are attending. Change your RSVP \[button\]'.

Any suggestions on how to do that?

A few more details: \- I created a custom module to handle the invitation process and form on a full view of the nodes. Details of invitations (who, where, when) are stored in a database. \- when the user is on the invitation in full view, i have created a block to display the RSVP form, adapting it to the status of the RSVP of the user.

# Answer
> 0 votes
I found the 'Views php' module, which allows to use php code as the output of a field in Views. Basically, after installing and enabling the module, I went to the views that I wanted to modify and added a field called 'Global: PHP'.

In that field's settings, there are two areas of note:

* the 'value code': I obtained the status of the invitation by calling a function from one of my modules and saving it in a variable. example:

```
$truc=invitation_status($data->nid);

```
* the 'output code': it is used to display the result. A simple echo of the data saved as a variable works:

```
<?php
  echo $truc;
?>

```

You can of course generate php code to display a link or a button, etc... I hope this helps people.

# Answer
> 0 votes
Not quite sure if there's a module for that. Is Flags enough? In basic, it has a 0 or 1 option: respond and already attending.

And how to distinct users? I presume, users are logged in. Add a role to give certain users the privelege to see the RSVP-button/block/whatever.

# Answer
> 0 votes
Your question doesn't detail (yet) HOW you implemented the invitation part of it, i.e. to indicate which users are invited for which specific event. If I was to implement those invitations, I'd use the Entity Reference module to implement "invitations".

Next I would use the Flag module (not Flags ...) to allow invited people to "flag" such invitation node like "Yes, I would like to attend".

Once you'd have this in place, display the flag in your views, and from there those who are invited, could then just indicate via that "flag" that they want to attend.

Since the question is a bit vague about how your current view is constructed (consider adding a screenprint of the Vieuws UI to your question ...), it could well be that this needs to further refined with some extra "conditions", which you could pretty sure add to it using he Rules module.

If you edit your question to be more specific, add moore details, then I can probably also furhter refine my answer here.

---
Tags: views
---


title: Views: Relationship with filtering?

text:
# Question
Title: Views: Relationship with filtering?
I have a content type `shortcut` with the fields `field_namespace` and `field_active`. Additionally, I have a Taxonomy term vocabulary named `namespace` that is used in `field_namespace`.

Example content:

```
Title       | Namespace   | Active
------------+-------------+-------
Shortcut 1  | Namespace A | True
Shortcut 2  | Namespace A | False
Shortcut 3  | Namespace B | False

```

Now, I have a view displaying a list of these Taxonomy terms as a table. A column of this table display the number of Shortcuts tagged with the particular term. Example:

```
Namespace   | Shortcut count
------------+---------------
Namespace A | 2
Namespace B | 1

```

I built this using a Views Relationship with *Taxonomy term: Content with term*. I used this relationship to add the Field *Shortcut: Nid* with the Aggregation Type *COUNT DISTINCT*.

**What I now want:** The Shortcut count shall only consider Shortcuts whose `field_active` is True, i.e. the output shall be:

```
Namespace   | Shortcut count
------------+---------------
Namespace A | 1
Namespace B | 0

```

So the *COUNT DISTICT* aggregation shall be somehow filtered by the value in `field_active`.

Is there an UI way to do this? If not, which hook is appropriate to do it programmatically?

# Answer
> 0 votes
After having asked a friend, I can now answer the question myself.

The solution is pretty straightforward: At *FILTER CRITERIA*, I simply add `field_active`, with the operator "Is one of" checking the value "On".

I thought, *FILTER CRITERIA* may only be fields actually displayed, but this is not the case. It works for all fields being in any form used in the view.

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


# Question
Title: How to record how much time user has spent on my node?
I want to record the time a user has spent on my particular node so I could show a pop up to the user to register once the user has read 3 article. But the user must have spent at least 30 seconds on each node.

There is the Time Spent module available, but I wonder if I can merge it with another (custom) module I have created (which records the number of nodes user have visited)?

# Answer
> 3 votes
# Without using any custom modules

Drupal core doesn't have any such feature. So if you don't want to consider using a contributed module, the only options you have is to:

* Write a custom module (or further enhance the custom module you already have for it).
* Add something like a javascript to the theme(s) you're using.
* Wait for a future release of Drupal (core) that may include such feature.
* Consider using a contributed module (e.g. as further explained below).

# Using the Javascript Timer module

The Javascript Timer module (available for D6 and D7) seems to be a possible answer to your question. Here is a quote from its project page:

> ... provides a timer API that can hook HTML elements to javascript widget objects. This is useful if you want a moving timer/clock or a widget that updates every second. It comes with widgets for a count-down timer, a count-up timer, and a clock. It uses jQuery and a single event loop to handle as many timers as you need on a single page.

Its Readme.txt file contains various examples, both Inline HTML Examples and PHP Input Format Examples.

Comment #4 in issue #1195560 contains an interesting comment that may help to get you going:

> It allows for redirecting to a new URL or refreshing the existing page. On the setting page it is called "Timer complete redirect". If you use a "redirect path" of `<reload>` it will just reload the current page.

# Answer
> 2 votes
Here is a solution that I am thinking you can handle in javascript with cookies. For example lets create a cookie called "show\_pop\_up";

1. Every time a user views a page for over 30 seconds check if he has cookie called show\_pop\_up.
2. If a user doesn't have the cookie, create the cookie and add the value of 1 (A better solution would be to store the user in the database and store the user identifier in the cookie but for simplicity just showing you this way)
3. If a user already has a cookie, check what number they have in the cookie.
4. If the value is equal to 4, show the pop up and increase the cookie value by 1.
5. If the value is less than 4, increase the cookie value by 1 (don't show the pop up).

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


# Question
Title: Customize HTML for field in field collection
My field collection template is ds-1col--field-collection-item-field-video-item.tpl.php. I need to access the Image field so that I can customize the HTML. I've tried the following by neither work:

```
<?php print $fields['field_video_image'][0]['und']['value']; ?>

```

and

```
<?php print $fields['field_video_image']->content; ?>

```

I also need to wrap each field collection item in its own div. For instance, each image should be wrapped in a videoClip div but right now all field items are rendering inside videoClip. Also I need to get the delta value of each field item to add it to as part of a CSS class. How can I do this?

Current fields wrapped in custom HTML together:

```
<div class="ds-1col entity entity-field-collection-item field-collection-item-field-video-item view-mode-full clearfix">
<div class="videoClip">
    <div class="videoImg">
        <div class="featuredVideo"></div>
        <div class="field field-name-field-video-image field-type-image field-label-hidden">
            <div class="field-items">
                <div class="field-item even"><!-- image here --></div>
                <div class="field-item odd"><!-- image here --></div>
            </div>
        </div>
    </div>
</div>
<div class="field field-name-field-video-caption field-type-text field-label-hidden">
    <div class="field-items">
        <div class="field-item even"><!-- video caption --></div>
        <div class="field-item odd"><!-- video caption --> </div>
    </div>
</div>

```

# Answer
If your template is being recognized you can access the fields and field content through the `$content` array. Below is the normal field collection item template file that comes with the field\_collection module.

```
<?php

/**
 * @file
 * Default theme implementation for field collection items.
 *
 * Available variables:
 * - $content: An array of comment items. Use render($content) to print them all, or
 *   print a subset such as render($content['field_example']). Use
 *   hide($content['field_example']) to temporarily suppress the printing of a
 *   given element.
 * - $title: The (sanitized) field collection item label.
 * - $url: Direct url of the current entity if specified.
 * - $page: Flag for the full page state.
 * - $classes: String of classes that can be used to style contextually through
 *   CSS. It can be manipulated through the variable $classes_array from
 *   preprocess functions. By default the following classes are available, where
 *   the parts enclosed by {} are replaced by the appropriate values:
 *   - entity-field-collection-item
 *   - field-collection-item-{field_name}
 *
 * Other variables:
 * - $classes_array: Array of html class attribute values. It is flattened
 *   into a string within the variable $classes.
 *
 * @see template_preprocess()
 * @see template_preprocess_entity()
 * @see template_process()
 */
?>
<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
  <div class="content"<?php print $content_attributes; ?>>
    <?php
      print render($content);
    ?>
  </div>
</div>

```

Using devel you can use `dpm($content);` and you will see the below setup.

So as you see in field collection item you could use `$content['field_field_1'][0]['#markup']` if your field has extra markup (like for instance if it was set to display as a link to from entity\_reference). You could use `$content['field_field_1']['#items'][0]['safe_value']` to get the safe value of the field (sanitized). If you want to customize the markup around a certain field you can hide the field and the render it somewhere else. See the below code for an example.

```
<?php

/**
 * @file
 * Default theme implementation for field collection items.
 *
 * Available variables:
 * - $content: An array of comment items. Use render($content) to print them all, or
 *   print a subset such as render($content['field_example']). Use
 *   hide($content['field_example']) to temporarily suppress the printing of a
 *   given element.
 * - $title: The (sanitized) field collection item label.
 * - $url: Direct url of the current entity if specified.
 * - $page: Flag for the full page state.
 * - $classes: String of classes that can be used to style contextually through
 *   CSS. It can be manipulated through the variable $classes_array from
 *   preprocess functions. By default the following classes are available, where
 *   the parts enclosed by {} are replaced by the appropriate values:
 *   - entity-field-collection-item
 *   - field-collection-item-{field_name}
 *
 * Other variables:
 * - $classes_array: Array of html class attribute values. It is flattened
 *   into a string within the variable $classes.
 *
 * @see template_preprocess()
 * @see template_preprocess_entity()
 * @see template_process()
 */
?>
<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
  <div class="content"<?php print $content_attributes; ?>>
    <?php
      // Hide field collection field.
      hide($content['field_image']);
      print render($content);
    ?>
  </div>
</div>
<section class="row">
  <div class=" large-4 columns">
    <!-- Render field_image field collection field-->
    <?php print render($content['field_image']); ?>
  </div>
</section>

```

Hopefully all of this helps, if not let me know and I can adjust to what exactly you are needing or explain more :)
> 3 votes

# Answer
You need to assign field collection field in `hook_preprocess_node` as a variable then use this variable in your node template file. Some thing like this
> 1 votes

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


# Question
Title: Failure getting nodes from terms via the rest api
I have added a REST web service in Drupal and all content is tagged with taxonomy. I'm now trying to acquire all related nodes to the terms.

First I'm calling taxonomy\_vocabulary/getTree along with the *vid* and I'll get all the terms for a specific vocabulary, that works just fine. The problem comes when I've gotten all the term-id's I need to go through. When I create a request it fails to find the nodes that should be connected to the term. I'll get a 404 response on each request.

This is how I call the **selectNodes**. I'm creating a POST request and pass along with the *tid*, the endpoint is called `http://myhostname/api/taxonomy_term/selectNodes`

Have someone else experienced this? Do I need to pass more arguments with the POST call?

EDIT: After a quick look in wireshark it also returns the error string: "String value: No nodes were found with tid 15". Does this mean that there aren't any relation between the terms and the nodes by default?

# Answer
The taxonomy\_term resource is only for returning taxonomy terms. It won't return any nodes.

There are tons of options but here are two that you can do quickly:

1. Install the Views Datasource module and create a taxonomy view. Have it output as json.
2. Create a custom resource that handles this. Check out these instructions on creating a custom resource.
> 0 votes

---
Tags: taxonomy-terms, services, 8
---


title: How to remove HTML code from rss.xml

text:
# Question
Title: How to remove HTML code from rss.xml
I want to remove all the HTML code from the feed created using the Views module, since LinkedIn doesn't seem to like it that way it comes. I have seen the module clean links, but I'm running Drupal 7 and even with the patch I found I can't get it to work. Is there any file I can edit and add "strip\_tags" to get it to work?

Note, that Im the biggest newbie on Drupal, but I know my way around PHP.

# Answer
Easy way to do this in D7 is through the Display Format settings. Under the content type(s) of the nodes in your view, you want to add a custom display for RSS and then set the fields you want to alter to plain text.

* Go to Structure -\> Content Types, and select 'Manage Display' next to your content type.
* On the bottom of the list of fields, expand 'Custom Display Settings' and check the box for RSS and save
* Now, in the upper right-hand corner you should see that you have display format settings for Default, Teaser, and RSS - select RSS.
* In the format settings for each of the fields, you want to select 'Plain Text' or whatever equivalent you like.
> 1 votes

# Answer
Check the advanced section of views and look for theme information. It will tell you which template you can make to override output. You can place your strip\_tags code there.

You probably want to edit something like `views-view-rss--test--feed.tpl.php` in your theme's templates directory.
> 1 votes

# Answer
The trick is to use 'fields' option and NOT 'content' option in FORMAT. This way you have more control over how and what is displayed.

So if you want your body field to populate the description tag you will be able to format it as plain text
> 1 votes

---
Tags: 7, views, feeds
---


# Question
Title: How can I let a user select my Drupal Commerce product to either be shipped or downloaded?
I am using the Drupal Commerce module. I want to download the digital file. I am using the Commerce License and Commerce File modules.

But now I need to add an option to let the user select between **Shippable** or **Download**. If the user selects *Shippable*, the product will be shipped, while if the user selects *Download*, the user will be able to download the file.

I want to do it like in the product page:

* If the user selects **Shippable**, the user doesn't have a FILES tab in the User profile page.
* If the user selects **Download**, the user has a FILES tab in the User profile page.

How can I implement this using **Drupal Commerce**?.

Any suggestions?

# Answer
> 1 votes
# Required steps

### Step 1

Create a taxonomy, let's say it's called "*Delivery methods*", with terms "*Shipable*" and "*Download*".

### Step 2

For each product type, add a field like "*Delivery method*", which is a field "term reference" (and refer to the "*Delivery methods*" taxonomy).

Attentionn: make sure to check the option "attribute field settings" (enables this field to function as an attribute field on the add-to-cart-form).

### Step 3

Use `store / products / add product` to add individual products, with a specific SKU, and for which you pick the right values for the Delivery methods taxonomy.

# Video tutorials

For a more detailed video tutorial of the steps described above, refer to Drupal Commerce - Pruduct Attributes (16:13).

Before doing so, you may want to first view these related videos:

By only reviewing/studying these 3 videos (total time = about 37 mins), you'll have a very good foundation to get started with the fundamentals of Drupal Commerce.

# Commerce Backoffice

Managing products (and orders) can be confusing. However, the Commerce Backoffice module helps with that. For more details about that module, refer to my answer to the question about Correct way for Attributes in Commerce.

---
Tags: 7, commerce, files
---


# Question
Title: Drupal 7 Form API file field - not recognizing the imported file
```
function test_data_import_form($form, &$form_state) {
    $form = array();

    //$form['#attributes'] = array('enctype' => 'multipart/form-data');

    $form['import_data'] = array(
        '#type' => 'file',
        '#title' => t('Upload data file'),
        '#size' => 22,
        '#required' => TRUE,
    );

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

    return $form;
}

```

Please see my form code above. I am trying to import a file through this form, but the file I am trying to import is not recognized as it is throwing "**Required field error**". Please help me with this.

# Answer
I tried `#file_managed` instead of the file, and then I am able to upload the files into the application. But, this option stores the file in `managed_file` table in the database with a temporary storage. The file details are not visible in the `dsm()` (devel module).
> 1 votes

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


# Question
Title: How to show Pop-Up event in calendar in drupal
I am working on calendar(event) with drupal commons.

> My requirement is when user mouseover/click on particular date in calendar,it should show event title and event conduct date in a popup.

Here i attached my view concept

```
$view = new view();
$view->name = 'calendar';
$view->description = '';
$view->tag = 'Calendar';
$view->base_table = 'node';
$view->human_name = 'Calendar';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['link_display'] = 'page_1';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'month';
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['row_plugin'] = 'calendar_entity';
/* Field: Content: Title */
$handler->display->display_options['fields']['title_field']['id'] = 'title_field';
$handler->display->display_options['fields']['title_field']['table'] = 'field_data_title_field';
$handler->display->display_options['fields']['title_field']['field'] = 'title_field';
$handler->display->display_options['fields']['title_field']['label'] = '';
$handler->display->display_options['fields']['title_field']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title_field']['link_to_entity'] = 1;
/* Field: Content: Rendered Node */
$handler->display->display_options['fields']['rendered_entity']['id'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['table'] = 'views_entity_node';
$handler->display->display_options['fields']['rendered_entity']['field'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['label'] = '';
$handler->display->display_options['fields']['rendered_entity']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['rendered_entity']['link_to_entity'] = 1;
$handler->display->display_options['fields']['rendered_entity']['display'] = 'view';
$handler->display->display_options['fields']['rendered_entity']['view_mode'] = 'teaser';
$handler->display->display_options['fields']['rendered_entity']['bypass_access'] = 0;
/* Field: Colorbox: Colorbox trigger */
$handler->display->display_options['fields']['colorbox']['id'] = 'colorbox';
$handler->display->display_options['fields']['colorbox']['table'] = 'colorbox';
$handler->display->display_options['fields']['colorbox']['field'] = 'colorbox';
$handler->display->display_options['fields']['colorbox']['label'] = '';
$handler->display->display_options['fields']['colorbox']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['colorbox']['trigger_field'] = 'title_field';
$handler->display->display_options['fields']['colorbox']['popup'] = '[rendered_entity]';
$handler->display->display_options['fields']['colorbox']['gid'] = 1;
/* Field: Content: Date */
$handler->display->display_options['fields']['field_date']['id'] = 'field_date';
$handler->display->display_options['fields']['field_date']['table'] = 'field_data_field_date';
$handler->display->display_options['fields']['field_date']['field'] = 'field_date';
$handler->display->display_options['fields']['field_date']['label'] = '';
$handler->display->display_options['fields']['field_date']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_date']['settings'] = array(
  'format_type' => 'long',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
  'show_repeat_rule' => 'show',
);
/* Sort criterion: Content: Date -  start date (field_date) */
$handler->display->display_options['sorts']['field_date_value']['id'] = 'field_date_value';
$handler->display->display_options['sorts']['field_date_value']['table'] = 'field_data_field_date';
$handler->display->display_options['sorts']['field_date_value']['field'] = 'field_date_value';
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'event' => 'event',
);

/* Display: Month */
$handler = $view->new_display('page', 'Month', 'page_1');
$handler->display->display_options['field_language'] = 'fr';
$handler->display->display_options['field_language_add_to_query'] = 0;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'month';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['name_size'] = '1';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '0';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['row_options']['colors']['legend'] = 'type';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['default_argument_type'] = 'date';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-date/month';
$handler->display->display_options['menu']['type'] = 'default tab';
$handler->display->display_options['menu']['title'] = 'Month';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['tab_options']['type'] = 'normal';
$handler->display->display_options['tab_options']['title'] = 'Calendar';
$handler->display->display_options['tab_options']['weight'] = '0';

/* Display: Week */
$handler = $view->new_display('page', 'Week', 'page_2');
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'week';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['calendar_type'] = 'week';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['default_argument_type'] = 'date';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'week';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-date/week';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Week';
$handler->display->display_options['menu']['weight'] = '2';
$handler->display->display_options['menu']['context'] = 0;

/* Display: Day */
$handler = $view->new_display('page', 'Day', 'page_3');
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'day';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['calendar_type'] = 'day';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['default_argument_type'] = 'date';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'day';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-date/day';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Day';
$handler->display->display_options['menu']['weight'] = '3';
$handler->display->display_options['menu']['context'] = 0;

/* Display: Year */
$handler = $view->new_display('page', 'Year', 'page');
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'year';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['calendar_type'] = 'year';
$handler->display->display_options['style_options']['name_size'] = '1';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = FALSE;
/* Field: Content: Date */
$handler->display->display_options['fields']['field_date']['id'] = 'field_date';
$handler->display->display_options['fields']['field_date']['table'] = 'field_data_field_date';
$handler->display->display_options['fields']['field_date']['field'] = 'field_date';
$handler->display->display_options['fields']['field_date']['label'] = '';
$handler->display->display_options['fields']['field_date']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_date']['hide_alter_empty'] = FALSE;
$handler->display->display_options['fields']['field_date']['settings'] = array(
  'format_type' => 'short',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
  'show_repeat_rule' => '',
);
$handler->display->display_options['fields']['field_date']['group_rows'] = FALSE;
$handler->display->display_options['fields']['field_date']['delta_offset'] = '0';
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['default_argument_type'] = 'date';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'year';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-date/year';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Year';
$handler->display->display_options['menu']['weight'] = '4';
$handler->display->display_options['menu']['context'] = 0;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->display->display_options['defaults']['use_ajax'] = FALSE;
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'mini';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['name_size'] = '1';
$handler->display->display_options['style_options']['mini'] = '1';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['default_argument_type'] = 'date';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);

/* Display: Upcoming */
$handler = $view->new_display('block', 'Upcoming', 'block_2');
$handler->display->display_options['display_description'] = 'Upcoming events block';
$handler->display->display_options['defaults']['use_more'] = FALSE;
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Date: Date (node) */
$handler->display->display_options['filters']['date_filter']['id'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['table'] = 'node';
$handler->display->display_options['filters']['date_filter']['field'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['operator'] = '>=';
$handler->display->display_options['filters']['date_filter']['default_date'] = 'now';
$handler->display->display_options['filters']['date_filter']['add_delta'] = 'yes';
$handler->display->display_options['filters']['date_filter']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);
$translatables['calendar'] = array(
  t('Master'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Month'),
  t('All'),
  t('Week'),
  t('Day'),
  t('Year'),
  t('Block'),
  t('Upcoming'),
  t('Upcoming events block'),
);

```

Kindly give me some idea for this colorbox concept.I used colorbox module in my drupal but i cant achieve it..

How to achieve it. I tried calendar pop-up but no luck. Is there any plugins for event calender popup or how to show popup in event calendar or Kindly guide me for creating pop-up with drupal commons..

# Answer
> 1 votes
I'm assuming you want to build a calendar of Events with Views in Commons. You need to install Colorbox by following the instructions. To create a view of Events, proceed as follows:

1. Check *Enable Colorbox inline* at `/admin/config/media/colorbox`.
2. Add a new view of Events as usual, set *Display format* to the way you want with *fields* (the default is usually *teasers*).
3. Continue and edit the view. In the *Fields* section, edit *Content: Title* and check *Exclude from display*. Add a *Content: Date* field, and a few more fields that you want to display in the popup, and likewise check *Exclude from display* for all of them.
4. Add a *Colorbox: Colorbox trigger* field, set its *Trigger field* to *Date*, and edit the *Popup* contents. You can use replacement patterns in popup contents.
5. Save the view.

# Answer
> 2 votes
The Fullcalendar module has similar functionality - it allwes you to display event node in popup. By default, there is support for Colorbox. However, there is also a patch for using Overlay (from Drupal core).

# Answer
> 1 votes
Consider looking at the Field formatter for colorbox module. That module doesn't have a lot of documentation (yet), as confirmed also in some of the issues in its issue queue. And I don't have experience with it myself (yet).

But in Comment nr 2 of Issue 2334695, the module maintainer wrote this:

> The field formatter of the Colorbox module is for images only. This module here **supports text and computed fields** and comes with some specific options for those field types.

So I think your best bet is to give this module a try, and if needed create an appropriate issue in it's issue queue to get it to work.

---
Tags: javascript, datetime, 7
---


# Question
Title: How to let the user enter the price for particular product in Commerce Kickstart?
I have installed Commerce Kickstart (version 7.x-2.25).

I have to set the price as 100 Rs. At the same time user will enter an amount above 100rs.

Is there any option for the user to enter the price and go to cart and checkout page?

# Answer
# Option 1: Commerce Donate

Maybe you want to try/experiment with the Commerce Donate module. Excerpt from its project page:

> provides a donation line item type along with a donation product and product display.
>
> In addition to being able to create a donation product, this module also provides a donation checkout pane, allowing customers to add a donation to their order as part of the checkout process.

You could use the 100 Rs as your "price", and implement the "\* ... user will enter the price above 100 Rs\* ..." as some kind of "donation"?

**Note**: refer to this tutorial/screencast also for a great introduction to this module.

# Option 2: Commerce Auction

As an alternative, consider the Commerce Auction module for creating auction websites using Drupal Commerce. Here is a quote about it (from the module's project page):

> ... lets you create auction/reverse auction websites using Drupal Commerce. It uses ECK to create a new entity for commerce auction bids.
>
> The module consists of 4 sub-modules:
>
> * **commerce\_auction**: provides core auction and bidding system
> * **commerce\_auction\_field\_helper**: provides a field formatter for entityreference fields which shows the count of referenced entities and a read-only widget for commerce\_price fields. You can use this formatter to show the bids count.
> * **commerce\_auction\_lineitem**: creates a new commerce\_line\_item type, updates auctioned product price and adds the product to the auction winner's cart when the auction is finalized. The auctioned products are added to the cart as 'commerce\_auction\_lineitem' line\_items.
> * **commerce\_reverse\_auction**: provides reverse auction feature.
> 1 votes

# Answer
I guess you're looking for Auction

> An auction is a process of buying and selling goods or services by offering them up for bid, taking bids, and then selling the item to the highest bidder.

Check Commerce Auction module

> This module lets you create auction/reverse auction websites using drupal commerce.
> 2 votes

---
Tags: 7, users, commerce
---


# Question
Title: How to specify a Rules event like "Content is 'going to be' viewed"?
To answer the question about "How to restrict access to a node via node/12 and allow access via a path like content/sometitle?", I thought it should be possible to use the Rules module to do so.

I was thinking about a rule as in this exported rule (which has "***Content is viewed***" as event):

```
{ "rules_disallow_using_urls_like_node_123" : {
    "LABEL" : "Disallow using URLs like node\/123",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_view" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "site:current-page:path" ], "value" : "node\/[node:nid]" } }
    ],
    "DO" : [
      { "redirect" : { "url" : "no_access" } },
      { "drupal_message" : { "message" : "Sorry, URLs like node\/[node:nid] are not allowed around here ..." } }
    ]
  }
}

```

Here is the challenge (and my actual question): for any node you visit, and even when visiting nodes using the path of such nodes, the rules action **always** gets executed. That makes me wonder how I can rework that "Content is viewed" event into something like "Content is 'going to be' viewed", so before Drupal is actually going to display the requested node? And this without writing a custom module.

To better explain the 'going to be'-part of it: compare it to the Content Access" module: if you try to visit a page for which content access is set so that you do NOT have permission to (e.g.) view it, then Drupal **will FIRST check** via content access if you do have access to it, then decides you have no permission, and then you will NOT actually be able to "view" that page (even though you asked for it). So that "will FIRST check" is similar to "going to be" ...

I also looked at the (unasnwered) question about "I cannot see the Rules event "Page is going to be viewed"", in which one of its comments points to issue nr 514824 (which is for D6). And in that issue there is Fago's comment #8 like so:

> Use the "Content is being viewed" event when you need the node.

Assuming that was available (and working as such) in D6, what is the D7 equivalent of this event, if any? Because, obviously, my sample above seems to indicate that in D7 it doesn't work like that anymore.

**Note**: The exported source above is intentionally DISABLED, because **if** you'd want to import it and enable it, **then** it is always going to get triggered for ANY node you view. Only URLs starting with (eg) `/user` or `/admin` will not satisfy the Event in this rule (so that at least you can disable this rule again to be able to view /node paths also again).

# Answer
> 1 votes
You should react to the *System \> Drupal is initializing* event and check for the URL there:

```
{ "rules_check_url" : {
    "LABEL" : "Disallow node/* access",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "text_matches" : {
          "text" : [ "site:current-page:url" ],
          "match" : "node\/\\d+$",
          "operation" : "regex"
        }
      }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "Sorry, URLs like [site:current-page:url] are not allowed around here ...",
          "type" : "error"
        }
      },
      { "redirect" : { "url" : "no_access" } }
    ]
  }
}

```

Also, notice that in the rule above we test against the `site:current-page:url` token, which contains the (full) original URL (as seen in the browser address bar). Checking against `site:current-page:path` would not work in this case as all nodes, even the ones being accessed via URL alias, would match.

# Answer
> 1 votes
Here is how I solved redirect based on ip.

My requirement: Show a different 'pricing' page based on country.

Default pricing page is node/7 - showing pricing in usd, node/12 is pricing page in INR

Using smart\_ip module

Redirect user from pricing(node/7) to pricing.in(node/12) - if user ip is India

**Event**:

Content viewed is of type Basic page
Drupal is initializing

**Conditions**

IP address is in country
*Parameter: Country: India*
data comparison
Parameter: Data to compare: \[site:current-page:path\], Data value: node/7

**Event**

Page redirect
Parameter: URL: node/12

Exported Rule \>\>

```
{ "rules_pricing_page_inr" : {
"LABEL" : "Pricing page INR",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "smart_ip", "rules" ],
"ON" : { "node_view--page" : { "bundle" : "page" }, "init" : [] },
"IF" : [
  { "smart_ip_condition_in_country" : { "country" : { "value" : { "IN" : "IN" } } } },
  { "data_is" : { "data" : [ "site:current-page:path" ], "value" : "node\/7" } }
],
"DO" : [ { "redirect" : { "url" : "node\/12" } } ]
  }
}

```

---
Tags: 7, rules
---