title: Hierarchical grouping in Views?

text:
# Question
Title: Hierarchical grouping in Views?
Drupal 7, Views 3, etc.

I'd like to use Views' grouping feature to group results hierarchically. I added the two fields I want to group with to the grouping list. I'd like to group by year, then by term. Here's the output I get now:

* 2011
    + Term 1
        - Result 1
        - Result 2
* 2011
    + Term 2
        - Result 3
        - Result 4
* 2012
    + Term 3
        - Result 5
        - Result 6
* 2012
    + Term 4
        - Result 7
        - Result 8

... and so on.

Here's what I want to see:

* 2011
    + Term 1
        - Result 1
        - Result 2
    + Term 2
        - Result 3
        - Result 4
* 2012
    + Term 3
        - Result 5
        - Result 6
    + Term 4
        - Result 7
        - Result 8

I thought that by using the "Use rendered output to group rows" checkbox, it would cause Views to ignore differences in the contents of the actual date field (which is more granular than just the displayed year) and only sort by year. Am I misunderstanding this checkbox, or is there something preventing it from working properly?

# Answer
I found the answer to my question by tinkering. Like most solutions to my aggravating questions, it's stupidly simple.

**I checked "remove tags from rendered output".**

Upon inspection of the HTML page source, I found that the attribute `content="[long, granular-to-the-millisecond datetime]"` (e.g. `content="2011-08-01T00:00-04:00"`) was plopped inside a `<span>` tag that was wrapped around the rendered output. So even though it *looked* like it was being grouped only by the 4-digit **year** value, it was actually being grouped by this whole, long value:

```
<span class ="date-display-single" content="[datetime]" datatype="xsd:dateTime" property="dc:date">[Year]</span>

```

Since each of these contained a totally unique datetime value, it appeared not to be grouping by year at all.
> 1 votes

---
Tags: views
---


title: Printing taxonomy terms in node.tpl

text:
# Question
Title: Printing taxonomy terms in node.tpl
I am trying to print taxonomy terms using this code:

```
<?php foreach ((array)$taxonomy as $item) { ?>
<a href="<?php print base_path() . "taxonomy/term/" . $item->tid; ?> "class='tags'><?php print $item->name ?>,</a>
<?php } ?>

```

It works fine if I put in contemplate, however it doesn't in the full node (node.tpl.php), the tags are empty in the full node. Can any one tell me what is the reason for this and how to fix this?

# Answer
First verify that the $taxonomy variable is available and populated in your node.tpl.php file. ...

EDIT:

Your accessing the values in your $item variable like it is an object but your casting to an array. Try accessing as an array:

```
 <a href="<?php print base_path() . "taxonomy/term/" . $item['tid']; ?> "class='tags'><?php print $item['name'] ?>,</a>

```
> 2 votes

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


# Question
Title: How can I add an operation to the node and user lists?
I am looking for a way to add entries in the "Operations" Column at:

```
/admin/people

```

and or

```
/admin/content

```

I considered hook\_node\_operations and hook\_user\_operations

But those are for adding commands to bulk operations.

# Answer
If you look at the User module in `DRUPAL_ROOT/modules/user` you'll see the `user_menu()` function: http://api.drupal.org/api/drupal/modules!user!user.module/function/user\_menu/7

You can add your own operation by making your own hook\_menu() that mimics what Core does for the "Permissions" Operation. Its also important to note that these tabs or drop down operations (depending on your theme) are essentially defined as `MENU_LOCAL_TASK` items in the drupal menu system. See below:

```
// What Core does in user_menu() ...
 // Permissions and role forms.
  $items['admin/people/permissions'] = array(
    'title' => 'Permissions',
    'description' => 'Determine access to features by selecting permissions for roles.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_admin_permissions'),
    'access arguments' => array('administer permissions'),
    'file' => 'user.admin.inc',
    'type' => MENU_LOCAL_TASK,
  );

// You do something similar in your own module ...
  function mymodule_menu() {
    $items['admin/people/foobar_operation'] = array(
      'title' => 'Foo Bar Operation',
      'description' => 'A form with my custom settings',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('yourmodule_foobar_permission'),
      'access arguments' => array('administer yourmodule permissions'),
      'file' => 'yourmodule.admin.inc',
      'type' => MENU_LOCAL_TASK,
    );

    // Do the same for stuff under admin/content.

    return $items;
  }

```

Hopefully this tidbit helps...
> 1 votes

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


# Question
Title: User login using a token or ID (no password)
How I am able to create a form/link to let assigned/special users to log-in to the system without entering their username and password?

I want them to be able to use a link/token to login to system instead.

This is mainly for development purpose and I am aware of the security risks on the live website

Thank you in advanced

# Answer
If security's not a concern (and make sure it really isn't!) then you might as well do it the simplest way possible.

This would involve a small custom module that provides a path to log in users by their ID.

```
function MYMODULE_menu() {
  $items['insecure-login/%MYMODULE_insecure_login'] = array(
    'title' => 'Insecure login',
    'access callback' => TRUE, // Might as well be, no point in authenticating
    'page callback' => 'MYMODULE_insecure_login',
    'page arguments' => array(1)
  );

  return $items;
}

function MYMODULE_insecure_login_load($uid) {
  // Don't let user 1 login with this method
  if ($uid == 1) {
    return FALSE;
  }

  // Just return the user ID
  return $uid;
}

function MYMODULE_insecure_login($uid) {
  if ($account = user_load($uid)) {
    global $user;
    $user->uid = $uid;
    $user->name = $account->name;
    $user->timezone = $account->timezone;
    user_login_finalize();
    drupal_goto('user');
  }
}

```

Users will be able to login by visiting http://example.com/insecure-login/USER\_ID

I've tested this and it worked, but it felt very wrong. The above code is just a proof of concept if you like, I can't really recommend that you use it.

Please, please double check your thinking before using any method like this; you're obviously aware of the security implications but I can't sign off this post in good conscience without encouraging you to think about it a little more ;)
> 3 votes

---
Tags: users
---


title: Tera Wurfl for Drupal

text:
# Question
Title: Tera Wurfl for Drupal
Has anybody added or know how to add tera wurfl to their drupal 7 site? I have tried to implement it on my test site with no success. For those of you who don't know, it is a mobile detection program. I'm also open to a good alternative. Doesn't seem like there is too much info on this topic in the forum. Any help would be great. Thanks

# Answer
> 0 votes
WURFL underwent licensing changes a little while back, and I stopped using it.

I either use Mobile Tools if I need all of the features it provides (mainly Panels integration) or I use get\_browser directly (make sure you have a recent browscap.ini).

I don't think Mobile Tools has a stable Drupal 7 release, though.

There is also the Drupal Browscap module, which purports to be better than the native version, though, I just manually keep my browscap.ini up-to-date.

---
Tags: 7, theming, mobile-tools
---


# Question
Title: get views customfield php value in another field
i create a views in drupal 6.24.set up some field like username and uid, in third field used **customfield php** .with my custom php code filled this filed, in another customfield php want use the value of customfield php value ,how can i do it? i know with **$data-\>uid** (if userid exist im my views filed) can get current row uid. i test $data-\>phpcode but return null to me. please tell me about how can i get customfield php in views?

# Answer
the correct way to this is add your desire code in value section ,with return it, and in output section use

```
<?php
 print $vlaue;
 ?>

```

with this method we can access all pervious variable in current and next php global field. this descriptions are all about views\_php module ;)

i hope this be useful for futures user with this problem,
> 0 votes

# Answer
You should use the views\_php module instead. It is the successor of Views Customfield PHP. The current module you are using does only render content, but has no value. views\_php introduce the possibility to define both value and rendering settings. You should then be able to use the generated value in other fields.
> 0 votes

---
Tags: views
---


# Question
Title: Why do start and end dates in views appear the same but are not in content?
When adding fields to a view I have two entries for date. One for the start date and one for the end date. However in my view they are both the start date. I check my content and it shows differing values for start and end dates.

Why does views not render the end date?

# Answer
It sounds to me like you have a single date field in your content that you have set with an end date but in your view you have set this with two different fields. Instead you should edit the view and click the first date field and check the formatter settings to be one that includes start and end dates.
> 1 votes

---
Tags: 7, views, datetime
---


# Question
Title: Drupal 7 - FAPI - Multistep form - with add another option
I'm creating a multistep form in Drupal 7 - FAPI.

In the main hook\_form() the redirection to the different steps are handeled.

```
function hook_form($form, &$form_state) {
    if (empty($form_state['storage']['step'])) {
        $form_state['storage']['step'] = 0;
    }

    switch($form_state['storage']['step']) {
        case 0:
          $form=  _step_0($form, $form_state);
        break;
        case 1:
          $form =  _step_1($form, $form_state);
        break;
        case 2:
          $form =  _step_2($form, $form_state);
        break;
        case 3:
          $form =  _step_3($form, $form_state);
        break;
        case 99:
          $form =  _step_end($form, $form_state);
        break;
    }
    return $form;
}

function _step_2($form, &$form_state) {
    ....
    $form['Name'] = array(
        '#title' => t('Name'),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#maxlength' => 80,
        '#size' => 80,
    );

        $form['Street'] = array(
        '#title' => t('Street'),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#maxlength' => 80,
        '#size' => 80,
    );

    ......

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

    $form['add'] = array(
            '#type' => 'submit',
            '#value' => 'Collega toevoegen',
        );
}

```

In step 2 I have an optional button 'Add onther' which saves the form\_values into storage and reloads the same form (step 2). But when it reloads this form for the seconds time. the previous form values are being represented as default form values and not a blank (new) form, which is wanted.

```
function inschrijven_form_submit($form, &$form_state) {
    switch ($form_state['storage']['step']) {

        case 0:
          switch($form_state['values']['op']) {
            case 'Next' :
              ....
              $form_state['storage']['step'] = 1;
            break;
          }
        break;

        case 1:
          switch($form_state['values']['op']) {
            case 'Next' :
              ....
              $form_state['storage']['step'] = 2;
            break;
          }
        break;

        case 2:
            switch($form_state['values']['op']) {
                case 'Next' :
                    ....
                    $form_state['storage']['step'] = 3;
                break;

                case 'Add another' :
                    $form_state['rebuild'] = TRUE;
                    ....
                    $form_state['storage']['step'] = 2;
                    return;
                break;

        .....

    }
}

```

I've try to clear the form\_state\['values'\] manually after each submit but with no success. Who can this multistep with add another functionality be achieved?

# Answer
When you want to add a new set of values, you have to build the form in a different way - the fields that should be "multiplicated" have to be in an array.

so, your

```
$form['Name'] = array(
        '#title' => t('Name'),
        '#type' => 'textfield',

```

should instead look like this :

```
$form['step2'][$i]['Name'] = array( ...

```

where $i is set to zero in the begining and increased by the callback for your "add another" button. The "step2" fieldset is there just to help you distinguish the parts that are repeated from the others - its not necessary i guess. The aformentioned examples module has nice examples how to acheive that even with ajax, so you dont have to reload the whole thing. Dont forget to set

```
$form['#tree'] = TRUE;

```

so that you can process the several sets of results.
> 0 votes

---
Tags: forms
---


title: Can you use jQuery to display a view?

text:
# Question
Title: Can you use jQuery to display a view?
I want to do something similar to views slideshow. The thing is my javascript is written already. I would like my javascript to be able to be integrated within the drupal framework from views. The JQuery just is a simple image slideshow like this one here. I just would prefer that I could show all or specific view field content instead of putting in the url in the javascript the long way. I want these images to come directly from a content type. Can you show me how?

# Answer
You could create a small module that will be called through ajax:

```
function MYMODULE_node_menu() {
    return array(//$items
        'MYMODULE/%' => array(
            'page callback' => 'MYMODULE_display_view',
            'page arguments' => array(1),
            'access callback' => TRUE,
            'type' => MENU_CALLBACK,
        )
    );
}
function MYMODULE_display_view($view_name) {
    // display your view depending on $view_name
   $view = views_get_view($view_name);
   $view->execute();
   echo $view->render();
}

```

Get a views html by making an ajax call using jQuery:

```
$(document).ready(function() {
   $.ajax('MYMODULE/YOUR_VIEW_NAME', {
           sucess:function(data) {
              // data will contain the html for your view
           }
   });
 });

```

You might find the following Drupal 7 Advanced Ajax helpful.
> 4 votes

---
Tags: views, javascript
---


title: Customized theme not working

text:
# Question
Title: Customized theme not working
How do I display a form followed by a table in a module??

I have this:

```
function main_function(){
  $form = drupal_get_form("report_details_form");
  $tabb = array(
    'header' => $header,
    'rows' => $rows,
    'caption' => $caption,);
  $output = theme("table", $tabb)
  $final_output = theme("report_page", $form, $output);
  return $final_output;
}

function theme_report_page($form, $result = array()) {
  $output = '
    <div id="report_form">
    '. $form .'
    </div>
    <div id="report_result">
    '. $result .'
    </div>';
  return $output;
}

```

What am I doing wrong? I am using Drupal 7. I need to display the form and under it the table. There is nothing wrong with $form or $output. If I return them in the main\_function they will display correctly.

I don't NEED a theme, I just need to display a form and table on the same page. So if it is to demanding I can skip it, and just have the form and table displayed.

I changed the main\_function a bit to this:

```
function main_function(){
 $form = drupal_get_form("report_details_form");
 $tabb = array(
  'header' => $header,
  'rows' => $rows,
  'caption' => $caption,);
 $output = theme("table", $tabb)

$build['content'] = array(
  'this_does_not_matter_too_much2' => drupal_get_form("report_details_form"),
  'this_does_not_matter_too_much1' => array('#markup' => $output,),);

$build['pager'] = array(
    '#theme' => 'pager',
    '#weight' => 5,
);

return $build;

```

A dummy table is now displayed, but just in the first call to the page, not when the page is self called after submiting the form for first time. A custom table is then created to list all the results for a SELECT. This custom table is not displayed for some reason.

# Answer
> 0 votes
I think you should this in this way, so you should register you theme hook

---
Tags: theming, forms
---


# Question
Title: shorten input text size and maxlength with exposed filters
I use Drupal-7.14 and Omega sub theme. I have a view of my content type with exposed filters. When focusing input tags, HTML output is like this:

```
<div class="view-filters">
  <form action="/searchedlist" method="get" id="views-exposed-form-searchedlist-page-1" accept-charset="UTF-8">
    <div>
      <div class="views-exposed-form">
         <div class="views-exposed-widgets clearfix">
            <div id="edit-field-bango-value-wrapper" class="views-exposed-widget views-widget-filter-field_bango_value">
              <label for="edit-field-bango-value"> BANGO </label>
                <div class="views-widget">
                  <div class="form-item form-type-textfield form-item-field-bango-value-min">
                    <input type="text" id="edit-field-bango-value-min" name="field_bango_value[min]" value="" size="30" maxlength="128" class="form-text" />
                  </div>
                  <div class="form-item form-type-textfield form-item-field-bango-value-max">
                    <label for="edit-field-bango-value-max">And </label>
                    <input type="text" id="edit-field-bango-value-max" name="field_bango_value[max]" value="" size="30" maxlength="128" class="form-text" />
                  </div>
                </div>
              </div>

```

Please show me how to change the input text size from 30 to 10 and its maxlength from 128 to 20.

## for other startup people

I've reached the solution.

```
# mkdir sites/all/modules/mymodule
# cd sites/all/modules/mymodule
# vi mymodule.info
# cat mymodule.info
name = mymodule
description = mymodule for dummy
package = mymodule
files[] = mymodule.module
version = "7.x-1.0"
core = "7.x"
# vi mymodule.module
# cat mymodule.module
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id){
  if($form_id == "views_exposed_form"){
    //dsm($form); // print $form array on the top of the page
    if (isset($form['field_bango_value']['min']) && isset($form['field_bango_value']['max'])) {
      $form['field_bango_value']['min']['#size'] = '10';
      $form['field_bango_value']['max']['#size'] = '10';
      $form['field_bango_value']['min']['#maxlength'] = '20';
      $form['field_bango_value']['max']['#maxlength'] = '20';
    }
  }
}
# wget http://ftp.drupal.org/files/projects/devel-7.x-1.3.tar.gz
# tar xzf devel-7.x-1.3.tar.gz
# mv devel modules

```

Admin \> Modules

Check the boxes on mymodule and Devel,then Save.

Admin \> config \> development \> performance

Clear caches.

Browse hostname/myview

Finally, HTML input tags says:

```
<input type="text" id="edit-field-bango-value-min" name="field_bango_value[min]" value="" size="10" maxlength="20" class="form-text" />
<input type="text" id="edit-field-bango-value-max" name="field_bango_value[max]" value="" size="10" maxlength="20" class="form-text" />

```

# Answer
> 2 votes
You should be able to use a regular hook\_form\_alter and has a great answer already, check it out and it should answer your question.

---
Tags: 7, views, debugging
---


# Question
Title: Manual language translation in drupal website?
I am developing the job portal website in multilingual. right now site have two (German&English) languages. and have static & dynamic content. I have to use manual language translator text (client will provide the content for static). not a auto translating option like google translator.

1. How to translate the entire site in multilanguage, Handling dynamic data, menus etc.
2. What are the modules will you suggest for this

Please help us on this, and let me know if you need further details.Thanks in advance.

# Answer
You need to enable the core modules "Locale" and "Content Translation". There's additional contributed modules like Internationalization or in short i18n

I'm not quite sure what you mean by "dynamic data". So I can't answer that part of your question.
> 0 votes

---
Tags: i18n-l10n
---


title: Fivestar votes on drupal fields

text:
# Question
Title: Fivestar votes on drupal fields
I'm looking for a drupal module, that allows me to have a fivestar voting for every user (also anonymous) and for every value of a certain field in a node.

What am I trying to do? I'm trying to have a gallery. Each node with the content-type of "gallery" represents a gallery. In it there is one Image field which allows multiple values. And **each image-value** should be rateable.

Does anyone know such a module for Drupal 7?

Thanks

# Answer
> 4 votes
You can do this easily with the help of three modules
1) Entity
2) Fivestar
3) Field collection

Step 1. Install above modules.
Step 2. Create content type gallery.
Step 3. Add field collection as a field in the content type.
step 4. Add fields(Image field and fivestar field) to the field collection http://www.example.com/admin/structure/field-collections

---
Tags: 7, entities, rating, media
---


# Question
Title: How can i get the value from the Dynamic query
```
$query=db_select('node','n');
$query->join('field_data_field_cmp_playerid','b','n.nid=b.entity_id');
$query->join('field_data_field_cmp_id','c','n.nid=c.entity_id');
$query->join('field_data_field_cmp_userscore','d','n.nid=d.entity_id');
$query->join('field_data_field_cmp_usersupport','e','n.nid=e.entity_id');
$query->join('field_data_field_cmp_status','f','f.entity_id=c.field_cmp_id_nid');
$query->join('field_data_field_cmp_attend_time','g',' g.entity_id = n.nid');
$query->join('field_data_field_cmp_end_date','h',' h.entity_id = c.field_cmp_id_nid');
$query->fields('n',array('title','nid'),'d',array('field_cmp_userscore_value'),'e',array('field_cmp_usersupport_value'),'f',array('feld_cmp_status_tid'),'g',array('.field_cmp_attend_time_value'),'h',array('field_cmp_end_date_value'));
$query->condition('b.field_cmp_playerid_uid',$userid,'=');
$query->condition('n.type','Campaign_PlayerList','=');
$result=$query->execute()->fetchAll();

```

i use foreach loop to get the value of the query

```
foreach($result as $value)
{
    drupal_set_message(t('The variable is %va',array('%va'=>$value->title)));
    drupal_set_message(t('The variable is %va1',array('%va2'=>$value->field_cmp_userscore_value)));
    drupal_set_message(t('The variable is %va2',array('%va2'=>$value->field_cmp_end_date_value)));
}

```

the value i get is "title" and i can't get the field\_cmp\_userscore\_value and field\_cmp\_end\_date\_value value.

what could the problem be?

Thank you

# Answer
The `fields()` member function of a `SelectQuery` class only take two arguments: An alias and an array of fields. At the moment you're trying to add the fields from all tables in one go, when you need to split them up into separate calls to `fields()`:

```
$query->fields('n',array('title','nid'));
$query->fields('d',array('field_cmp_userscore_value'));
$query->fields('e',array('field_cmp_usersupport_value'));
$query->fields('f',array('field_cmp_status_tid'));
$query->fields('g',array('field_cmp_attend_time_value'));
$query->fields('h',array('field_cmp_end_date_value'));

```

There are also a couple of typos in your fields names:

1. `.field_cmp_attend_time_value` should be `field_cmp_attend_time_value`
2. `feld_cmp_status_tid` should be `field_cmp_status_id`
> 1 votes

# Answer
The problem is that the following line is wrong:

```
$query->fields('n',array('title','nid'),'d',array('field_cmp_userscore_value'),'e',array('field_cmp_usersupport_value'),'f',array('feld_cmp_status_tid'),'g',array('.field_cmp_attend_time_value'),'h',array('field_cmp_end_date_value'));

```

You need to call fields() separately for each table. Right now, the additional arguments are ignored.

Also note that it is strongly recommended to use EntityFieldQuery to query field tables, that however has the limitation that you need to load the node object to get the field values.
> 1 votes

---
Tags: database
---


# Question
Title: Drupal Commerce: Add content nodes to checkout steps
We have a number of checkout steps that have some content in them that can only be edited via templates which is not ideal for clients.

Is it possible to create content nodes in the CMS that can then be used on the checkout?

# Answer
It is! With the module commerce\_extra\_panes you can add nodes (content) to the checkout.
> 1 votes

---
Tags: commerce
---


# Question
Title: Panels layout with sidebar next to 3 pane grid
I'm using Panels 3.2 on a fresh install of Drupal 7. I want to create a custom layout that I can use and manage via Panels, and the flexible editor is great, but not quite sufficient for the layout I want (as far as I can tell).

Currently I have a simple 3-column layout, but what I want to achieve is this:

I did take a look at Panels Extra Layouts, but I'm not sure if that would cater for this.

EDIT: to clarify, I don't have a problem creating a layout like this with straight up HTML and CSS. I'm just looking for a way of introducing another region above the first two columns of a 3 column layout - something which the flexible layout editor doesn't seem to allow. Sorry for any confusion.

# Answer
Just take a peek at the current layouts you have, and you can probably figure out how to add new regions, it's fairly straightforward.

There's also a tutorial here: http://drupal.org/node/495654
> 2 votes

# Answer
This is not really a Drupal or Panels issue, but this has been a long standing issue with using divs and CSS instead of tables for layouts. Essentially unless you use Javascript, you can't really force divs stretch vertically and match the neighbor divs height. However there's a neat little trick featured on an article on "A List Apart" called "Faux Columns". It's quite old but I believe solves your problem. http://www.alistapart.com/articles/fauxcolumns/
> 1 votes

---
Tags: panels, theming
---


title: Views not showing Pager

text:
# Question
Title: Views not showing Pager
I created a Views out of some nodes and displaying it. And I've done views theming of type **Row style output** and saved the file in following format **views-view-fields--\[views machine name\].tpl.php**. All is working great except the views pager/navigation. It's simply not showing up, I tried all type of combinations : **full pager, mini pager, Display a specified number of items and display all items,** but of no use.

One important thing: I'm also using using **CCK pager** which might be overriding the views pager. For this issue, I tried changing **views pager id**, but that too failed.

# Answer
I figured it out that i used multi-field selector which has its own set of **min-max** fields limits, which were by default set to display **all**. There was no conflicts between the CCK pager and the view pager nor with the pager id.
> 0 votes

# Answer
Seems like this problem can have a bunch of reasons depending on the site, therefore I'm adding my own answer that worked for me, even though the issue has already an accepted one. In my case none of the google-findable answer worked, so I started debugging. The clue was viewing the paged view under another theme. Pager worked like a charm which led me to do regression tests with stuff like templates, theme.info region declarations and... functions in template.php. The latter was the answer - I had a `theme_item_list` override for some paths, and the switch was missing default case.

```
function MYTHEME_item_list($variables) {
  switch( drupal_get_path_alias($_GET['q']) ){
    case 'path/one':
    case 'path/two':
      // pasted raw function from theme.inc with wrapper tags removed:
      // <div class="item-list"> and </div>
      // so to deliver required markup for jquery plugin
      $output = ....
      return $output;
    default: // was missing
      return theme_item_list($variables);
  }
}

```

So, to all ye who have problems with pager - the reason at your site can be completely different, but it might as well be buried in the theme assets you're using.
> 0 votes

---
Tags: views, paging
---


title: User flagged nodes in views

text:
# Question
Title: User flagged nodes in views
I'm using the flag module with Views. I need to display all the nodes a user has flagged. This is quite similar (point.3) View of users flagged by a user, users flagging a user, and nodes from users flagged by a user \- But there doesn't appear to be an answer. Any idea how to achieve this?

The view will take in the uid as a contextual filter from the URL. But I'm not sure how to print out the related flagged content, as the view has only user information available..

Edit\> There will be multiple users in which anyone can view the profiles of. On a users profile there is a tab called 'Following'. This needs to show the nodes that the user (being viewed) has flagged 'follow'. So I've created a page in a view 'user/%/following' for example.. I've included the flag relationship, I just need to print out the node teasers.. This option doesn't appear to be available..

Any ideas? Cheers!

# Answer
> 7 votes
I'm not sure I understood the question... it is very simple. You don't need contextual filter, you need to add a relationship with Flag by current user. Click on relationship a look for Flags: User's flagged content, then select the type of flag and here we go, you got a page or a block with the content flagged by the current user.

If you are using drupal 7 import this view to see if it's what you are looking for

```
$view = new view;
$view->name = 'User Follow';
$view->description = '';
$view->tag = 'flag';
$view->base_table = 'node';
$view->human_name = '';
$view->core = 0;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['title'] = 'User bookmarks';
$handler->display->display_options['access']['type'] = 'role';
$handler->display->display_options['access']['role'] = array(
  2 => '2',
);
$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'] = 'none';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'type' => 'type',
  'title' => 'title',
  'name' => 'name',
  'comment_count' => 'comment_count',
  'last_comment_timestamp' => 'last_comment_timestamp',
);
$handler->display->display_options['style_options']['default'] = 'last_comment_timestamp';
$handler->display->display_options['style_options']['info'] = array(
  'type' => array(
    'sortable' => TRUE,
  ),
  'title' => array(
    'sortable' => TRUE,
  ),
  'name' => array(
    'sortable' => TRUE,
  ),
  'comment_count' => array(
    'sortable' => TRUE,
  ),
  'last_comment_timestamp' => array(
    'sortable' => TRUE,
  ),
);
$handler->display->display_options['style_options']['override'] = FALSE;
$handler->display->display_options['style_options']['sticky'] = 1;
$handler->display->display_options['style_options']['order'] = 'desc';
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['text']['id'] = 'area';
$handler->display->display_options['empty']['text']['table'] = 'views';
$handler->display->display_options['empty']['text']['field'] = 'area';
$handler->display->display_options['empty']['text']['empty'] = FALSE;
$handler->display->display_options['empty']['text']['content'] = 'This user has not yet bookmarked any content.';
$handler->display->display_options['empty']['text']['format'] = 'plain_text';
/* Relationship: Flags: bookmarks */
$handler->display->display_options['relationships']['flag_content_rel']['id'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['table'] = 'node';
$handler->display->display_options['relationships']['flag_content_rel']['field'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['label'] = 'bookmarks';
$handler->display->display_options['relationships']['flag_content_rel']['flag'] = 'bookmarks';
$handler->display->display_options['relationships']['flag_content_rel']['user_scope'] = 'any';
/* Relationship: Content: Author */
$handler->display->display_options['relationships']['uid_1']['id'] = 'uid_1';
$handler->display->display_options['relationships']['uid_1']['table'] = 'node';
$handler->display->display_options['relationships']['uid_1']['field'] = 'uid';
$handler->display->display_options['relationships']['uid_1']['required'] = 0;
/* Relationship: Flags: User */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'flag_content';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
$handler->display->display_options['relationships']['uid']['relationship'] = 'flag_content_rel';
$handler->display->display_options['relationships']['uid']['label'] = 'bookmarks_user';
$handler->display->display_options['relationships']['uid']['required'] = 1;
/* Field: Content: Type */
$handler->display->display_options['fields']['type']['id'] = 'type';
$handler->display->display_options['fields']['type']['table'] = 'node';
$handler->display->display_options['fields']['type']['field'] = 'type';
/* 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']['link_to_node'] = 1;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'uid_1';
$handler->display->display_options['fields']['name']['label'] = 'Author';
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
/* Field: Content: Comment count */
$handler->display->display_options['fields']['comment_count']['id'] = 'comment_count';
$handler->display->display_options['fields']['comment_count']['table'] = 'node_comment_statistics';
$handler->display->display_options['fields']['comment_count']['field'] = 'comment_count';
$handler->display->display_options['fields']['comment_count']['label'] = 'Replies';
/* Field: Content: Last comment time */
$handler->display->display_options['fields']['last_comment_timestamp']['id'] = 'last_comment_timestamp';
$handler->display->display_options['fields']['last_comment_timestamp']['table'] = 'node_comment_statistics';
$handler->display->display_options['fields']['last_comment_timestamp']['field'] = 'last_comment_timestamp';
$handler->display->display_options['fields']['last_comment_timestamp']['label'] = 'Last Post';
/* Contextual filter: User: Uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'users';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['relationship'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'empty';
$handler->display->display_options['arguments']['uid']['exception']['title_enable'] = 1;
$handler->display->display_options['arguments']['uid']['title_enable'] = 1;
$handler->display->display_options['arguments']['uid']['title'] = '%1\'s bookmarks';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['specify_validation'] = 1;
$handler->display->display_options['arguments']['uid']['break_phrase'] = 0;
$handler->display->display_options['arguments']['uid']['not'] = 0;
/* 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']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'user/%/bookmarks';
$handler->display->display_options['menu']['title'] = 'Bookmarks';
$handler->display->display_options['menu']['weight'] = '0';

```

---
Tags: views, flags
---


# Question
Title: Make a view or panel that displays image *or* video field if present
My goal is to have a content type that will display an image in a certain panel pane or an embedded video, if the video is present.

I can imagine setting up two fields, one for the image and one for the video embed code. But I'm not sure how to hide the image if the video is present or to make the video field take precedence over the image field in panels.

# Answer
> 7 votes
It can be done with Views rewriting options.

1. Add both fields (Image *before* Video) to Views and exclude Image field from output.
2. For Video field set “NO RESULTS BEHAVIOR” to Image field token:

It means that if Video field is empty Views will get value from this textarea, which contains special placeholders (in this case `[field_image]`).

Available tokens for your fields can be found under “REWRITE RESULTS” fieldset:

Don't forget to uncheck “Rewrite the output of this field” flag.

# Answer
> 0 votes
Kalabro solution is good if you use a view with fields. If you use a view with "content" you need to go to the content type -\> Manage Display and hide image and video field.

Then in the node--YOURCONTENT.tpl.php you can write:

```
if ($field_image) {
 print $field_image;
}

if ($field_video) {
  print $field_video;
}

```

Of course you need to change the name of the variables I wrote.

# Answer
> 0 votes
It is done with writing the views tpl.By clicking on the theme option of view and you can check the value of your fields in your tpl files like Display Output,Style Output,etc..You can get the code of this tpl file by clicking on the output which you want to check like Display Output,Style Output,etc..Just like I click on the style Output and the code of the style output is displayed as shown in the image .Now you can save this file with the name as given in the figure1 in front of the tpl(Display Output,Style Output,etc.).Now you can save this in your enabled theme. for more information of view themeing and views tpl naming please see this. http://drupal.org/node/352970.Now you can check values of fields in this tpl and show as per your requirement. After making the tpl file and placing it in your enabled theme direcory.Now you can click on the rescan template files so that this file will be active and this filename will be shwoing in bold text.

```
if ($image) {
 print $image;
}
if ($video) {
  print $video;
}

```

you can change the name of fields($image,$video) above as you have.

---
Tags: views, panels, files, nodes
---


title: How to change comment text using hooks

text:
# Question
Title: How to change comment text using hooks
Under each node there is a 'Add Comment' text. For a particular content type I want to change the text to 'review by adding comment". How do I do this?

# Answer
Try with the String Overrides module. Here is a quote about it (from the module's project page):

> Provides a quick and easy way to replace any text on the site.
>
> Features
>
> * Easily replace anything that's passed through t()
> * Locale support, allowing you to override strings in any language
> * Ability to import/export \*.po files, for easy migration from the Locale module
> * Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
> 0 votes

---
Tags: 6, comments
---


title: Menu Block shows both languages

text:
# Question
Title: Menu Block shows both languages
I'm using the i18n module for translating nodes and menu items. I have a bunch of menu-items and am now trying to put that into the header with a menublock.

But unfortunately all menu-items in all languages appear instead of just the items in the current language and language-neutral.

Does anyone know how to fix that.

The only solution I have is to create a menu for every language.

# Answer
Okay sorry ... it took some time, but I found the solution.

First I had the themed menu within the template, now I have the main menu direct as a block.

The solution was to edit the main menu and set the following option:

* *Translate and Localize. Menu items with language will allow translations. Menu items without language will be localized.*

That's it.
> 1 votes

---
Tags: 7, routes, blocks, i18n-l10n
---


title: How to remove only created hour?

text:
# Question
Title: How to remove only created hour?
I'm using Drupal 7 and Clean theme. And when created a node, show date top on node. No problem. But i want remove only hour and min. tab.

How can i solve this?

# Answer
> 0 votes
I would disable the created date display under the content type settings, and then just add a new date field whose display settings you can alter just like any other field.

The other option would be to change it by overriding hook\_tokens in your theme. Specifically, you would override `format_date($node->created, 'medium', '', NULL, $language_code);` with your custom date format.

# Answer
> 3 votes
I think you want to have your node show *June 12, 2012*

If that is the case, you can do this:

```
function THEME_preprocess_node(&$variables) {
  if ($variables['submitted']) {
    $variables['submitted'] = t('Posted: !datetime', array( '!datetime' => format_date($variables['node']->created, 'custom', 'F j, Y')));
  }
}

```

Here's PHP documentation for date formats: http://php.net/manual/function.date.php

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


title: Timetable for event.

text:
# Question
Title: Timetable for event.
i'm trying to create a timetable using Drupal 7. I need this timetable for an event.

At the moment I created it throught views but I think it is too much "heavy".

I did it in this way.

I created 3 content types: Speaker, Company and Agenda. In the Agenda content type I've got the node reference fields pointing to Speaker and Company. The event has got 3 streams. Now I'm managing the display throught the views, I've created a basic page with a table and per each row (time) I've put one view (content) which shows 3 nodes (one per each stream). this is a normal view wich shows title and body of the node. To show the speaker and the company I've created another view (fields) with agenda nid such as contextual filter. I've put it inside agenda--node.tpl.php. Then I've put another view inside agenda--node.tpl.php which create a js dialog with the topic, speaker and company info. Basically we have in one page about 70 views...

Is it heavy?

I need to create something like this http://cph2010.drupal.org/sessions/timetable.html and the way I would like to create it is this http://groups.drupal.org/node/2567 with this dript style.

Does anyone know the right way to create a timetable with drupal?

Thanks in advance.

# Answer
> 1 votes
One simplification could be the following:

Create just one content type called **presentation** that has speaker, agenda, time, title, and company as fields (and anything else you want).

Then you create one view which lists nodes of type presentation.

* In the fields portion, you select all the fields you think are relevant to show in the table, perhaps just title and speaker. The title can be a link to the full content.
* Perhaps have the style be 'grid' and order the items by 'time', so the ones in the same time slot are on the same row.

That's one idea to make it simpler. Does it work in your case?

---
Tags: 7, views
---


# Question
Title: How to add current user field to view field list, when it has no relation to the content?
**Is it possible to add the current user-id in the rewrite results of a View Field ?**

I have created a view of fields of a custom content type "Document". My goal is to rewrite the `Document: Title`-field to a hyperlink of the following format:

http://mysite.com/download.php?u=\[user-id\]&docid=\[document-fid\]

where `user-id` is the id of the currently logged-in user, and `[document-fid]` is the id of the file in the records of the view.

I know full well that before you can use a certain field in a rewrite, it needs to be added to the fields list of the view, and it has to be placed *before* the field you want rewritten. But here is the problem. When I click "add" in the fields list, I don't see a `User`, or a `User: Current`-field.

Please bare in mind that `User: Current` has absolutely NO relation to the `author` of the item, or any other user related to the document. Therefor I cannot use the Relationships, under the Advanced section in views.

Please advise.

# Answer
> 1 votes
**This is an answer for Drupal 7.**

You can

* use Views template system and rewrite output of the field (will work only for Views) or
* create own formatter for file field (will work everywhere for fields with this formatter) or
* alter any file path in `hook_file_url_alter` (will work everywhere without settings)

I will show how to create field formatter. It will correctly work with standard node rendering, Views, Panels, etc.

```
/**
 * Implements hook_field_formatter_info().
 */
function YOURMODULE_field_formatter_info() {
  return array(
    // Our own formatter for 'file' field
    'YOURMODULE_file_link' => array(
      'label' => t('Special download link'),
      'field types' => array('file'),
    ),
  );
}

/**
 * Implements hook_field_formatter_view().
 */
function YOURMODULE_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  global $user;
  // Now just hide field if user not logged in
  if (user_is_anonymous()) {
    return;
  }

  switch ($display['type']) {
    case 'YOURMODULE_file_link':
      foreach ($items as $delta => $item) {
        // Some title
        $title = isset($item['description']) ? $item['description'] : $item['filename'];
        // Theme link (http://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_link/7)
        $element[$delta] = array(
          '#theme' => 'link',
          '#text' => $title,
          '#path' => 'download.php',
          '#options' => array(
                        'attributes' => array(),
                        'html' => FALSE,
                        'query' => array('u' => $user->uid, 'document-fid' => $item['fid'])
                      )
        );

      }
      break;

  }
  return $element;
}

```

Add this code to your module (replace `YOURMODULE` with your module name), enable module, clear the cache if needed. New formatter will be available in Views field settings and in standard content type display settings.

---
Tags: 7, views, users
---


title: Synchronize two displays of a view?

text:
# Question
Title: Synchronize two displays of a view?
I have a view with several tiers of arguments, navigated like so:

Camp \> Date \> Photo Gallery

I need a way to display a block of all the tags associated with the given content. So when Camp is selected, I need to display the tags associated with content for that camp. When Date is selected, I need to display the tags associated with content for that date AND that camp.

I've tinkered with Panels, I've installed EVA, I tried Views Field, and I just can't figure out how to do this thing.

# Answer
> 0 votes
I got this working, and I didn't need Eva, Views Field, or Panels. I just needed good ol' fashioned Views.

I created a View with a Page and a Block.

Page displays images and takes contextual filters Term (of vocab Camp) and Date. When the value is not in the URL, a summary is displayed.

Block displays Terms (of vocab Tags) and takes the same two contextual filters. When the filter value is not available, I choose Provide default value \> Raw value from URL \> and select relevant path component.

I set the block to display on all pages, but on pages that don't pass it recognized arguments it just doesn't appear because it's empty.

Voilá. So much simpler than I thought.

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


# Question
Title: How do you make a module integrate with the Rules module?
Rules has so many uses but if another module is not integrated to it, you can not use rules with it. Does anyone know how to integrate a module with rules?

The module I would like to integrate is Metatags.

# Answer
> 2 votes
The best documentation you will find is in http://drupalcode.org/project/rules.git/blob/refs/tags/7.x-2.1:/rules.api.php. You will also find this file in the code you downloaded from drupal.org.

You also would probably learn something from looking at other modules that implement rules similar to how you would like it in metatags and seeing how they implement the above hooks.

Then it is up to you do decide what functionality from metatags you want to expose to rules using those hooks.

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


# Question
Title: Limit duration (length / time) of Uploaded Video
I have a website that uses the Video module to allow users to upload videos. I want to limit the duration(both minimum and maximum) of the video that the user uploads.

**For Example:**

Users cannot upload videos that are more than 10mins and less than 5mins. So the duration of their videos should be in-between 5 to 10mins.

Thanks in advance...

# Answer
> 1 votes
You can't do that at the moment, but you can set up your presets to limit the length of the transcoded video. I hope that is sufficient for you.

---
Tags: 7, files
---


title: Video Module Logo Question

text:
# Question
Title: Video Module Logo Question
I have a question about configuring a player in the video module.

In the theme there's a video-play-html5.tpl template, which formats the JW Player.

The question is this--I've used the coding below, along with the pathauto module to change site logos based on content type:

```
    <?php
    // Return a file based on the URL alias, else return a default file
    function unique_section_header() {
      $path = drupal_get_path_alias($_GET['q']);
      list($sections, ) = explode('/', $path, 2);
      $section = safe_string($sections);
      $filepath = path_to_theme() . '/images/sections/header-' . $section .'.png';
      if (file_exists($filepath)) {
        $output = $filepath;
     }
      else {
        $output = path_to_theme() . '/images/sections/header-default.png';
     }
      return $output;
    }

    //Make a string safe
    function safe_string($string) {
      $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
      return $string;
    }
    ?>

```

The question is, can something similar be done to change the watermark in the JW Player based on video content type in the html5 player template? (This is assuming that the function even goes in the template; I'm still learning my way around drupal.)

# Answer
video-play-html5.tpl is primarily for the HTML5 player. Are you using JW Player with this template? I think you should use the JW Player module to use JW Player. Using preprocess functions you may be able to change the overlay path.
> 0 votes

---
Tags: 7, theming, files
---


# Question
Title: generate or extract a automatic thumbnail for a video file using Video module in drupal 7
I need to show a video thumbnail of a video file which the admin upload using the video module.

I have a content type called MEDIA.I have created field as with following settings.

```
   LABEL             NAME           FIELD   WIDGET           OPERATIONS

   Upload Videos    field_video Video   Video Upload    edit    delete

```

Here The following setting I have set for the Upload videos label

```
         UPLOAD VIDEOS FIELD SETTINGS

```

These settings apply to the Upload Videos field everywhere it is used.

```
    Number of values: 1

   Upload destination
   Public files:checked

Enable auto video conversion:checked
 Convert videos automatically using FFmpeg or Zencoder. You can define presets at preset        settings to automatically convert videos to web compatible formats eg. FLV, MP4. Make sure   to configure your transcoder settings to make this work properly.
Video thumbnails
Automatically extract thumbnails from video (with fallback to manual upload):checked

  If you choose Automatically extract thumbnails from video then please make sure to      configure your transcoder settings to make this work properly.

```

Here I have checked the Automatically extract thumbnails from video check box and I have saved it.

I have configure the transcoder setting as follows.(I am working on windows XP)

```
  Video transcoder
    FFmpeg:checked
  Select a video transcoder will help you convert videos and generate thumbnails.

    Zencoder is unavailable: The Zencoder API module has not been setup properly.
   PATH TO FFMPEG EXECUTABLE
    FFMPEG:C:/xampp/htdocs/newsite/ffmpeg/bin/ffmpeg

   Absolute path to FFmpeg executable.When you install a new FFmpeg version, please clear the caches to let Drupal detect the updated codec support.
   VIDEO THUMBNAILS
    Path to save thumbnails:videos/thumbnails

    Path to save video thumbnails extracted from videos.
    Number of thumbnails:5

    Number of thumbnails to extract from video.
    Save all thumbnails in {file_managed} table
    Save all auto-created thumbnails to the {file_managed} table. Change file status as PERMANENT

```

Then I created a new media article where i upload the video from my system and But what happens the video thumbnail is not extracting from the video which I upload.

Can anyone help me.Please forgive me for my english

# Answer
Are there any messages in your Drupal error log related to video transcoding? Also, try to update to the latest version of the Video module.
> -1 votes

---
Tags: nodes, files
---


title: Video transcoding with ffmpeg

text:
# Question
Title: Video transcoding with ffmpeg
I have installed the latest 6.x-5.0 version the video module, have ffmpeg configured correctly on my server, but am unable to get the videos to automatically transcode on either cron run or during node submit.

I am attempted to upload a wmv file and have it automatically transcoded. I have manually transcoded the file on the server using this command successfully

!cmd\_path -y -i test.wmv -s 300x200 -r 15 -b 250 -ar 22050 -ab 48 -vf test.flv

I am able to see the thumbnails being generated when uploading the file, but nothing in the logs or anywhere else suggests that the module is even attempting to transcode the videos. Am I somehow missing a needed module or did I misconfigure the module in some way? When installing the module I was under the impression that it would be able to automatically transcode uploaded videos using FFMPEG.

Any ideas on how I can go about debugging the issue?

# Answer
> 1 votes
I'm also new to ffmpeg/video module, so I may be little help. Yet, I initially forgot to add/enable a Video Preset (sites configuration \> video \> preset). For Drupal 6, I believe it's an include file (.inc) under sites/all/video/video\_preset directory if you wanted to add your own custom settings.

# Answer
> 0 votes
Has transcoding been enabled for your field? The setting is disabled initially due to CCK not allowing default values for field settings.

---
Tags: 6, files
---


# Question
Title: Import Data with Commas into Term Reference Field
I'm having some difficulties to use feeds to import data that with commas.

I have a content type named device, and device has a field named features. features is supposed to be checkbox type which allows users to select multiple options from the provided list like A, B, C, D and the field type is `term reference`

I'm using feeds to map features column from a csv file to the features of device. When I do the import, instead of importing A, B, C, D separately, it created a new option as A, B, C, D altogether.

Is there anyway to separate them?

Thanks

# Answer
Using the Feeds Tamper module, you can explode that field, then use ", " (comma space) as the separator.
> 2 votes

---
Tags: taxonomy-terms, entities, feeds
---


# Question
Title: Change dropdown value depending on URL clicked
Using Drupal 7. From links in an email newsletter, how would it be possible to change the value of a default option value on a webpage? Is there a /?q= that can be used?

email link1 -\> my webpage with option 2 selected

email link2 -\> my webpage with option 3 selected

by default, webpage dropdown has option 1 selected

# Answer
Prepopulate module will take values from the URL and populate a field. This page has an example for D7.
> 1 votes

---
Tags: uri
---


# Question
Title: Node or Taxonomy reference field with "Add new item" on node creation page
I would like to include an "Analyst" Reference field in a content type and allow users to create a new option without needing to leave the Add node page. So it would be a drop-down with an "Add New Analyst" button. So a pop-up or an iframe or something so the user doesn't have to leave the page to add a new option and then start over from scratch.

The "Analyst" could be a separate content type or even taxonomy term with multiple fields.

I would use Select (or other) module, but it doesn't support Node reference or taxonomy with multiple values.

# Answer
> 2 votes
For node reference fields, I use References Dialog to include a link for adding the referenced node. Looks like they are working on taxonomy references.

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


# Question
Title: Drupal 7 default core search functionality
I am using drupal 7, i am in need of showing the default search functionlity, which shows the searched term content type and how many times the searched keyword occurred in the content type.

The entered keyword will be searched with site wide search and the results will show what are the content type nodes having the keyword and how many times the keyword occurred for the content type. Please help me to solve this problem.

# Answer
display suite offers counts and highlighting, plus you can edit the search-result-display via UI. to get the contenttype there, you'll need to add a custom field, or install search api and use views.
> 1 votes

# Answer
To me, this sounds like you want to facet on the content type. The Faceted Navigation for Search module allows you to do this.

After enabling the module, visit *admin/config/search/settings*, uncheck the "Node" checbox under "ACTIVE SEARCH MODULES" and check the "Faceted Navigation for Search" checkbox.

Then visit *admin/config/search/settings/facets* and enable the "Content type" facet. Once the facet is enabled, visit the core Block administration page at *admin/structure/block* and position the "Facet API: Search : Content type" appropriately.

Now you can execute a search, and you will get the following results:
> 0 votes

---
Tags: search, nodes
---


title: Dynamic Select box

text:
# Question
Title: Dynamic Select box
Maybe there is a better way to do this. What I'm trying to do is generate on the the fly a Select box for a form based off of a SQL query.

Right now the code below works, however a few oddities. The default value specified below does not show up. I'm wondering does this have to be a valid result returned? Also my drop down shows the SQL results, however the foreach loop seems to go an extra iteration which causes a stray value of 2 to return to the list. Is there a way to stop that. And of course if I'm going about the structuring of this all wrong please let me know.

Thanks

```
$sqlplatform = "SELECT vid, name FROM {taxonomy_vocabulary} WHERE vid >= 4";
$i = 0;
$result = db_query($sqlplatform);
foreach ($result as $row){
  $option[] = $row->name;
  $i++;
}
$form['multiple_dev']['platform'] = array(
'#type' => 'select',
'#title' => t('Select a Platform'),
'#options' => array(
  $i => t($option),
),
'#default_value' => 'Platform Type',
);

```

# Answer
> 1 votes
Each item in your options array needs to be keyed by something; the default value will then come from that. At the moment you're not adding the options array to the element in quite the right way which is probably why you're seeing some strange results.

Your code should probably look more like this:

```
$result = db_query($sqlplatform);
$options = array();
foreach ($result as $row) {
  $options[$row->vid] = t($row->name);
}

$form['multiple_dev']['platform'] = array(
  '#type' => 'select',
  '#title' => t('Select a Platform'),
  '#options' => array(0 => t('Platform Type')) + $options,
  '#default_value' => 0
);

```

I've made the assumption that you're trying to get an option into the top of the select list entitled 'Select a Platform', and that you want that item to be selected by default.

I think that might be where the confusion is; the default value should be the key of the option you want selected when the select list is first displayed, it's not used to add an extra option to the list.

---
Tags: forms, database
---


title: How to group this view?

text:
# Question
Title: How to group this view?
I have a view that pulls data from the Speaker content type, as well as from related sessions (Session content type contains an entity reference to the Speaker, so to get that "reverse lookup" I'm using the "A bridge to the Content entity that is referencing Content via field\_speaker" relationship type to get the Content: Title from the session nodes.)

This all works, but I can't get the view to display the way I want when a speaker has more than one session. I've tried grouping by speaker name (Content: Title on the speaker node) and get this:

What I want is this:

Here's the basic view setup:

Can this be done just in the Views UI, or do I need to start fiddling with templates?

# Answer
> 0 votes
Not sure but try grouping with all the fields that are common between this 2 like the job title should also be in group so that it will be display only once

---
Tags: 7, views
---


title: Should Drupal 6 be considered insecure?

text:
# Question
Title: Should Drupal 6 be considered insecure?
After reading the post about linkedin on IT security and this issue I would think that having a default Drupal 6 installation without, for example, the phpass module should be considered quite insecure, since the passwords are stored in a way which doesn't require much force to guess and check.

Should I run and install phpass on every Drupal 6 site?

# Answer
***Yes!***

You should consider Drupal 6 without phpass to be unnecessarily insecure. And yes, you should use phpass on all your D6 apps. There are reasons they've changed the way things work in Drupal 7, and made the same changes available as a module to D6 users.

There is no silver bullet, but there's no reason to ignore an easy-to-use module that will significantly increase your level of security.

Not using it is a little like not wearing a seat belt: of course you want to avoid ever being in an accident to begin with (analogous to ever letting anyone gain access to your data), but once you have an accident it's far too late to try buckling up. Buckle up now!

***Update:*** A security expert seems to agree with me:

> ...take the view that attackers **will** ultimately get into your network, access your data... you should be looking at the problem differently.
> 5 votes

# Answer
Security happens at many different points in the system. As far as I'm concerned if a hacker already has full database access it is game over.

To help protect your user's privacy I would do everything you can at the server level to prevent that from happening.

Another step you can take is sanitizing the user data you don't need when moving around development databases. If you are not using the password hashes in development leave them on the production server where they are secure and less likely to be misplaced.

That being said adding phpass definitely doesn't hurt. My philosophy on security is to cover as meany weaknesses as possible without driving yourself crazy chasing edge cases and it seems easy enough to add to the mix.
> 2 votes

---
Tags: 6, security, authentication-authorization
---


# Question
Title: Don't show Header view after clicking next on pager
I'm -very- close to finishing my first drupal site, I've got just one or two more hurdles to overcome and I'm hoping you can help me.

On my /news page (showing Articles), at the top I want to show the 4 most recent Articles as teasers. Below that, I want to show a grid of next 12 most recent Articles. Below that I want to include a pager to allow them to see older Articles.

Using Views and Page Manager I've created a page that gets me very close.

I have a View for "Most Recent Articles" which shows the 4 most recent teasers.

I have a View for "More Articles" which shows a grid of fields of 12 Articles with an offset of 4 so that it doesn't include the 4 most recent.

In Page Manager I created a page that includes the Most Recent Articles View and then includes the More Articles View. This works very well and gives me exactly what I want.

My Problem: When I click the "next" link in the pager at the bottom of the More Articles view, I don't want to show the Most Recent Articles anymore. I'd either like to hide that View on subsequent pages or I'd like to selective only include it on the 1st page (two different approaches to the same idea).

Help?

# Answer
I have an idea:

Create a third view that's a page showing articles with an offset of 16 (so it skips the 4 and the 12). Call it 'older articles'.

Then instead of a pager, have a 'more' link under your view of 12. It's important, in the 'Advanced' section of the view, to set the more link to go to that new views page (older articles). The older articles page can then have its own pager!!! But the initial articles page -- the landing page -- can just have a 'view more' link so it can hop over to the older views altogether.

Would that be sufficient?
> 1 votes

---
Tags: 7, views
---


title: How can I alter a module's JavaScript?

text:
# Question
Title: How can I alter a module's JavaScript?
I need to alter the "Webform AJAX" module's JavaScript code. Is this possible without hacking the module, and risking losing it all upon module updates?

# Answer
> 19 votes
You can use hook\_js\_alter() in a module. For example, this code replaces the jQuery library used by Drupal with the file present in the jquery\_update directory.

```
function jquery_update_js_alter(&$javascript) {
  // Swap out jQuery to use an updated version of the library.
  $javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js';
}

```

The same can be done for inline JavaScript code. The differences are:

* Instead of `'misc/jquery.js'`, the first index is a number
* `$javascript[$index]['data']` will contain the JavaScript code

This means that first you have to find the entry for the JavaScript code to replace, and then alter it. The following code should work in this case.

```
function mymodule_js_alter(&$javascript) {
  $old_code = 'The code to alter';
  $new_code = 'The new code';

  foreach ($javascript as $index => $info) {
    if (is_numeric($index) && $info['data'] == $old_code) {
      $javascript[$index]['data'] = $new_code;
      break;
    }
  }
}

```

As alternative, if you need to alter the library implemented by a module, you can implement hook\_library\_alter(). For example, this is the code implemented by the latest version of the jQuery Update module.

```
function jquery_update_library_alter(&$javascript, $module) {

  // We are updating just the system module. For all other cases we return.
  if ($module != 'system') {
    return;
  }

  $path = drupal_get_path('module', 'jquery_update');

  // Make sure we inject either the minified or uncompressed version as desired.
  $min = variable_get('jquery_update_compression_type', 'min') == 'none' ? '' : '.min';
  $cdn = variable_get('jquery_update_jquery_cdn', 'none');

  // Replace jQuery with the latest version.
  $version = variable_get('jquery_update_jquery_version', '1.5');
  jquery_update_jquery_replace($javascript, $cdn, $path, $min, $version);

  // Replace jQuery UI with CDN or local files. If from a CDN include all of jQuery UI.
  jquery_update_jqueryui_replace($javascript, $cdn, $path, $min);

  // Replace the jQuery Cookie plugin.
  $javascript['cookie']['js']['misc/jquery.cookie.js']['data'] = $path . '/replace/ui/external/jquery.cookie.js';
  // Noting the version based on git commit as no version number is available.
  $javascript['cookie']['version'] = '67fb34f6a866c40d0570';

  // Replace jQuery Form plugin.
  $javascript['jquery.form']['js']['misc/jquery.form.js']['data'] = $path . '/replace/misc/jquery.form' . $min . '.js';
  $javascript['jquery.form']['version'] = '2.69';

  // Replace files for jQuery 1.7 and up
  if (version_compare($version, '1.7', '>=')) {
    $javascript['drupal.states']['js']['misc/states.js']['data'] = $path . '/replace/misc/1.7/states.js';
  }
}

```

This is valid also for JavaScript code used by Drupal core, since for those JavaScript files, the System module implements hook\_library(). (See system\_library().)

`hook_js_alter()` can be used for any JavaScript file/code, even for files used by Drupal core. Between `hook_js_alter()` and `hook_library_alter()`, it is preferable to implement the latter, when the JavaScript files are exposed as library.

---
Tags: 7, javascript
---


# Question
Title: How can I add a header and footer field to all drupal generated blocks?
I have a number of blocks that are created by drupal core, modules and views. In views blocks I can add a header or footer using the views UI, but I would also like to do this for other blocks not created by views. e.g. core search block. I would like to add a user configurable header and footer field to every block generated by drupal. This way a user can add arbitrary content above or below block content using the block UI. Doing this for all views blocks would be great as well as I would not have to give the client permissions and train them how to use the views UI to make changes.

EDIT:

Each block needs to have their fields configurable in the UI. I can't have laypersons digging into the tpl files.

Switching to an entity based block replacement such as the BEAN module is not an option. I need to keep the core block architecture and it also must be able to add headers and footers to core and module generated blocks (which are not beans, boxes etc)

# Answer
> 1 votes
You can use `block.tpl.php`

> Default theme implementation to display a block

And add html in the same template file.

---
Tags: 7, blocks
---


# Question
Title: Login and registration form in a single page
> **Possible Duplicate:**
> Print registration and login forms on same page

I found the LoginToboggan module, but it doesn't allow to register and log in from the same page.

What should I do to get registration and login form in the same page?

# Answer
> 1 votes
This has been answered many times here. See this Print registration and login forms on same page

For this You need to create a page for Registration like this

```
page-user-register.tpl.php

```

And print the page contents as usual. in that page you could try render `user_login_block`

Additional resources

1. http://www.trevorsimonton.com/blog/page-usertplphp-profile-php-template-drupal
2. http://api.drupal.org/api/drupal/modules%21user%21user.module/function/user\_login\_block/7

---
Tags: 7, users
---


# Question
Title: Omega & delta: rendering node title in a block
Is it possible to render node fields as blocks with the omega theme and delta module? If I build a complex layout with zones and regions there can be situations where I need just the node title for example to be rendered in a block and then I can place it in the correct region.

# Answer
Display Suite has just this feature available in Extras -\> Other -\> "Region to block." It doesn't work with the default view mode though so you will need to create/use a new view. I used "Full content." Then at the bottom of the Manage Display screen there will be a new vertical tab called "Block Regions." From here you create new regions which will be exposed as blocks. You can move any field into a block with this technique.
> 1 votes

# Answer
Delta Blocks (sub module included with delta) makes that available as a block, as well as things like the author, terms, and post date. Combine with the context module and you can place the blocks in whatever order you like for particular content types.
> 2 votes

# Answer
You could try the CCK Blocks module:

> This module allows you to create blocks from fields of the currently displayed node. It is very handy as a simple way to get fields appearing in a block, instead of in the main content region.
> 1 votes

---
Tags: theming
---


# Question
Title: hierarcical select not apply parent restriction
i want to add a "category" field in my custom content type.category type is "terme refrence" with ***hierarcical select wideget*** . in settings of it i restrict it with set parrent term for it

but in my form not resriction happend !!!

but in ***$form\['field\_category'\]\['und'\]\['#config'\]*** have this

what is the problem and what is the correct way to restrict HS to pick up only sub term of optional term?(i have a vocabulary with a lot of term,i don't want split it to some vocaublary)

# Answer
> 1 votes
eventually i found this is a bug in hierarcical select module, and the patch in here

i hope this be useful.

---
Tags: taxonomy-terms
---


# Question
Title: How can I restrict Hierarchical Select to specific terms?
I have the below vocabulary in Drupal 7

> tags
> -location
> --uk
> ---londin
> ---manchester
> ---liverpol
> --france
> ---paris
> --germany
> ---kolhn
> ---munich
> -skills
> --sport
> ---football
> ---pingpong
> ---tenis

I want have a hierarchical select that only uses my selected term and subterms of it. For example - if I want location, the user only has first level sub term of location in the list, and in level 2 have the subterms of location.

Is there any way I can accomplish this?

# Answer
this is a bug in hierarcical select module,and with spend some our about it finally found the solution. correct patch is here this issue in drupal

it's is worked for me.
> 0 votes

# Answer
You should create separate vocabularies. That's the clean & easy solution. Note that you can move terms from one vocabulary to another so migrating it is not even *that* big an obstacle.

If you really want all terms to be in one big, semantically incorrect vocabulary, then you can. But you'll have to write your own HS API implementation (see the `API.txt` file in the Hierarchical Select module). Start from the `hs_taxonomy` implementation in D7, look at the `hs_content_taxonomy` implementation for D6 to see how it was done there (that implementation *did* support what you need).
> 4 votes

---
Tags: taxonomy-terms
---


title: Résumé upload functionality in Drupal 7

text:
# Question
Title: Résumé upload functionality in Drupal 7
Is there any module available in Drupal 7 for getting a résumé uploading functionality? I need a form with a couple of text fields and a file upload field that accepts files of .doc, .odt, and .docx formats. My requirement is to send an email also with the attachments, and also see the list of submitted résumés.

# Answer
Add a *Résumé* content type. Add your text fields and a file field to this content type. Set your permissions accordingly, allowing whichever user roles you want (or anonymous) to create this content.

This will allow people to upload their resumes.

Get the Rules module and create a rule a bit like follows

**Events**

*Node* \- After saving new content

**Conditions**

*Node* \- Content is of type: Résumé

**Actions**

*System* \- Send mail

You can use Token to put content fields into the email, but I'm not sure if you can put links to the file. If not, you can at least put a link to the content that contains the file.

Lastly...use Views and create a simple view that shows *Résumé* content -From here, get sorted however you want.

For extra points, you could also use the Flag module to flag résumés (e.g. follow up, spam, not useful and so forth), and then create more views based on those flags (so you can only see useful résumés for exampleetc).
> 2 votes

# Answer
thats baked into d7 core already. just add a filefield and specify the file types.
> -2 votes

---
Tags: 7
---


title: Custom module to validate fields

text:
# Question
Title: Custom module to validate fields
I am trying to create a custom module using webforms drupal 7 to carry out some form of validation. All i want the module to do to check if a value of one field (A) is entered then the other field (B) should be zero and if the value of field (B) is entered then the value of field (A) is zero. Anybody able to help? I am a newbee to drupal.

# Answer
> 1 votes
Webform Validation to the rescue!

> This module adds an extra tab to each webform node, allowing you to specify validation rules for your webform components. You can create one or more of the predefined validation rules, and select which webform component(s) should be validated against those.

---
Tags: 7, forms
---


# Question
Title: I want to change the layout of add/edit page
I have one content type called *Restaurant*, and I want to change the layout of this content type in the administrative area. When the administrator user adds/edits a Restaurant node, the layout should be my custom layout.

How can I change the whole layout?

# Answer
> 2 votes
As shown in the comment at the beginning of theme\_get\_suggestions(), for a URL such as http://www.example.com/node/1/edit, the following default suggestions will be used.

* `page__node`
* `page__node__%`
* `page__node__1`
* `page__node__edit`

If you want to add `page__node__edit__article` as suggestion, you need to implement hook\_preprocess\_page() in a module. The following code works for any content type.

```
function mymodule_preprocess_page(&$variables) {
  if (!empty($variables['node']) && arg(2) == 'edit') {
    // (1)
    array_unshift($variables['theme_hook_suggestions'], 'page__node__edit__' . str_replace(array("/", "\\", "\0", '-'), array('', '', '', '_'), $variables['node']->type));
    // (1)
  }
}

```

If you want to be use not to apply the template file for, e.g., node/1/edit/revert, replace the code between `// (1)` with the following one.

```
$arg3 = arg(3);
if (empty($arg3)) {
  array_unshift($variables['theme_hook_suggestions'], 'page__node__edit__' . str_replace(array("/", "\\", "\0", '-'), array('', '', '', '_'), $variables['node']->type));
}

```

---
Tags: 7, theming
---


# Question
Title: Do not let Drupal handle 404's on development environment
Drupal handles 404 error pages, but on localhost that can be very annoying, especially if you have missing assets (such as uploaded images). For each image, CSS and such that is not found, a drupal is bootstrapped and ran.

How can one best disable this?

Removing the line `ErrorDocument 404 /index.php` from .htaccess gives no change. Should that work?

Changing it to `ErrorDocument 404 "development not found"` does not work either.

# Answer
Newer versions of Drupal have an addition to `settings.php` so that it doesn't handle the 404 for certain assets:

```
$conf['404_fast_paths_exclude'] = '/\/(?:styles)\//';
$conf['404_fast_paths'] = '/\.(?:txt|png|gif|jpeg|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i';
$conf['404_fast_html'] = '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>';

```

There are comments in the file that explain these new options some more.

You can also edit the .htaccess to disable the `ErrorDocument` and then put some `ErrorCond` directives in to prevent missing files from being punted to `index.php`:

```
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !files/foo/(.*)\.bar$
RewriteRule ^ index.php [L]

```
> 5 votes

---
Tags: 6, .htaccess
---


# Question
Title: How to ignore default roles in drupal roles
I don't want to show the default roles to end user and want to ignore anonymous user and authenticated user. How can I remove these two roles from roles array. Shall I hard code the role names and rid say as in example below?

I have used this code.

```
$ignore = array(1 => 'anonymous user', 2 => 'authenticated user');
$roles = user_roles();
$roles =  array_diff($roles, $ignore);

```

Thanks for your help.

# Answer
If you call user\_roles(TRUE), the function will not return the anonymous user role.

Drupal always sets the role ID for anonymous user role, and the authenticated user role to the value of the constants `DRUPAL_ANONYMOUS_RID`, and `DRUPAL_AUTHENTICATED_RID`.

The following code is executed by user\_install() in Drupal 7, and similar code is executed by system\_install() in Drupal 6.

```
// Built-in roles.
  $rid_anonymous = db_insert('role')
    ->fields(array('name' => 'anonymous user', 'weight' => 0))
    ->execute();
  $rid_authenticated = db_insert('role')
    ->fields(array('name' => 'authenticated user', 'weight' => 1))
    ->execute();

  // Sanity check to ensure the anonymous and authenticated role IDs are the
  // same as the drupal defined constants. In certain situations, this will
  // not be true.
  if ($rid_anonymous != DRUPAL_ANONYMOUS_RID) {
    db_update('role')
      ->fields(array('rid' => DRUPAL_ANONYMOUS_RID))
      ->condition('rid', $rid_anonymous)
      ->execute();
  }
  if ($rid_authenticated != DRUPAL_AUTHENTICATED_RID) {
    db_update('role')
      ->fields(array('rid' => DRUPAL_AUTHENTICATED_RID))
      ->condition('rid', $rid_authenticated)
      ->execute();
  }

```

The following code works also in Drupal 5; the `$roles` array will not contain information about the anonymous user, and the authenticated user roles.

```
$roles = user_roles(TRUE);
unset($roles[DRUPAL_AUTHENTICATED_RID]);

```
> 2 votes

---
Tags: users
---


# Question
Title: How to use different fields for different content types in a view
I want to construct a view which will include nodes from several content types.

For each different content type, I want to display different fields (say an image for a type, a video for another, some different text for others)

Let me show you the example I want to achieve:

row 1 is "image", row 2 is "video", row 3 is "event" content type. So,

1. John shared a new image: IMAGE
2. Jane is watching a video now: VIDEO
3. Jack is thinking "this day is sunny".

# Answer
Have you tried anything so far?

Try creating your view and select unformatted list as your style. Add your fields as you would normally. Under format, select settings and make sure that "Hide empty fields" is clicked.

If you fetch lets say the first five nodes from content types Images, Videos, Statuses then each row of the view should look like this:

```
==row 1==
John shared a new image: IMAGE
John is watching a video now: VIDEO
John is thinking "this day is sunny".

==row 2==
Jane shared a new image: IMAGE
Jane is watching a video now: VIDEO
Jane is thinking "this day is sunny".

==row 3==
...

```

but if row 1 is a result from the Video content type then the fields image and status should be empty and will be hidden since you clicked that format option before. Try it and see if it works for you.
> 1 votes

# Answer
So far, the best option is to use a special patch to Views. The patch is located on: http://drupal.org/node/357082

This patch makes the filters take values from contextual filters.

So, for my case, I created several custom contextual filters. Then I got these returned values in different filters. Once they are filters, I was able to AND/OR them.
> 0 votes

---
Tags: views, entities, nodes
---


# Question
Title: How can I use user fields in panels title
This seems to be basic but I cannot get my head around it and I am rather stuck. I am trying to have a panel override in D7 on the user profile page and access a few fields that I have defined in a user profile type (first name and surname in profile2)

I have added a context of the profile type in the panel and set the title to use the content pane title. I add the profile field, how can I set this field to be the panel title?

Any help welcome please.

# Answer
> 0 votes
Click on the gear icon on the grey bar for your field you have added, and click set as panel title.

---
Tags: 7, panels
---


title: Rewrite link on other field in Views

text:
# Question
Title: Rewrite link on other field in Views
I'm using Drupal 7 and Clean theme. My main module is Views. And created 2 field in a content type and listed via Views on page.

I want, rewrite a field link on a other field.

e.g. My Field:

Head: Content Head Link: www.site.com

When click content head go to www.site.com

How can i do this?

# Answer
> 2 votes
Say you have two fields, title and link, in your view. Click the title field and exclude from display so it doesn't show. Then click the link field and rewrite results. Under rewrite results I think you can check BOTH "Rewrite the output of this field" and "Output this field as a link". In rewrite results text box, put in the replacement pattern \[title\] and in link path \[link\] (you can get a full list of replacement patterns below).

If that doesn't work just do a simple href in the rewrite results text box:

```
<a href="[link]">[title]</a>

```

---
Tags: 7, views, entities, uri
---


# Question
Title: How do I display information about a node's author on the full node and not the teaser view?
I have added the following to my node.tpl

```
<?php if ($display_submitted): ?>
 <?php print $user_picture; ?><?php print $name; ?>
<?php endif; ?>

```

This displays the authors info on the node itself, but also the teaser. How do I change the code to remove it from the teaser, but still keep it on the node?

# Answer
Just pop an `if ($page):` condition around it:

```
<?php if ($page): ?>

  <?php if ($display_submitted): ?>
    <?php print $user_picture; ?><?php print $name; ?>
  <?php endif; ?>

<?php endif;?>

```

In the context of node.tpl.php `$page` is defined on the docs page as a:

> Flag for the full page state.
> 0 votes

---
Tags: 7, theming
---


# Question
Title: How do I conditionally change the print.css stylesheet to use media = all
I added this to my template.php, but it doesn't appear to be working. I've also placed this code in theme\_preprocess\_html(),

```
<?php
  function theme_process_html(&$variables) {
    if ($_GET['print'] == 'true'){
      $variables['css']['sites/all/themes/mytheme/css/print.css']['media'] = 'all';
    }
  }
?>

```

# Answer
> 0 votes
I ended up using hook\_css\_alter(&$css)

```
<?php
  function MYMODULE_css_alter(&$css) {
    if (isset($_GET['print']) && $_GET['print'] == 'true') {
      $css[path_to_theme().'/css/print.css']['media'] = 'all';
    }
  }
?>

```

---
Tags: 7, theming
---


# Question
Title: Body Class, Drupal 7, change language name programmatically
I am trying to add a the language being displayed in the html body class. Drupal 7 for example, when i open firebug it displays the body class with these values

body class=html not-front logged-in no-sidebars page-node page-node- page-node-187 node-type-page toolbar toolbar-drawer i18n-el show-grid no-rgba

Is it possibe to add the language as lang-el instead of il8n-el? Which file is it responsible for outputting these values?

# Answer
> 1 votes
```
sites/all/modules/i18n/i18n.module

Line:267:  $variables['classes_array'][] = 'i18n-' . $language->language;

```

You can create your own small module mysmallmodule.module and put this in it:

```
/**
 * Implements hook_preprocess_html().
 */
function mysmallmodule_preprocess_html(&$variables) {
  global $language;
  $variables['classes_array'][] = 'lang-' . $language->language;
}

```

Which wont get rid of the i18n class but will just add your own version :)

EDIT: Step by step to create a small custom module.

1. Create a new folder in the sites/all/modules folder called custom, in here you can keep any custom modules you may need.
2. Create another folder in the custom folder and call it something suitable like customclasses.
3. In the customclasses folder create two files, customclasses.module and customclasses.info.
4. In the customclasses.module file paste the code above but call it "function customclasses\_preprocess\_html" instead of "mysmallmodule".
5. In the customclasses.info file paste

name = Custom Classes

package = Custom Stuff

description = Custom class to get "lang-" in the body class.

core = 7.x
6. Finally, go to the modules page and enable your first custom module.

---
Tags: 7
---


# Question
Title: Check if administration toolbar is visible
How can I check in a theme-file.tpl.php if the administration toolbar is visible or not?

The easiest, but not nicest way to check that, if the user has certain user roles. But is there a way to check that, without checking the roles?

# Answer
I think using the user\_access function to see if they have the "access toolbar" permission should work.

Some example code:

```
if (user_access('access toolbar')) {
  // Your logic here.
}

```
> 3 votes

---
Tags: 7, toolbar
---


# Question
Title: URL Alias does not work in Menu-Blocks with i18n (pathauto also installed)
I'm currently facing a problem with Internationalization and the main menu block on my page.

So when I created the page about-anna and navigating to /de/about-anna - it works great also with /node/27 it works. Thats ok.

But the menu-item is instead of /de/about-anna just /node/27

So I continued testing, added the english-translation and setabout-anna as path alias again. But the problem still exists.

I also looked up the internet and Drupal Answers and I found some good answers... but didn't fix my problem...

# Answer
I was still testing and found another bug, that when your browser is in german, you can't switch to english.

---

So in Configuration \> Languages \> Detection and Selection (admin/config/regional/language/configure) I unchecked "Browser" from the list.

Now the menu-block uses path aliases too and you can switch languages on the site.
> 0 votes

---
Tags: 7, routes, i18n-l10n, blocks
---


# Question
Title: Drupal 7 OG Group Unsubscribe after given time period for member
I am new to drupal 7 and was willing to implement something like time based unsubscription from a OG Group.

I have users added in OG Group. I want to implement time based unsubscription of the users already added in the group say 'Computers'.

User say 'Tony' is added to the group 'Computers' today, now I wish that a user 'Tony' should be unsubscribed from the group 'Computers' after a subscription of 3 months (a specific time period).

A Notification message should be sent to user 'Tony'.

All the process should be based on systems current date and the joining date of user 'Tony' to the group 'Computers'.

Please help me with any solution.

# Answer
This is definitely a job for rules. It is also quite a complexed subject as you are going to need to utilise components so that you can schedule this to happen every day. I would do it like this:

1. Set up a views\_bulk\_operations view that looks up all users that have been members of groups for 90 days.
2. Create a rule component that loads the list of users, loops through the list, sends a notification and unsubscribes the user from the group.
3. Schedule the rule to do this every day.
> 1 votes

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


# Question
Title: Avoid adding breadcrumb if title is empty
I created a view without the title but then the breadcrumb shows as

Home\> \>

If I add title to the view then it is showing as

Home\> \>Title

is there any way to avoid adding breadcrumb when empty title is present ?

# Answer
I think you can remove the breadcrumb if you create a template for the view:

views-view--your-view-name--page.tpl.php
> 0 votes

---
Tags: views, 6, breadcrumbs
---


# Question
Title: Devel admin interface unreachable; or I broke my Devel?
Not sure what broke where, been using devel & love it. I enabled the `Display $page array` option, went, did stuff, came back to disable and when trying to load `admin/config/development/devel` either through button, url or asking nicely, I get a

> Error 324 (net::ERR\_EMPTY\_RESPONSE): The server closed the connection without sending any data.

I uninstalled, reinstalled, no change. I uninstalled, deleted variables (shouldn't devel do this?) flushed caches, ran cron, deleted the devel folder, and reinstalled from a fresh download (7.x-1.2), no change. The strange part is devel still works (when module is installed), i'm still getting my $page array in the message area, but I can't admin devel anymore :'(

Unfortunately I'm ramping this site up for production & can't turn back now, might have to proceed w/o it.

Anybody know how to admin devel another way? Run into this before? Have something else I can try?

Update: Just started testing the rest of devel & these functions elicit the same response (324):

* Execute PHP
* Devel settings (either the development menu link `/devel/settings` or the link in the admin toolbar `admin/config/development/devel`)
* Menu item

**Rebuild menus !** Thankfully this still works, because it fixed the problem! So try that if you start getting 324's in weird places!

# Answer
**Rebuild menus ! This fixed the problem!**

One of the menu tables must have been corrupted somewhere in my Drupal shenanigans.

So try that if you start getting 324's (or other non 200 responses) in weird places!
> 0 votes

---
Tags: 7, debugging, http-request
---


# Question
Title: Trying AJAX autocheckboxes example; getting Notice: Undefined index: #ajax in ajax_form_callback()
I'm using the exact code found within the examples module `function ajax_example_autocheckboxes` though I have changed the function and callback names. When I change the select dropdown the field goes gray for a second as the AJAX process kicks off; but no checkboxes appear. I don't think it matters, but my form is in a block defined in my custom module.

I'm getting this in my recent log messages:

```
Type    php
Date    Wednesday, March 21, 2012 - 12:24
User    me
Location    http://localhost.com/system/ajax
Referrer    http://localhost.com/node
Message Notice: Undefined index: #ajax in ajax_form_callback() (line 379 of C:\Users\me\Documents\www\localhost.com\includes\ajax.inc).
Severity    notice
Hostname    127.0.0.1

```

**UPDATE:** I tried the examples module (ajax examples) in a clean D7 install and get 503 errors trying to open the example pages; now I'm investigating my hosting environment (xampp) will update once resolved.

**UPDATE2:** Installed a bitnami drupal stack & tested ajax examples; everything works as expected which points to an issue with my xampp environment.

FYI xampp details:

```
    ###### ApacheFriends XAMPP version 1.7.7 ######

  + Apache 2.2.21
  + MySQL 5.5.16 (Community Server)
  + PHP 5.3.8 (VC9 X86 32bit thread safe) + PEAR
  + XAMPP Control Panel Version 2.5 from www.nat32.com
  + (BETA) XAMPP Control Panel Version 3.0.2 by Steffen Strueber (not in the USB & lite version)
    see http://www.apachefriends.org/f/viewtopic.php?f=16&t=46743
  + XAMPP Security
  + OpenSSL 1.0.0e
  + phpMyAdmin 3.4.5
  + ADOdb 5.14
  + Mercury Mail Transport System v4.62 (not in the USB & lite version)
  + FileZilla FTP Server 0.9.39 (not in the USB & lite version)
  + Webalizer 2.23-04 (not in the USB & lite version)
  + Perl 5.10.1 (not in the USB & lite version)
  + Mod_perl 2.0.4 (not in the USB & lite version)
  + Tomcat 7.0.21 (not in the USB & lite version)

```

# Answer
**Reinstall XAMPP!** if that doesn't fix it, try a different stack:

So installing the Bitnami Drupal stack and testing successfully there indicated a problem with my XAMPP install. Also wanted to try the Acquia stack, was ok, ended up going back to XAMPP.
> 0 votes

---
Tags: ajax
---


# Question
Title: Is this possible? Dynamically changing fieldsets on node creation
(Note that I am not talking about simply hiding/displaying fields conditional upon other fields' values.)

This question about programmatically creating fields led to questions about whether it was even possible to do what I want. See, I want to create a set of webforms that I will use as quizzes. Then I want to create a node of type "answer key" for each quiz. The answer key will be connected to a quiz by a node reference field. Upon selection of a quiz from the dropdown, some AJAX will automagically go to the specified webform, find its form elements, bring them back, and add them to node submission form for the answer key.

The tricky part here is trying to save them. See, since they weren't known to the content type beforehand, they won't have been defined already with a spot in the database and all that. So, how can I store them? Can I define on the content type a text field with unlimited values and just store one form element's answer per value in the unlimited field?

The tl;dr of this is: **Is it possible to save inputs on fieldsets that are different for each node of the same content type?**

# Answer
> 0 votes
You probably could apply some woodoo to save the data :) But : you would have hard times retreiving it. Node displays only the defined fields, Views only show the fields and so on.

I would suggest not using webform, but simply defining those quizes as new node types and save them, together witha reference to a record about the answer (if it is important).

It might be handy to use eck instead and create an entity type and bundles for each quiz - so you dont have to deal with all the settings on node, just the fields.

---
Tags: nodes, forms, database
---