# Question
Title: Get a sortable link in Views table display
I have an content type (bundle) "Journal" that has a field "journal number" (integer field) and an entity reference to "Document" bundle. I have a view that lists"document" objects as a table. I want to add there a number of journal referencing to the "Journal" item. It can be done via Relations in Views. But then I want to see this number as a link to corresponding journal. I see two ways there:

.1. that number is shown as a link via "override" option of the field with **hardcoded** url. (I use pathauto with custom patterns which means that I'm to monitor that hardcoded with "override patterns" urls to be correspondent to their actual urls provided by pathauto)

Pros: the field is sortable as an integer (I want it to be that).

Cons: if Pathauto patterns change, the views overide patterns should be changes correspondingly by hand.

.2. Add a field "Link" referencing to that journal and override this field with a journal number field.

Pros: linking system works without any crutches: Pathauto pattern changes -\> link to journal will still work.

Cons: The overriden property is **NOT SORTABLE**

How can i get both beiing a link and sortable ability as a number for a field?

# Answer
> 1 votes
You should use the first option, but with a slight alteration. If you use the base url when you create a link using override - views will render the link using the Drupal APIs and the the link will use any path alias created.

So all you have to do is to create the link like: `node/[nid]`, instead of doing `content/[title]`. *These urls are examples*.

---
Tags: views
---


# Question
Title: How to show a image preview of the files in IMCE file browser?
I'm using the the imce module with the ckeditor module.

When you open the imce file browser to select/upload a image you can see a list of the images you have in your server.

This list shows the name for every image.

Is there a way to make this list to show a image preview of the image (a thumbnail)?

Look my capture:

# Answer
> 0 votes
I have seen it work sometimes, but I can not tell does not always work. I will recommend you opening an issue on the IMCE module page in Drupal.org. See it working on the image below:

---
Tags: wysiwyg, files
---


# Question
Title: Using hook_menu() and hook_permission() to control access
How does one limit "what" can access a page. I understand how to use `hook_permission()` to set user permission based on a role to control access to `hook_menu()` items. However, what if I have a `hook_menu()` item that is to be used solely by the system itself? For example, say I have a registration page in a custom module: `module/register` \- Anyone can access that page. Then, say I have an ajax call that is to be made when the user performs some action on the page. So, I register another item in `hook_menu()`, call it `module/register/ajax` \- I do not want anyone to be able to browse to `module/register/ajax` but I want to be able to do an ajax call to that page. What is the best way to accomplish this?

I have used AJAX callbacks but this is not a case where a form is being submitted. This is just a pure AJAX call from JavaScript on an event after the page loads.

# Answer
Quick and dirty, you could do something like this:

```
function YOURMODULE_menu() {

  $items=array();

  $items['YOURMODULE/register/ajax'] = array(
    'page callback' => 'YOURMODULE_register_ajax',
    'access callback' => 'YOURMODULE_access_ajax',
    'type' => MENU_CALLBACK,
  );

  // other $items here...

}

```

and then define you own access function for ajax like this:

```
function YOURMODULE_access_ajax() {

  if (user_is_logged_in() && $_SERVER['REQUEST_METHOD']=='POST') {
    return TRUE;
  } else {
    return FALSE;
  }

}

```

which will grant access to the path only if the user is logged in and is using POST to access it. The key here is when you surf around, you are using GET, but when using AJAX, most of the time at least, you are using POST. Now, if you wanted to get more fancy other than just if the user is logged in, you could do more with `user_access()` in there instead of the simple `user_is_logged_in()`.

IF however, you are using GET for your AJAX, you can in your page callback check the parameters and if they don't validate, `return MENU_NOT_FOUND;` or `return MENU_ACCESS_DENIED;` instead of the `drupal_json()` stuff.
> 3 votes

---
Tags: hooks, ajax
---


title: Why are my AJAX forms submitted twice?

text:
# Question
Title: Why are my AJAX forms submitted twice?
I've been looking up and down for hours now trying to figure out what I am doing wrong.

Every time I submit a form via AJAX, the submit function gets invoked twice. In other words, the form gets submitted twice. Here is an example I have been working with in my attempt to boil everything down to the basics in hope of finding the root of this very annoying issue (the example assumes AJAX requests, and is not really geared towards graceful degradation).

*This is not an issue with multiple AJAX requests being sent from the browser. The browser only sends one single request when i click on the form's 'submit' button.*

```
/**
 * Page callback for 'welcome'. This path has been registered
 * as a plain MENU_CALLBACK.
 */
function us_welcome() {

  // This is where the user arrives at first when navigating to
  // 'welcome'. The user is simply presented with a link which
  // will load the registration for via AJAX and show that form
  // on the very same page.

  $html[] = l(t('Register'), 'welcome/register/nojs', array(
    'attributes' => array(
      'class' => array(
        'use-ajax'
      ),
    ),
  ));

  $html[] = '<div id="form-register-wrapper"></div>';

  return implode($html);

}

/**
 * Page callback for 'welcome/register'. This path has been registered
 * as a plain MENU_CALLBACK.
 */
function us_register($mode = 'nojs') {

  // This callback is responsible for the path 'welcome/register'
  // and is the one which the link invokes. If invokation happens
  // from the link, then $mode is 'ajax'. Otherwise, it is 'nojs'.

  // Get form.
  $form = drupal_get_form('us_register_form');

  if ($mode != 'ajax') {
    return $form;
  }

  // Generate commands array.
  $commands = array(
    ajax_command_replace('#form-register-wrapper', drupal_render($form)),
  );

  $page = array('#type' => 'ajax', '#commands' => $commands);
  ajax_deliver($page);

}

function us_register_form($form, &$form_state) {

  // A plain old form builder function. Nothing magical
  // going on here.

  $form['#prefix'] = '<div id="form-register-wrapper">';
  $form['#suffix'] = '</div>';
  $form['#action'] = '/welcome/register/nojs';

  $form['messages'] = array(
    '#markup' => '<div id="form-messages"></div>',
  );

  $form['basic'] = array(
    '#type' => 'fieldset',
    '#title' => t('Basic Details'),
  );

  $form['basic']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Your Name'),
  );

  $form['basic']['email'] = array(
    '#type' => 'textfield',
    '#title' => t('Your E-mail'),
    '#required' => TRUE,
  );

  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#ajax' => array(
      'callback' => 'us_register_form_submit',
      'wrapper' => 'form-register-wrapper',
      'effect' => 'fade',
    )
  );

  return $form;

}

function us_register_form_submit($form, &$form_state) {

  // This is the form submit function. The weird thing is that it gets
  // called twice every time the form is submitted via AJAX.

  // This block of code will only apply to AJAX requests. Normal requests will
  // return from the validation function(s) if validation error(s) should occur,
  // and by the time normal requests get to this point everything have been
  // validated. AJAX requests, on the other hand, goes through the validation
  // function(s) but will still reach this point even though validation error(s)
  // occur. Thus, we need to check for errors and return error messages in case
  // of validation errors. In case of errors, return the form again.
  $errors = form_get_errors();
  if (!empty($errors)) {
    return $form;
  }

  // @todo : carry out registration here.

  $content = array();
  $content[] = t('Thank you for registering!');

  // Process form submission.
  $commands = array(
    ajax_command_replace('#form-register-wrapper', implode($content)),
  );
  $page = array('#type' => 'ajax', '#commands' => $commands);
  return $page;
}

```

# Answer
> 11 votes
The problem you are noticing is caused from the fact that `us_register_form_submit()` for Drupal is the form submission handler for the form returned from `us_register_form()` and, at the same time, you set `us_register_form_submit()` as AJAX callback.
That function will be called twice, when AJAX is enabled: first as AJAX callback; then, as form submission handler.

Just change the code as this. (See the `/* changed this */` comment.)

```
  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#ajax' => array(
      'callback' => 'us_register_ajax_callback' /* changed this */,
      'wrapper' => 'form-register-wrapper',
      'effect' => 'fade',
    )
  );

```

AJAX callbacks are not for validating a form, and they will never get called to validate a form, except when you set as AJAX callback a function already used as form validation handler. The purpose of an AJAX callback is reacting when a JavaScript event happens for a form field, and updating the form without returning to the browser a full page.

# Answer
> 1 votes
Based on this post, I believe I found why my forms get submitted twice. It appears that the #ajax\['callback'\] function is both a validation function and a response function. The form's standard submit function will still get invoked, but during AJAX requests, whatever the submit function returns will be ignored as the return values from the callback function will be used instead.

The submit function will not be invoked in form validation fails, and the callback function will be invoked directly after validation functions so that the user can be notified about the failed validation.

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


# Question
Title: How to change link to a node's path in Views conditionally
I have what I'm calling a "student blog" section. Students can create a blog either locally (with a Body field), or remotely using a Link. A single conditional\_fields value of "blog is hosted" controls what is shown on the add\_node\_form.

These blog entries are moderated via Workbench Moderation.

Anyways in Views 3.x I want to make a listing of the blog titles, linked to their content. If the content was "local" I want a link to node/NID or the url alias. If the content was "remote url" I want the url to point to the offsite url for the blog post (eg, Blogger.com).

I have created the content type, and a simple views block that lists the node titles .... but I can't get the link(s) to point to the correct locations per entry.

If possible, please submit answers using Views 3.x Core only (not views\_php, etc) ... this site has a ton of modules already :P

Images of configuration:

**Content Type Fields**

**Initial Blog Creation Screen**

**Blog was Local screen**

**Blog was Remote Url screen**

**Views Block Output of Node Titles (that should link either local or remote**

# Answer
> 3 votes
You could add a blog\_url field which you hide in a form alter and programmatically set when the form is submitted. If the blog is remote, you set it to the value of the link field. If it's local, you set it to the value of the node. You can then use this field in Views (just include the Title field and use 'Link this field' to link it to the value of blog\_url). Something along the lines of:

```
/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'school_blog_node_form') {
    $form['field_blog_url']['#access'] = FALSE;
    $form['#validate'][] = 'mymodule_validate_school_blog_form';
  }
}

/**
 * Validate handler for school_blog edit form.
 */
function mymodule_validate_school_blog_form($form, &$form_state) {
  if ($form_state['values']['field_blog_is_hosted'] == 'local') {
    $form_state['values']['field_blog_url'] = 'node/' . $form['nid'];
  }
  else {
    $form_state['values']['field_blog_url'] = $form_state['values']['field_blog_remote_url'];
  }
}

```

# Answer
> 1 votes
This is the closest I can come up. This will render each row of the view -- and I alter it's output per row.

I could stick this code into a custom block from a module. Oober hacky given I know i'm only showing 1 link per entry.

```
$view = views_get_view('student_blogs');
$view->set_display('block');
$view->set_arguments(array('singapore'));
$view->execute();

$renderer = $view->style_plugin->row_plugin;
foreach ($view->result as $index => $row) {
  $view->row_index = $index;
  $is_remote_blog = ( $row->_field_data['nid']['entity']->field_blog_is_hosted[LANGUAGE_NONE][0]['value'] == 'remote site') ? 0 : 1;
  $remote_url = $row->_field_data['nid']['entity']->field_blog_remote_url[LANGUAGE_NONE][0]['url'];
  $output =  $renderer->render($row);
  if ($is_remote_blog) {
    $output = preg_replace('/(.*<a href=")(.*)(">.*)/i',"$1$remote_url$3", $output);
  }
  echo $output;
}
// Cant use views->preview as we alter what comes back from render().
//$view->preview();

```

---
Tags: views, theming
---


# Question
Title: Unable to Retrieve Custom Taxonomy Fields Using PHP
I have added a custom image field to a Drupal 7 taxonomy called "field\_uc\_catalog\_image2".

I am now attempting to get the path of that field using PHP with this code:

```
$normal_path= drupal_get_normal_path($_GET['q']);
$tid = array_pop(explode('/', $normal_path ));
if ( is_numeric( $tid ) ) {
  $term = taxonomy_term_load($tid);
  print $term->field_uc_catalog_image2['und'][0]['uri'] . '<br/>';
}

```

However, I am getting the following error:

> Notice: Undefined index: und in eval() (line 6 of C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\le\modules\php\php.module(80) : eval()'d code).

Whereas, this similar expression for the standard image works fine:

```
print $term->uc_catalog_image['und'][0]['uri'] . '<br/>';

```

Do you have any suggestion?

# Answer
> 0 votes
Using `print_r($term)` (as per Mohammad's suggest) I could see the correct expression was actually another one.

```
$term->field_image['und'][0]['uri']

```

---
Tags: media, taxonomy-terms
---


# Question
Title: Why does not hook_block_view_MODULE_DELTA_alter work?
I'm implementing a `hook_block_view_MODULE_DELTA_alter` for the user login block.

```
function mymodule_block_view_user_login_alter(&$data, $block) {
    drupal_set_message($block->module);
}

```

According to the **block** table, the module is **user** and delta is **login**.
But, the hook was not invoked and the message was not printed out as expected. I'm using D7.

# Answer
That hook is called right before a specific block is rendered. If the block isn't present in the page, the hook is not invoked. Replace that hook with `hook_block_view_alter()`, and it will get invoked for every block shown in the page.

Bear in mind that Drupal caches the hooks implemented from a module; if you alter the code of an enabled module, Drupal will not know the module has a new hook. Disable the module before editing its code, and re-enable it after editing its code; in that way, Drupal will clear its cache, and notice there is a new hook, using it when necessary.
> 1 votes

---
Tags: hooks, blocks, users
---


# Question
Title: how to display avatar in forum-list (advanced-forum)
Any suggestions? I'm interested in how to display the avatar last post in forum list. I tried to display the avatar as $picture but is not working.

# Answer
> 1 votes
You may include the picture of the author of the forum topic by configuring the corresponding view:

admin/build/views/edit/advanced\_forum\_topic\_list

HTH

---
Tags: views
---


# Question
Title: how to show more information in user's profile
by default user's profile in drupal show very little information about users. I can extend that by adding more fields to profiles. but I want user's profile in such a way that it would be showing all his/her information and some more information like users last 10 posted content, top 10 rated content and most commented content etc.

how can I extend this type of profile view in drupal? please suggest me, thanks in advance :):)

# Answer
> 1 votes
For things like last 10 posted content, I believe you can use contextual filters in Views. With that you can create pages like /user/somebody/posts where Views will show you the last contents of user for example, also I believe you can make a block out of such a view that you can place on profile pages.

Also it may worth for you to check out the Profile2 module, you can create multiple types of profile pages with it for example.

http://drupal.org/project/profile2

---
Tags: users
---


# Question
Title: Change layout of a view 'page display' based on number of grouping field occurences
Sorry about that rather specific title: hopefully my question will clarify itself with the following:

# What data is on the table to work with

I have a View (page display) that lists nodes based on the main categories "Fruit" and "Veggies"
So I have two pages: 1 at www.mysite.com/**fruit** and the other www.mysite.com/**veggies**

* arg(0) is being used as a contextual filter to get the right nodes on both those pages.
* I'm grouping my nodes (grouping field dropdown in Style options) based on the taxonomy term they belong to (eg for "Fruit" \> sweet and sour) to reflect their hierarchical place in the taxonomy structure (see below)

**fruit**
-- sweet(**taxonomy term**)
-- -- banana **node**
-- -- melon **node**
-- sour(**taxonomy term**)
-- -- lemon **node**
**veggies**
-- red (**taxonomy term**)
-- -- paprika **node**
-- -- onion **node**

# What I would like achieve

I would like to be able to add different styling to a page that has only 1 main category (like the **veggies** \- categorypage -\> we only have the "red" subcateg there) as opposed to a page that has 2 or more main categories (like the **fruit** \- categorypage -\> we have 2 subcategs there: "sweet" and "sour")

# What I have uptil now (it's working but I need to clean up my act/code)

As stated ... this already functions , but I would love to know:

* if I followed Drupal protocols.
* if there are better ways (more performant, cleaner code, easier)

**I've got this in my template.php**

```
/* Helper function so I can reach my specific display in the preprocess hook below*/
function <themename>_preprocess_views_view(&$vars) {
  if (isset($vars['view']->name)) {
    $function = __FUNCTION__ . '__' . $vars['view']->name . '__' . $vars['view']->current_display;

    if (function_exists($function)) {
     $function($vars);
    }
  }

// This is where I inject a custom CSS file in the case where I've got only 1 Main category (as explained above)
function <themename>_preprocess_views_view__need__page(&$vars) {
  $tidArr = $vars['view']->field['term_node_tid']->view->field['term_node_tid']->items;
  $terms = array();
  foreach ($tidArr as $key=>$tids) {
    $terms[] =  current(reset($tids));
  }
  $uniqueTids = count(array_unique($terms));
  if($uniqueTids < 2) {
      drupal_add_css(path_to_theme() .'/css/my_custom_css.css');
  }

}

```

*Disclaimer: Heavy question , I know ... but hopefully clear enough so you can all understand what is going on , and what I'm trying to achieve.
Understand that I'm happy I got it working , but I would be even more happy if I could do it the Drupal "way" and have my code as lean and mean as possible.
thanx for taking the time.* }

# Answer
> 0 votes
I ***think*** what you are trying to drupalize/ise this into is something along the lines of:

```
function YOURTHEME_preprocess_views_view(&$vars) {

  $view=$vars['view'];

  if (empty($view)) {
    watchdog('YOURTHEME', 'Rut roh Rastro....');
    return;
  }

  switch ($view->name) {

     case 'need':

        if ($view->current_display=='page') {

          $tid_arr = $view->field['term_node_tid']->view->field['term_node_tid']->items;
          $terms = array_keys($tid_arr);
          $number_tids = count($terms);

          if ($number_tids == 1) {
            drupal_add_css(path_to_theme() . '/css/my_custom_css.css');
          }

        }

        break;

     // any other views here

  }

}

```

with my basic comment being that you switch on the View's name in the preprocess function and do all your work in there instead of going out into another function.

---
Tags: views, theming
---


# Question
Title: How can I print node author's last login date on page.tpl.php?
I could easily find out how to print the current user's last login date but what about the node author's one?

# Answer
> 3 votes
It would be better to put this logic in an preprocess function rather than directly in the template file, but the code would probably be something like this:

```
if ($node = menu_get_object()) {
  $author = user_load($node->uid);
  $last_login = $author->login;
}

```

# Answer
> 2 votes
For `hook_preprocess_page()` you can simply use the following code.

```
function mytheme_preprocess_page(&$variables) {
  if (isset($variables['node']) && ($account = user_load($variables['node']->uid))) {
    $variables['author_last_login'] = $account->login;
  }
}

```

In your page.tpl.php file you can then print `$autor_last_login`, with `format_date($autor_last_login)`, for example.

Bear in mind that `$account->login` is the last time the user has logged in; it is not the last time the user has been seen. For that you need `$account->access`.

---
Tags: 6, nodes, theming
---


# Question
Title: Menu block doesn't appears where I expect it
I have this kind of menu: "Level 1" has menu item "Level 2", which links to the page with "cat1" url. Then, I have node which have aliases "cat1/\[nid\]", hence, in my opinion, menu block (provided by "menu block" module) should appear. But it doesn't. Why?

If you haven't worked with menu block module and not familliar with it, then how can I force to show "Level 1 -\> Level 2" menu part if a node with alias "cat1/\[nid\]" is loaded?

# Answer
> 2 votes
Inspecting the code of the Menu Block module, I understood this module doesn't work with URLs. There are other modules, such as the Context: Menu Block module, which make it possible.

> Context: Menu Block allows the Menu Block module to be aware of contexts provided by the Context module by informing menu blocks of active menu context reactions.

---
Tags: routes, blocks
---


# Question
Title: How to choose between Bean, Boxes and Fieldable Panels Panes?
Bean, Boxes and Fieldable Panels Panes all provide similar functionality. I have trouble understanding what exactly the differences between them are.

What are their advantages/disadvantages compared to each other? Are they geared towards different use cases?

I want to use some kind of blocks in Panels to add custom content - content editors also need to be able to add content, in that sense the blocks I need are not pure configuration. But I also use Features...

Edit: I'll add what seem to be the main differences

**Boxes**

* Largest userbase (~ 11500)
* Treats blocks as configuration (i.e. the content ends up in your features)
* Modules offering integration

**Beans**

* Has recently become popular, ~1000 installs
* Treats blocks as content, but allows exportability of their configuration via machine name (e.g. via Bean Panels)
* Modules offering integration

**Fieldable Panels Panes**

* Smallest userbase (~ 400)
* From the author of Panels/Views/etc.
* Panes cannot be used as regular blocks in theme regions like beans or boxes (I assume)
* I wonder what the advantages over Bean mentioned here are ("offers additional features that makes it easier to empower content admins to lay out certain pages")

# Answer
It's perfectly possible to make a D7 site without blocks if you can live without dashboard. Our new - content driven - site is being built on panels with workbench as a suitable (for us) alternative to dashboard. Arjan appears to already understand this.

On to the alternatives. Read Your site should be full of beans. The problem with boxes is the danger regarding overwriting existing content when using features. But read Fabian Franz's comment in the same article. Beans has many options. I'm not comfortable regarding management, scalability and performance. Hardcore developers that are fluent with panels use Fieldable Panels Panes. Fieldable Panels Panes lack documentation and examples. What should get everyones focus and effort for D8 is the wscci-initiative. It allows for REST-calls, including for example DELETE. This could permanently tackle the problem of overwriting site builder configuration on code rollouts.
> 4 votes

# Answer
for your purpose may be optimal to use views with some taxonomy: to one content type add terms for the place of panel, for that place make views block with filter this term and content type, then add this views-block on the place in panel, usually I make additional field for weight for this content type and in views I sort by weight, and editors never needed edit the panel to add/edit/remove content on this place - the views block select propper content for the place by term
> 1 votes

# Answer
Check out the nodeblock module. Being nodes they don't export via Features, but you might find it does what you need.
> 0 votes

---
Tags: panels, features, blocks
---


# Question
Title: How do I display the latest post related to another?
I'm on d7. I have 12 nodes that I use as groups with the entity relations module. When a user submits a post, they choose one of the groups to put it into. I want to make a views list of all 12 groups that displays the title of the latest post that has been submitted into each of them. Any suggestions? Thanks.

# Answer
> 0 votes
I ended up using the views field view to get the job done.

---
Tags: 7, views
---


# Question
Title: Customising Search Box in Search Results Adding OnBlur and OnFocus Attributes
I am trying to add custom #attributes to the search\_form in the search results page. I get the $form\_id from devel which is `$form_id = "search_form"`.

Here is my `hook_form_alter()` implementation:

```
function nm_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'search_form' ){
    $form['search-form']['#attributes']['onblur'] = "if (this.value == '') {this.value = '".$form['search-form']['#value']."';}";
    $form['search-form']['#attributes']['onfocus'] = "if (this.value == '".$form['search-form']['#value']."') {this.value = '';}";
  }
}

```

I checked if the condition is right inside the if statement with the following code, but nothing happened.

```
dpm($form['search-form'])

```

So, I am suspecting that the `if condition` is right.

# Answer
If you want to add attributes to the form itself you need to do it on the `$form` array:

```
$form['#attributes']['onblur'] = "if (this.value == '') {this.value = '".$form['search-form']['#value']."';}";

```

I'm just guessing but I think you're expecting there to be a `search-form` element because that's the CSS ID of the form? That's not quite how it works with the FAPI, the elements are in a hierarchy that will eventually be rendered down to HTML. Until that rendering happens the elements have no concept of an ID/class etc., so you won't find them in the array under the ID/class.
> 1 votes

# Answer
The search form contains the following form elements.

```
  $form['module'] = array(
    '#type' => 'value',
    '#value' => $module,
  );
  $form['basic'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('container-inline')),
  );
  $form['basic']['keys'] = array(
    '#type' => 'textfield',
    '#title' => $prompt,
    '#default_value' => $keys,
    '#size' => $prompt ? 40 : 20,
    '#maxlength' => 255,
  );
  // processed_keys is used to coordinate keyword passing between other forms
  // that hook into the basic search form.
  $form['basic']['processed_keys'] = array(
    '#type' => 'value',
    '#value' => '',
  );
  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );

```

There isn't any `$form['search-form']`.

If you want to add attributes to the form you need to add them to `$form['#attributes']`, as with the following code.

```
$form['#attributes']['class'][] = 'search-form';

```

If you want to add attributes to the textfield, then you should use `$form['basic']['keys']['#attributes']`.

Keep in mind that the attributes you add there are added to the search form, not to the page showing the search results. The page showing the search results is output from search\_view().
> 1 votes

# Answer
**Solution:**

What I was trying to do was adding the onblur and onfocus attributes and here how I did it: You can insert the following to your template.php

```
function {ThemeName}_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'search_form' ){
    $form['basic']['keys']['#attributes']['onblur'] = "if (this.value == '') {this.value = '".$form['basic']['keys']['#default_value']."';}";
    $form['basic']['keys']['#attributes']['onfocus'] = "if (this.value == '".$form['basic']['keys']['#default_value']."') {this.value = '';}";
  }
}

```

*Thanks for all who helped.*
> 0 votes

---
Tags: forms
---


# Question
Title: Change title head of the pages in Drupal 7 by path
I need to change the title head of the pages in Drupal 7 by path. NOt to all content type. I need to change the title head to a specific page generated with views.

For example, I have a site http://www.mysite.com

```
<title>My favorite website </title>

```

I need the for pages:

http://www.mysite.com/test

```
<title> My test today </title>

```

http://www.mysite.com/examples

```
<title> My examples for share </title>

```

Thanks.

# Answer
> 11 votes
Here is how I did it in Drupal 7.

In template.php:

```
function YOUR_THEME_preprocess_page(&$vars){
  $path = $_GET['q'];

  if (strpos($path,'YOUR_PATH_STRING') !== false) {
    drupal_set_title('YOUR_TITLE');
  }
}

```

For example, if your path was yoursite.com/boogabooga, then you would set `'YOUR_PATH_STRING'` to 'boogabooga' and `'YOUR_TITLE'` to whatever you want the page title to be.

# Answer
> 14 votes
It sounds for your limited set of pages maybe implement `THEME_preprocess_html()` and examine the url path and override `$vars['head_title']`. See this blog post as an example: How to set custom page title in Drupal 7

If you have some patterns for the head title try Page Title

---
Tags: 7
---


# Question
Title: Contact form block with data from the page the blocks featured on
So I have a content type "Real Estate." On the view for a "Real Estate" node, I want to have a contact block in the right side bar that has a feild for the node id of this specific "Real Estate" node.

An example of the feature I'm trying to make can be seen here

This problem has two parts which I'm not sure how to do. The first is that I don't know how to make a block for a contact form. I know drupal has a default Contact module but I'm not sure how to turn this into a block or even if that is the best way to go (maybe WebForms module can help?) Second is that I'm not sure how to pre-load the node id into the form. I'm sure that this would require a hook of some kind but seeing as I don't know how to make the contact form block, I don't know what hook to use.

Any help would be much appreciated. Thanks!

# Answer
If you don't want to write custom theming and you want less coding, you need to create a custom page with 2 columns using panels module.

1. Install the panels and ctools modules if you don't have.
2. Enable Chaos tools, Page manager and Panels.
3. Create a custom page at **admin/structure/pages/add** with the path "estate/%node" which will be a new mirror page of the existing path "node/%node".
4. Assign **Node: ID** context to the argument **%node**.
5. Choose two column layout.
6. Add **Existing node** to the left column. To use a NID from the URL, use **%1** in the title box.
7. For the right column, add the contact form from **Widgets**.

To get node information in the contact form, you need to write a hook hook\_form\_FORM\_ID\_alter in your custom module using the argument NID. You can study custom moduling here. Here is the example code snippet.

```
<?php
/**
 * Implementation of hook_form_alter().
 * @see http://api.drupal.org/api/function/hook_form_alter
 */
function yourmodule_form_contact_mail_page_alter(&$form, &$form_state, $form_id) {

    if(arg(0) == 'estate' && is_numeric(arg(1)){
        $node = node_load(arg(1));
    }

}
?>

```

You can also see how can you customize the contact form here:
http://www.metaltoad.com/blog/how-add-field-drupal-contact-form
http://www.isegura.es/blog/modifying-contact-form-drupal-how-add-field
http://www.pensamientosdivergentes.net/blog/modifying-contact-form-drupal-how-add-field

The drawback of this solution is you have to use the new path "estate/%node" to the node view page instead of using the default existing path "node/%node".
Any better answer is welcome.
> 0 votes

---
Tags: 7, hooks, emails
---


title: join two tables with views?

text:
# Question
Title: join two tables with views?
I have two content types: one for invoices, and the other for donations.

Each content type contain two fields, one for "User Name" (which is a user reference type) and the other is the "Amount($)" (an integer type).

I am trying to create a table with the Views module that returns 3 columns: user name, total donation (the sum for all the donation for the same user), and invoice sum (the sum of all the amount paid for the same user).

I have two users (Ahmed and Taha). Ahmed made 3 donations ($50, $30 and $70) and paid 2 invoices ($30, $30); Taha made 1 donation ($60), and paid 3 invoices ($30, $30, $30).

What I am trying to achieve with the Views module is something like the following.

```
    *----------------*------------------------*-------------------------*
    |   Username     | Total Donations        | Total Subscriptions     |
    *----------------*------------------------*-------------------------*
    |   Ahmed        |     $150               |      $60                |
    *----------------*------------------------*-------------------------*
    |   Taha         |     $60                |       $90               |
    *----------------*------------------------*-------------------------*

```

or Something like:

```
    *----------------*------------------------*-------------------------*
    |   Username     | Donations              | Subscriptions           |
    *----------------*------------------------*-------------------------*
    |   Ahmed        |     $50                |      $30                |
    *----------------*------------------------*-------------------------*
    |   Ahmed        |     $30                |      $30                |
    *----------------*------------------------*-------------------------*
    |   Ahmed        |     $70                |       ---               |
    *----------------*------------------------*-------------------------*
    |   Taha         |     $60                |       $30               |
    *----------------*------------------------*-------------------------*
    |   Taha         |     ---                |       $30               |
    *----------------*------------------------*-------------------------*
    |   Taha         |     ---                |       $30               |
    *----------------*------------------------*-------------------------*

```

# Answer
To add Joins to your views using the Views UI you will need to open the Advanced settings and visit Relationships. (See graphic)

Assuming the user is the author ($node-\>uid) of the donation's and subscription's payment types you should be able to use the "Content: Author" field to accomplish this join.

This should allow you to build the second table from your question. To see results displayed in a similar format to your first table you will need to use aggregation. 'Use Aggregation' can be found under the Advanced menu.

Once use aggregation is enabled you will see a new link below your fields called "Aggregation settings."

Select SUM on the field you want to display the totals for and you should see something similar to your first table.

Lastly, while you are getting aquanted with the Views module I recommend turning on the "Show the SQL query" feature in Views settings. This can be found at `admin/structure/views/settings`

This will show you the SQL views is generating which can be useful while debugging or learning the Views UI.
> 4 votes

---
Tags: entities, views
---


title: Reset Webform's SQL table indices?

text:
# Question
Title: Reset Webform's SQL table indices?
I'm using webforms to get some data from users. These results are later used in another php script, and this relies on looping through the data:

```
for ($i = 1; $i <= count($data); $i++)
    {
        $answers[] = $data[$i]["value"][0];
    }

```

However, by adding and deleting questions in the webform, the indices look something like this now:

```
1
2
3
5
8
12

```

And this gives an error because I use `count()` to get the number of entries. (`count() = 6`, but `max() = 12`). My first idea is to find a way to automatically reset the indices after adding or removing questions. So my indices look like this:

```
1
2
3
4
5
6

```

But I honestly have no idea how to go about this. Any ideas?

# Answer
Well, as I got it, the question is not related to Webforms (which I'm not familiar with) but to PHP itself.

Besides "for each" option there is array\_values() function. (If you don't want to change your script that processes the array).

```
$arr = array_values($arr);

```

link and link
> 1 votes

# Answer
I might be misunderstanding you but I think you just want a `foreach` loop:

```
foreach ($data as $item) {
  $answers[] = $item["value"][0];
}

```

Or even shorter:

```
$answers = array_map(function($item) { return $item['value'][0]; }, $data);

```
> 1 votes

# Answer
You can use the `webform_get_submissions($nid);` loop the out put of this function using foreach. You will get the values without any issues.
> 0 votes

---
Tags: 7, webforms
---


# Question
Title: Display a custom field of a content type in template with PHP?
I'm using Drupal 7. I have a content type called Widget. One of the custom fields is field\_widget\_position. When I did a `<?php print_r($page); ?>` in the template, I can see the key-value pair of field\_widget\_position buried deep in the array. Is there an easier way to get a handle on field\_widget\_position instead of typing `<?php echo $page['somefield']['somefield2']['somefield3']['etc....']['field_widget_position']; ?>`?

# Answer
I found the answer.

```
$node->field_widget_position['en'][0]['value']

```
> 2 votes

# Answer
```
$node->field_widget_position['en'][0]['value']

```

This is a bad solution.

The right solution is

```
render(field_view_field('node', $node, 'field_widget_position'));

```

or

```
render(field_view_field('node', $node, 'field_widget_position', array('label' => 'hidden')));

```

if you don't want to print a label.

See http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way for more info.
> 4 votes

---
Tags: theming
---


# Question
Title: HTML Mail not working with custom module
I have installed HTML Mail and Mail System modules and set them up with a template.. this is working fine when I send the test email it uses the template.

However when I send mail from my function, it doesn't use the template.. it was my understanding this should happen automatically, but how can I force it?

I have a `mymodule_mail` function that just does a switch on $key and fills $message based on various types of messages the system sends.

I call it using drupal\_mail().. and that's working, but not loading the template file.

So I added this line above where the mail is being dispatched:

```
mailsystem_set(array(mailsystem_default_id() => 'HTMLMailSystem'));
drupal_mail('mymodule', 'notification', $email, user_preferred_language($user), $params);

```

Then I tried moving the mailsystem\_set to inside the `mymodule_mail` function.

and it still isn't working. What am I missing??

drupal\_mail has a module parameter that I'm using to call my own module that processes the different templates based on database calls etc. I'm wondering if I have to use that to call HTMLMailSystem, but I need to call my own first. (and still thought using the HTMLMailSystem would be the default)

# Answer
The configuration can be done through the Mail System UI. Here is how I send HTML messages with a custom module without a template.

First, install HTML Mail and Mail System as you already have.

Next, create your module and implement hook\_mail() and add an identifier (key) to use when sending.

```
function hook_mail($key, &$message, $params) {
  switch ($key) {
    case 'MODULE_unique_sending_key':
      $message['Reply-To'] = $params['Reply-To'];
      $message['subject'] = $params['subject'];
      $message['body'] = $params['body'];
      $message['headers']['Reply-To'] = $params['Reply-To'];
      break;
    }
}

```

Next, implement drupal\_mail().

```
$key = 'MODULE_unique_sending_key';
$message = drupal_mail('MODULE', $key, $to, LANGUAGE_NONE, $params, $from);

```

Lastly, you will need to tell Drupal to use the HTMLMailSystem to send when using the `'MODULE_unique_sending_key'` key.

To do this, go to `admin/config/system/mailsystem` and go to 'New Setting.'

Under module, choose your custom module.

Under Key, enter your unique message identifier you used in drupal\_mail().

Now, while still on the `admin/config/system/mailsystem` page look under `'MAIL SYSTEM SETTINGS'` look for the Module+Key combination you just created.

From here, you will need to select the HTMLMailSystem as your sending class. Save and test your module. HTML mail should now be working without using a template.
> 4 votes

---
Tags: 7, emails
---


title: Linking Content Types to Pages

text:
# Question
Title: Linking Content Types to Pages
I have multiple content types like news, publications, etc and I will like to link them to pages on my site. So when a user posts a news item on a specific page, it only shows up on that page only. Also I will want users to be able to edit content on only pages they have been assigned to. Eg. A user will only be allowed to add news to pages they have rights to. I was considering using groups for this, but I know more suggestions will be helpful.

Many thanks Isacc

# Answer
> 0 votes
You can create different views and filter the content types.

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


# Question
Title: Fetch customer profile in a component rule
I'm working on a multi-lingual webshop and I'm trying to create a system for commerce where an admin can accept or reject orders. I've done this by creating a view that lists all pending orders and then I'm using bulk operations with 'accept' and 'reject' buttons to send a list of selected orders too a component rule that changes the order status. This works fine, except that I also want to send an e-mail to the person who made the order when the order is rejected. Again, sending the e-mail is not a problem, since it is stored within the order, what I'm having trouble with is sending the e-mail in the customer's language.

The site allows for anonymous orders, so referring too the order's owner for the language is not an option. I can't store extra information in an order either, so I added a hidden field too the customer profile that stores the language. However, all I have to work with is the list of orders. When I try to fetch the customer profile I don't get access too the field values, only the profile's ID and User ID.

Is there any way to fetch the complete profile, or possibly even better, is there a way to send the language string as parameter too the component rule with from the view?

# Answer
> 0 votes
Which module you using for customer profile. Are you using user profile like profile\_load\_profile($account);

---
Tags: 7, views, commerce, rules, i18n-l10n
---


# Question
Title: Is there a way to allow an authenticated user to add to another users post?
I have a content type that uses a field collection field and I would like for one user to create the initial node, then have other users able to add field collection entries after it has been submitted. Do you have any suggestion?

# Answer
You can use the Content Access module to give the users permission to content level.
> 0 votes

# Answer
If you need to restrict who can edit a field, and make that groups of users different from the group of users who can edit the node, you can use the Field Permissions module.

Users who has the permission to edit a field still need the permission to edit the node.

> The Field Permissions module allows site administrators to set field-level permissions to edit, view and create fields on any entity.
>
> ### Features
>
> * Enable field permissions on any entity, not just nodes.
> * Role-based field permissions allowing different viewing patterned based on what access the user has.
> * Author-level permissions allow viewing and editing of fields based on who the entity owner is.
> * Permissions for each field are not enabled by default. Instead, administrators can enable these permissions explicitly for the fields where this feature is needed.
> 0 votes

---
Tags: 7, entities
---


# Question
Title: How to have a required profile2 on user registrations, but allow admin-created users without a profile?
Profile2 allows to give access to a profile based on user role. This works naturally when creating a profile is optional for privileged users with an extra role. How can you achieve what is more or less the reverse? That is,

* Visitors can create a user account, and a main profile2 profile must be filled out on the user registration form (it has some required fields)
* But, admins should be able to create users without this main profile (e.g. new admin users). This does not seem possible with the usual configuration options...

What is the best way to achieve this?

# Answer
> 0 votes
I'm going to guess the best option is to:

* set the profile fields to not required
* set the profile to show on the user registration form
* then hook into the user registration form via a custom module to set the profile fields you want filled out as required (and admin-created users added via user/add will be able to skip these fields).

---
Tags: users
---


title: unwanted site name in url

text:
# Question
Title: unwanted site name in url
I've just copied my drupal website from local to server, everything is fine except the url of the site is http://www.mydrupalsite.com/mydrupalsite.com/index.php (although there is no folder named mydrupalsite.com)

The server directories and files are like this:

* root
    + .htaccess
    + mydrupalsite.com
        - index.php
        - other drupal files...
        - .htaccess (drupal one)
    + myothersite.com
        - ...

I don't think the root htaccess file has something to do with it, because myothersite.com has no problems with it. Is it possible that the .htaccess file of the drupal is causing it? If so, how to prevent it?

I made some changes and tried this in root .htaccess, but it still doesn't work:

```
RewriteEngine on
RewriteOptions MaxRedirects=2
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+).([a-zA-Z0-9-]+).([a-zA-Z]+)$
RewriteCond %{QUERY_STRING} !^(.*)redirect=1(.*)$ [NC]
RewriteRule ^(.*)$ /%2.%3/$1?redirect=1&%{QUERY_STRING}

```

To sum it up, I found out that this structure has been created by previous admin and should not be changed (as there are two domains). I guess the problem could be solved by removing the /mydrupalsite.com/ when present in url with .htaccess somehow, but finally I've been said it does not matter, so I left it as it is.

# Answer
If I understood your question correctly, and given the directory structure, you'll want to modify the .htaccess (the one in the root directory) so that requests are rewritten.

To do so, find and modify (or add) the following line:

`RewriteBase /mydrupalsite.com`
> 2 votes

# Answer
If http://www.mydrupalsite.com, and http://www.myothersite.com are two domains that point to the same web server, you can set a multi-site configuration.

A multi-site configuration allows you to run Drupal on two different domains that point to the same web server copying the Drupal files in a single directory. Basing on the domain name used when accessing the site, Drupal will use a different settings.php file, which means the sites can also use different databases.
If you install Drupal on the document root directory of the web server, your sites will appear at http://www.mydrupalsite.com, and http://www.myothersite.com, without any additional paths.

I actually used a multi-site configuration for my site: Instead of having two copies of the files for the main domain, and its subdomain, I have a single copy of the files. In my case, I simply added a DNS entry to point blogs.mysite.com to mysite.com. (I have used an A entry, as I am using a static IP.)

See Multi-site how-tos including videos for more information.
> 0 votes

---
Tags: uri, redirection, .htaccess
---


# Question
Title: How to create custom field in ubercart 3.x checkout page?
I want to customize checkout page and remove/add some fields from client information. How can I do it?

# Answer
I found the Extra Fields Checkout Pane module.

> This module allows an administrator to define additional (billing and shipping) address fields as well as custom order fields in Ubercart e-commerce suite. These fields will be available during checkout process and in order handling pages. This module has been developed and tested with Ubercart 2.6.
> 1 votes

---
Tags: ubercart
---


title: Views, get data for parent term as well

text:
# Question
Title: Views, get data for parent term as well
I will try to keep the question simple and short. I have (Drupal 7):

a Vocabulary "Country regions" (depth 1 level):
Austria
-Burgenland
-Tyrol
Belgium
-Arlon
-Liege
-Namur
...

a Content type "Regional development programs" with a "Applies to:" field on this vocabulary, a terms multi-select field.

a View with an URL argument (a region) - contextual filter.

I'm trying to build a View to show all "Regional development programs" that use the parent of the given region.

Example:
URL: /get-programs/Liege/
I want to retrieve all programs that apply to Liege (given argument), which is easy, BUT I also need all programs that apply to the region parent, which is Belgium (because, of course, all Belgium programs apply to its regions as well).

Sorry if the solution is already given in another question, but I couldn't find a similar question (I found several questions for getting the children of an argument, but not for the parent).

Thanks a lot!

# Answer
> 3 votes
I believe that your problem would be solved by adding a relationship to your view. Here are the steps:

1. Add Relationship: taxonomy terms on node
2. Select the vocabulary you want to use.
3. Add Relationship: parent term

Now you should be able to add fields from any of the terms or their parents, and to use them as contextual filters as well.

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


title: Showing a node with a Views?

text:
# Question
Title: Showing a node with a Views?
I have a bundle "Text" and bundle "Protocol". The "Protocol" bundle has a field of Entity Reference type which links the "protocol" node with texts that were accepted during that protocol. (I.e. the join is somewhat like "Protocol"-\>"Text") Also Protocol has following fields: a protocol number (integer) and a date (date-iso)

While viewing "Text"-type node there will be shown information about the corresponding protocol:its number and acceptance date (mention them above).

So the question is: is it a good practice to show this pages via Views? Owing to its Relations feature, obtaining of information related to the corresponding protocol is really easy. But idea itself seems to me being of kinda "bad Drupal way", because there is a standard way of displaying nodes in Drupal.

If the Views is really bad idea, then how should I obtain the protocol's number and date, from tpl.php (or preprocessor function)? Any variants?

# Answer
Views can be a little heavy, and if you don't need the module it's lighter just to drop it.

If you just want to grab some info for a template, you could also do it with Entity Field Queries.
> 1 votes

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


# Question
Title: How do I avoid duplication in a view result?
I want to list the states from the state/province field (handled by the Location module) in a content type. I used views, but it shows the same state name more than once.

I enabled distinct in the Views module, but it doesn't works. How can I avoid the same state name is shown more than once?

Current Result: Illinois, Georgia, Alabama, Illinois, Alabama, Alabama, Georgia.

I attached the screen shot of my view (I used table format and views group by module).

Expected Result : Illinois, Georgia, Alabama.

This is my views set up.

This is what I'm getting from my view.

I'm expecting this result no matter how many nodes have the same state; I want to display the state name only once.

This is the table style I used, and views group by module.

# Answer
> 1 votes
If Views' `distinct` parameter doesn't work for your case, you can always use a `views_pre_render()` hook to do anything with the result before it is rendered. Something along the lines of...

```
YOURMODULE_views_pre_render(&$view) {

  if ($view->name=='NAMEOFVIEW') {

    // drupal_set_message('<pre>' . print_r($view->result, TRUE) . '</pre>');

    $states_found=array();

    foreach($view->result as $delta => $row) {

      if (in_array($row->LOCATION_FIELD_NAME_VALUE, $states_found)) {
        unset($view->result[$delta]);
      } else {
        $states_found[]=$row->LOCATION_FIELD_NAME_VALUE;
      }

    }

  }

  // any other pre_render()ing here...

}

```

What this does is loop through the rows of your view result keeping track of what states have been found and unsetting any duplicates. The commented out `dsm` at the beginning will help you figure out what `LOCATION_FIELD_NAME_VALUE` you need to use in your specific case.

# Answer
> 0 votes
I used the following code to get the state names(major condition is no matter how many nodes have the same location but it should retrive the state name only once)

```
<?php
$var = db_query("SELECT DISTINCT province FROM  location");
          while($variable = db_fetch_array($var)){

            print $variable['province'].'<br/>';

          }

```

?\>

Just used the select query in my page.tpl it displays the statename only once even one or more than one node has chosen the same state.

---
Tags: views, location
---


title: Rebuild form in AJAX callback

text:
# Question
Title: Rebuild form in AJAX callback
I've got a simple form which I've added a little AJAX to. The form simply let's people add users to a list. That is, I've got a textfield where people can enter an e-mail address, and that e-mail address gets added to the list.

Now, the "Add" button is AJAX enabled, meaning that the add request gets posted as an AJAX request. However, I would then like the AJAX callback function to render the form again so that the newly added user appears in the list. However, I can't really see how I should do this.

I've tried to build the form ("from scratch") using drupal\_get\_form() in the AJAX callback function and then return that form, but that does not work. It just gives me the error :

```
Notice: Undefined index: form_build_id in /home/playground/www/public_html/includes/ajax.inc on line 320

```

How should I go about when I would like to rebuild the form from the very scratch as a part of the AJAX request, and then return that form?

# Answer
In your AJAX callback, use `$form_state['rebuild'] = TRUE;` (drupal\_rebuild\_form).

$form\_state\['rebuild'\] is very useful in multistep forms, but it can also be handy in Ajax callbacks.

I recommend checking out the Examples project as well. Both the Form examples and the AJAX examples.

If you will add the relevant snippets of your code I will try to add more details.
> 1 votes

# Answer
Looks like you're trying to do it old way.

In D7 your form building code runs on initial form display and on subsequent ajax calls. You can make use of `$form_state` parameter there to render the form according to freshly entered data.

You attach a '#callback' attribute to ajaxified elements. Most examples show returning one particular element in a callback. But it's just a convenient special case. There is a powerful Ajax Commands API, it can be used to request execution of a wide range of operations on a client from a server.

No need to manually rebuilding forms or something like that. Just look at the examples on http://api.drupal.org/api/drupal/includes!ajax.inc/group/ajax\_commands/7.
> 1 votes

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


title: Janrain custom theme issue

text:
# Question
Title: Janrain custom theme issue
I am creating a custom theme for my site and with this I am interested in using Janrain as my log in.

I have tested the janrain set up on various theme downloadable through drupal and it works perfect.

I started writing my own theme from the ground up and ran into an issue...

I created everything I needed for a basic site (left sidebar, right sidebar, content, footer, etc) and placed the Janrain block inside the left sidebar.

Everything shows up in my side bar fine. I can log in perfectly with the regular log in fields. When I click one of the icons to say log in with facebook, the lightbox (popup, login alert, whatever its called) does not show up.

I inspect the fb icon element with Google Chrome and and press the fb icon again and this is the error i receive from the source tab.

> Uncaught ReferenceError:RPXNOW is not defined (repeated 14 times)

This is what that error points to:

```
<div class="form-actions form-wrapper" id="edit-actions"><input type="submit" id="edit-submit" name="op" value="Log in" class="form-submit" /></div><div class="item-list"><ul class="rpx-links"><li class="rpx-link first last"><a href="https://eval.rpxnow.com/openid/v2/signin?token_url=http%3A//johnr.rrc.com/rpx/token_handler%3Fdestination%3Dnode/4" class="rpxnow" onclick="return false;" onmousedown="delete RPXNOW.default_provider;">Sign in using one of these accounts:</a><br /><a href="https://eval.rpxnow.com/openid/v2/signin?token_url=http%3A//johnr.rrc.com/rpx/token_handler%3Fdestination%3Dnode/4" class="rpxnow" onclick="return false;" onmousedown="RPXNOW.default_provider = 'facebook';"><div class="rpx-icon-small rpx-facebook-small" id="rpx-facebook"></div></a><a href="https://eval.rpxnow.com/openid/v2/signin?token_url=http%3A//johnr.rrc.com/rpx/token_handler%3Fdestination%3Dnode/4" class="rpxnow" onclick="return false;" onmousedown="RPXNOW.default_provider = 'twitter';"><div class="rpx-icon-small rpx-twitter-small" id="rpx-twitter"></div></a><a href="https://eval.rpxnow.com/openid/v2/signin?token_url=http%3A//johnr.rrc.com/rpx/token_handler%3Fdestination%3Dnode/4" class="rpxnow" onclick="return false;" onmousedown="RPXNOW.default_provider = 'google';"><div class="rpx-icon-small rpx-google-small" id="rpx-google"></div></a><a href="https://eval.rpxnow.com/openid/v2/signin?token_url=http%3A//johnr.rrc.com/rpx/token_handler%3Fdestination%3Dnode/4" class="rpxnow" onclick="return false;" onmousedown="RPXNOW.default_provider = 'yahoo';"><div class="rpx-icon-small rpx-yahoo-small" id="rpx-yahoo"></div></a><a href="https://eval.rpxnow.com/openid/v2/signin?token_url=http%3A//johnr.rrc.com/rpx/token_handler%3Fdestination%3Dnode/4" class="rpxnow" onclick="return false;" onmousedown="RPXNOW.default_provider = 'aol';"><div class="rpx-icon-small rpx-aol-small" id="rpx-aol"></div></a><a href="https://eval.rpxnow.com/openid/v2/signin?token_url=http%3A//johnr.rrc.com/rpx/token_handler%3Fdestination%3Dnode/4" class="rpxnow" onclick="return false;" onmousedown="RPXNOW.default_provider = 'openid';"><div class="rpx-icon-small rpx-openid-small" id="rpx-openid"></div></a></li>

```

What am I missing for my custom theme that janrain needs so it works properly?

Note: As another test i did this with a completely blank theme and still the same issue.

**edit**:

It looks like janrain requires the use of a footer, but I am adding in all the footer stuff I need:

```
<!-- Footer -->
<div id="footer">

    <div id="footer-inside">

        <div class="footer-area first">
        <?php print render($page['footer_first']); ?>
        </div><!-- EOF: .footer-area -->

        <div class="footer-area second">
        <?php print render($page['footer_second']); ?>
        </div><!-- EOF: .footer-area -->

        <div class="footer-area third">
        <?php print render($page['footer_third']); ?>
        </div><!-- EOF: .footer-area -->

    </div><!-- EOF: #footer-inside -->

</div><!-- EOF: #footer -->

<!-- Footer -->
<div id="footer-bottom">

    <div id="footer-bottom-inside">

        <div id="footer-bottom-left">

            <?php print theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('class' => array('secondary-menu', 'links', 'clearfix')))); ?>

            <?php print render($page['footer']); ?>

        </div>

        <div id="footer-bottom-right">

            <?php print render($page['footer_bottom_right']); ?>

        </div><!-- EOF: #footer-bottom-right -->

    </div><!-- EOF: #footer-bottom-inside -->

</div><!-- EOF: #footer -->

```

# Answer
I think you're missing $page\_top and (probably more importantly) $page\_bottom in your html.tpl.php. Try changing

`<?php print $page; ?>`

to

```
<?php print $page_top; ?>
<?php print $page; ?>
<?php print $page_bottom; ?>

```

From the html.tpl.php pastebin that you linked to above:

> * $page\_bottom: Final closing markup from any modules that have altered the page. This variable should always be output last, after all other dynamic content.
> 1 votes

---
Tags: 7, theming
---


# Question
Title: Views: if fieldvalue (external link) is set, use it, if not, link to node
For my articles, i've added a field "external\_link". If this link is set, the headline should link to an external website, and if not, the headline should open the articles detailview.

Now i have the fields of my view two fields, which are excluded from the display, the external\_link, and the nid. And on the headlinefield, i can do a

"rewrite results -\> output this field as a link" and write either node/\[nid\] or \[external\_link\],

but how to use conditions in views, to use the external\_link if set, and the node/\[nid\] if not set? I'm new to Drupal and i have no idea how or where to add this condition...

# Answer
There is no direct way of using conditionals inside of Views. However, you *might* be able to fake it out with something like this:

1. Order the fields in your view in nid, external link, title order.
2. In your external link field, set empty field behavior to node/\[nid\]
3. Always use it as the link in the last rewrite.

In my just woke up and enjoying espresso before getting to some real work state of mind, this *should* do what you are asking for, eg, linking to node/nid if there is no external link, but using it if it exists.
> 0 votes

---
Tags: views
---


# Question
Title: pages accessible only by specific groups
I have made those pages on my Drupal 6: Alpha, Bravo, charlie, Delta. At time of writing, those pages are visible by anybody. I need that those pages are visible only for limited groups, for example: Alpha is visible only for group One and Two Bravo is visible only for group Two and Three Charlie is visible only for group Two and Three Delta is visible only for group Three. I have other nodes and other groups on the Drupal installation that needs to stay untouched, I need to change permissions only for those four pages, and of course their menu links need to reflect that (so each group will see only the menu links that they have granted access) How can I do that?

# Answer
Try the Nodeaccess module, here is a quote from its project page:

> ... is a Drupal access control module which provides view, edit and delete access to nodes. Users with the 'grant node permissions' permission will have a grant tab on node pages which allows them to grant access to that node by user or role. Administrators can set default access controls per content type, and also define which roles are available to grant permissions to on the node grants tab.
> 1 votes

---
Tags: routes, users, 7
---


# Question
Title: View: How to make a list of article(in a block) related to the taxonomy term of my main article
I would like to display a list of link in a block that are related to the taxonomy term of my main article.

I read others subjects like article-view-with-links-to-other-articles

but it doesn't work for me. My URL is like that : **example.com/product/\[node:id\]** (Maybe it doesn't work because i don't have the term id in my url)

My article has a vocabulary call "tendance", this article is tag with the term, for instance "tendance one". I would like to have all the article tag with "tendance one"

I have this configuration:

1. **Contextual filter:** Content nid
2. **WHEN THE FILTER VALUE IS NOT AVAILABLE :** raw value from URL
3. I add validation etc.
4. And in **More** section, i click on exclude

So i had a list of all my article in my block thanks to the **exclude** but there are not related to the term "tendance one" of my main article.

I tried to add relationship :

* Content: Taxonomy terms on node (and i select my vocabulary "tendance" and required relationship)
* Taxonomy term: Content using tendance

And it doesn't work, i always have the same list of article linked to the good vacabulary but not to the good term.

Do i have to pass in my url the taxonomy term to make it work? Thanks,

# Answer
i've just found the perfect solution for me.

I tried a lot of solution with some php code but without success.

The problem was : I had one view which display an article (with a taxonomy vocabulary) and i wanted to add a block with a list of link of another content type who are linked with the same taxonomy term.

URL: www.example/product/\[nid\]/\[title\]

***Contextual filter***

1. **Contextual filter**: Content nid
2. **WHEN THE FILTER VALUE IS NOT AVAILABLE** : raw value from URL (path -\> 2 to retrieve the node id)

***RELATIONSHIPS***

1. Content: Taxonomy terms on node (with Require this relationship)
2. (term) Taxonomy term: Content with term (with Require this relationship) -\> Relationship -\> Taxonomy terms on node

And after you have to come back to the contextual filters:

* And add a **Relationship** to **Taxonomy term: Content with term**

Now it works great, i have all my other content type with the same term of taxonomy linker to the term of the main article display by view on my page.
> 1 votes

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


# Question
Title: Drupal commerce - product display view replicates products
I'm building a ecommerce for a fashion designer and of course every item has got variation such as color and size. With line item it's fine, on the product display i've got the option to change color and size and with the fancy attribute module I can show a small box with the color instead of simple text.

Now I have to build a view of product display which contains title, 1 picture and price. In order to get the price I create a relationship with the product reference but here comes the problem, it shows all the products, every variations so one item could be repeated several times in different color and different size.

I would like to show just one product of that group, then the user clicks on it and sees the product display and there he can choose the variation.

Of course I can delete the relationship, add a price field on the content type "product display" and show it in the view but I would like to know if there is another way to do it.

Thanks in advance.

# Answer
This is known issue discussed in this issue. Setting the query to distinct in the queery settings under advanced within views worked for me, as described in comment 6.
> 3 votes

# Answer
Not needed to add Fields in view, only create a view (Content, not Product) of Product display nodes, Format show Teaser OR other **Display entity view** already created with http://drupal.org/project/entity\_view\_mode \- in display mode add only field you want to display
> 2 votes

---
Tags: views, commerce
---


# Question
Title: Boost module's "Cache every page except the listed pages" option
I use Boost 7.x. I couldn't use "Cache every page except the listed pages" option. If i leave the textarea (of exclusion of some pages) everything works well.

In "/admin/config/system/boost" it is written like this:

> Specify pages by using their paths. Enter one path per line. The '\*' character is a wildcard. Example paths are `blog` for the blog page and `blog/*` for every personal blog. `<front>` is the front page.

When I add the allowing lines, Boost breaks to cache files.

* content/my-alias-1
* content/my-alias-2

Am I using the wrong format for writing those lines?

# Answer
> 3 votes
I know this question is moldy old bread, but I wanted to answer for future searchers.

If a page has been cached by boost and then you exclude it, the cache will need to expire or be manually cleared before the exception will be used.

This is probably why you were still seeing the cached page when you added an excluded page.

---
Tags: caching
---


# Question
Title: Displaying a Page Before Drupal Bootstrap starts
Is it possible to display page before drupal starts. for example displaying a nice jQuery animated page first and then after some time, loading drupal or providing a link to the drupal site on that animated page.

# Answer
> 0 votes
To *precisely* answer your question, Yes. If a file exists, drupal will *not* get involved. Therefore, if, for example, you went to `www.yourhost.com/splash.php`, and `splash.php` existed in your web root/directory, it would be run without drupal getting involved. In there, if you had a link to `www.yourhost.com`, where drupal's `index.php` exists, then upon clicking that link, drupal would bootstrap up and do it's thing.

If this is not what you are asking, you could investigate the Front module that allows you to have different front pages based upon roles. Here, you could, for example, have a fancy splash page for anonymous users that goes away after they login.

If that doesn't work for you, then you could fake this out in a custom module using your own custom logic in either the `boot()` or `init()` hooks.

# Answer
> 0 votes
Before Drupal bootstraps, it cannot output anything. The only output before Drupal bootstrap can come from a PHP file that doesn't use Drupal, or a simple HTML page that show the jQuery animation.

Serving the initial page from outside Drupal, and then redirecting the user to the Drupal page doesn't give any performance gain, as Drupal is bootstrapped in any case. Drupal would help, for example, when the animation needs to be presented to specific users (e.g. anonymous users, users that log in on Drupal for the first time).

As modules, there is the Splashify module. I have never used it, but from the description, it seems suit your need.

> Display a splash page anywhere on your site by redirecting the user, showing a lightbox, or displaying a popup. This module is designed to be search engine friendly, mobile device friendly and offers multiple configuration options.

If there aren't modules that are helpful for you, you can create your own module. I would implement hook\_page\_alter() to add a JavaScript file to show the animation/popup you need.

---
Tags: 7, bootstrapping
---


# Question
Title: How to wrap module output with common html?
I am using Drupal 7.14. I have a custom module with a number of different output pages. I define the paths in hook\_menu and then in the callback functions I do some work and call echo theme('mytemplate', array(..args...)) at the end to output my content.

I also have a second custom module that does different work but outputs its content in a similar way.

I want to output some wrapping html that is common to the two module page outputs. At the moment the way I do this is to require a head and foot html file in each of the module template files.

This doesn't feel like a very Drupal approach so I'd appreciate some guidance.

Note: the wrapping html is specific to these two modules so I'd prefer not to pollute my main page.tpl.php file with it.

# Answer
> 1 votes
The only thing I see you could do is to have one commeon theme function and let one module depend on the other (you should specify this in the .info file). If you are going to have more modules with them same requirement you could have a central output module doing the theming.

---
Tags: 7, theming
---


# Question
Title: Use relationship for Views taxonomy term filter
I'm using the Commerce module, and I'm trying to create a view that displays the nodes with several exposed filters that should apply for the products.

Now, the node has a term field that references to a category. A normal taxonomy term filter works just fine for this case.

The products has a term field that references to a color.

What I would like to do is adding another taxonomy term filter for the color vocabulary (just like the one described above) that uses a relationship to the product. AFAIK, it's not possible to use a relationship for a taxonomy term filter.

Can I achieve what I am trying, in any way?

I'm using Drupal 7.2 and Views 3-beta3.

# Answer
I've been able to do this with a simple "Content: Referenced product" relationship in my view. If you try using any of the "Content: xxxxx" filter fields, they won't work, as you're noting here. So, "Content: has taxonomy term ID," won't let you choose the relationship. However, if you use the "Commerce Product: xxxx" (where xxxx is the term refrerence field) field for your contextual filter, it'll work with the relationship.
> 1 votes

---
Tags: 7, views, commerce
---


# Question
Title: display 2 tables with checkboxes by ajax button
I am altering a form and placing a new 'button' . On the press of the button, using the #ajax property , I want to display 2 separate tables with checkboxes for each row. Each table has separate data.

The 2 tables should be initially hidden and should become visible on button press. How should I proceed with this ??

The table data is fetched from database and some operations are performed on it.. so where should I put this code ? In the callback function ?

Update- I tried to implement this by using tableselect, but the checked boxes aren't returning the values in the $form\_state\['values'\]. You can check out the code here or suggest me a simpler interface to implement.

# Answer
> 0 votes
You should not put the table-building code in the ajax callback. Put the code to build the tables into the hook\_form\_alter() implementation that you are using to add the button. You can use $form\_state\['triggering\_element'\] to tell if the button has been pressed, and only execute the query and build the tables if you need to.

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


# Question
Title: How do I remove the header background image in Pixture Reloaded theme?
I'm not sure why this is difficult, but how do I remove the default background image in the Pixture Reloaded theme?

# Answer
> 0 votes
I deleted the temp directories and css cache files, selected the theme color again, and it worked.

# Answer
> 0 votes
For Pixture Reloaded 3.x, I made a subtheme and I added this CSS:

```
#header, #header .header-inner {
    background: mycolor;
    background-color: mycolor; }

```

---
Tags: 7, theming
---


title: How can I integrate Magento in a site?

text:
# Question
Title: How can I integrate Magento in a site?
Does anyone know of a way to integrate Drupal 7 with Magento?

I see that the Magento module doesn't have a version for Drupal 7, but I'd like to keep my Drupal installation shiny and new at the start of the project. I'm talking to the powers that be about using the commerce module instead, but I suspect that's going to be a non-starter.

# Answer
The easiest and simplest way to integrate drupal with magento is using magento API. http://www.magentocommerce.com/api/soap/introduction.html. Magento API provides all the functions necessary for e-commerce operation. You can get the list of all categories, products, product reviews, shopping cart feature etc.
> 2 votes

---
Tags: 7
---


title: jCarousel and image zoom

text:
# Question
Title: jCarousel and image zoom
I'm using the module image zoom to enlarge an image with the mouse over, also I use jCarousel to get a carousels in different pages.

In the image zoom module you have the option to get the thumbnail of the not selected images. example :you have a node with 6 images, one will be big and the other will be thumbnails and when you click on one of them automatically it the big image will be swapped with the clicked one.

Now automatically those thumbnail are styled with the jquery carousel, I don't mind but the problem is that I cannot change the configuration of it! I cannot change horizanotal to vertical or other settings.

How do I fix it? Should I create the jcarousel by my self and uninstall the modules or is there a solution somewhere?

Thanks in advance.

# Answer
As described on the jCarousel module page:

> Note that you will almost certainly need to do custom CSS in your theme in order to use this module.

Use Chrome Inspect, Right Click \> Inspect aka Chrome Developers Tools or Even use Firebug on Firefox to inspect the applied css properties and override them in your .css file in your theme folder "sites/all/themes/themename"

A basic CSS Knowledge is what you really need.

To Change the Settings of jCarousel, Go to your views and find the "Format" Area. Make sure that the "Format" is set to jCarousel and click on "Settings" beside it. A new pop-up will open. Inside, You will find all the setting related to your jCarousel initiator.

**To change from Horizontal to Vertical scrolling, Click on the Advanced, Scroll down then Check the "Vertical" checkbox.** See Screenshot

This is the most easy way to do it. If I understod your question rightly.
> 1 votes

---
Tags: commerce, media, javascript
---


# Question
Title: Rules with Commerce Discount for a certain type of product.
I'm trying to get a handle on Rules in Drupal. The concept seems to be very flexible and straight forward for the most part. However, I'm stuck and hoping someone can lend some assistance.

I have a Drupal Commerce store that sells two items. Gift cards and books. The store offers a volume discount of buying 3-5 books at a time. I have got the discount working using Commerce Discount and rules. The issue is the discount is added to the entire cart, not just books. Under Rules there is no way, that I can find, to select the content type of the line item being added and compare it to the books custom content type.

Can someone please explain or help me with where to look to only apply the discount to commerce products from the custom content type Books.

Here is the basic setup.. Drupal Core 7.15 Drupal Commerce 7.x-1.3 Drupal Discount 7.x-1.x-dev Rules 7.x-2.2

Books is a Custom Content Type. Discount should only be applied to Books.

Rules Setup 1. Event \+ Calculating the sell price of a product 2. Condition: \+ Entity exists by property //This one way I have tried but not working, seems the most reasonable way \+ Total product of type quantity comparison //This counts the total by product in cart 3. + Apply discount to product

# Answer
You have a rule that reacts on "Calculating the sell price of an item" and a condition of "is of type BookDisplay (whatever the real display is called)". Then in actions you just apply the discount.

I have this working on a site.
> 2 votes

---
Tags: 7, commerce, rules
---


title: Order list: Pay unpaid invoices

text:
# Question
Title: Order list: Pay unpaid invoices
I have created some extra statuses: Paid and Unpaid.

Now they got the functionality and react on the transaction balance perfectly fine. However, on the user site, it is kind of a dumb thing.

Even if the invoice is unpaid, there is no option to pay the invoice from the user --\> orders pages. It looks like you can ONLY pay at checkout; apparently you cannot pay with Paypal later on.

Either way, I am looking for the function that users can pay the amount (or remaining amount) using Paypal WPS. Can any one help me accomplish this?

Secondary, as small addition to this, I would love the user to be able to see transactions that have been done AND the open balance (if any) similar to what the Admin view got.

Can anyone help me accomplish these 2 points? I am not a coder so please keep it simple.

# Answer
> 0 votes
I would ask joachim about the status of this module. He's very good and was interested in finishing it up a little over a month ago. I'm not certain where he is but it's worth a try.

---
Tags: views, commerce, payment-gateways
---


title: Custom fields per page

text:
# Question
Title: Custom fields per page
I need to create a site that is editable for the client. The site is pretty basic: home, about, contact, etc. On each page there are different blocks of text. Like on my homepage, I have different sections like a basic text, "3 reasons" boxes, etc.

I have a content type "pages" with the title and the basic text, which is fine. But how do I create the 3 boxes? Do I create a custom content type for them too? If so, how do I add them on the front page with the text as well?

I heard a bit about the Views module. Would it be useful in my case?

# Answer
> 1 votes
If you are using D6, you need to install the cck module to add custom fields to nodes.

But, if you are using D7, cck has been migrated into drupal core. You can easily create custom fields for each content type at the path **admin/structure/types/manage/{content-type-name}/fields**. For your page content type, go to **admin/structure/types/manage/page/fields**.

I think your case is not concerned with the views module. You can generally check what is views here.

AFAIK, there is no module to create different custom fields per node. We can only create custom fields per content type.
If you are sure you have static numbers of page ( such as page, about, etc. ) and if you will not allow your client to add a new page content, it is possible to create and display different fields upon NID.
You will need to write `hook_preprocess_field` in your theme template.php and `hook_form_alter` in your custom module to show/hide different field upon NID.
Here are some example code snippet.

In your theme template.php,

```
function yourtheme_preprocess_field(&$vars){
    $element = $vars['element'];
    // let's say nid=1 is for your home page
    if($element['#object']->nid == 1){
        // hide custom fields for the other node 2
        if( in_array($element['#field_name'], array('field_1_for_nid_2', 'field_2_for_nid_2')) ){
            $vars['classes_array'][] = 'invisible'; // make display:none in theme css file for the class .invisible
        }
    }
    // let's say nid=2 is for your about page
    elseif($element['#object']->nid == 2){ // do same things for nid=2
        // hide custom fields for the other node 1
        if( in_array($element['#field_name'], array('field_1_for_nid_1', 'field_2_for_nid_1')) ){
            $vars['classes_array'][] = 'invisible'; // make display:none in theme css file for the class .invisible
        }
    }
    // and so on.
}

```

In your custom module yourmodule.module,

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

    if($form_id == 'page_node_form'){ // for the content type 'page'
        $nid = arg(1);
        if($nid == 1){ // when your client edit the page "home", let's say it is nid=1
            // hide custom fields for the other node 2
            $form['field_1_for_nid_2']['#required'] = FALSE;
            $form['field_1_for_nid_2']['#type'] = 'hidden';

            $form['field_2_for_nid_2']['#required'] = FALSE;
            $form['field_2_for_nid_2']['#type'] = 'hidden';
        }
        elseif($nid == 2){ // when your client edit the page "about", let's say it is nid=2
            // hide custom fields for the other node 1
            $form['field_1_for_nid_1']['#required'] = FALSE;
            $form['field_1_for_nid_1']['#type'] = 'hidden';

            $form['field_2_for_nid_1']['#required'] = FALSE;
            $form['field_2_for_nid_1']['#type'] = 'hidden';
        }
        // and so on
    }

}

```

If you don't know about how to write custom module, here is a good start point.
If you don't want custom coding, the best way is to create different content types with different fields for your pages.

---
Tags: nodes
---


title: Comments -> link to node

text:
# Question
Title: Comments -> link to node
i have a content type which display some text image and comments count, in my View module i need to rewrite this comment count to link on this node. How to do it? I though i should create field with nid but i dont know how to do it.

# Answer
> 0 votes
1. Add the "Node ID (nid)" field
2. Add the "Comment count" field -\> Configure field -\> Rewrite results -\> Output this field as link -\> in the "Link path" enter: node/\[nid\]

You can hide the nid field as you probably don't need it.

Make sure the comment count is coming after the nid. You can just reorder them.

---
Tags: nodes, comments
---


title: Content management

text:
# Question
Title: Content management
Is there any way to search and manage content via something more usable than admin/content page? There is no search patterns there, for example. I suppose that if the site will have several hundreds nodes it'll be a quite challenging task to find there what you want. It's even impossible to disable pager there!

So, any solutions?

# Answer
> 3 votes
For management purposes, check Total control and Views Bulk Operations.

For better search check Apache Solr.

# Answer
> 1 votes
You can check CMF module, it has a lot of options to filter from.

Show nodes, comments or both
Filter by author (select from drop-down list)
Filter by author (enter username in AJAX search field)
Filter by user role (shows nodes authored by any user in the selected role)
Filter by user status (active or blocked)
Filter by title or body substring
Filter by node created date (before/after)
Filter by node language
Displays a column in the content list with node creation time
Sort content list by any column: Title, Type, Author, Status, Time

# Answer
> 1 votes
in d7 admin/content is a views page, you can try to expand it: edit that view or better clone it, add filter node title with options **Expose** and **contain**, add author field if you want to select nodes by author, may by add all fields type Taxonomy reference - to select per terms - all **Expose**, if clone add own path like admin/my-admin-nodes, save, open the page - ta-da, more filters to select content nodes

---
Tags: nodes
---


# Question
Title: How to map term name via XPath node feed using xpathparser into Term reference field?
I have an xml feed to import to and mapped to a content type. However, there are fields that are referenced to taxonomy. The fields that are not referenced seems to be working fine and are getting picked up. But those that are referenced to a taxonomy vocabulary are not.

How can I import data from xml from say:

```
<properties>
  <item>
    <refid>1234</refid>
    <propertytype>Apartment</propertytype>
    <!-- ... -->
  </item>
</properties>

```

I want to be able to import `propertytype` to this content type as 'Apartment' as referenced to a taxonomy vocabulary - `Property Types`:

```
Property Types (Taxonomy Vocab)
Apartment
Townhouse
Villa
etc...

```

I've learned that taxonomy referenced fields stores data to a separate table in the database. Does this mean I have to manually do insert query to these tables separately? Or is has anyone encountered the same predicament?

# Answer
You create taxonomy vocabulary by name property types and attach this to the content type you are using for feeds import. Map the fields accordingly.

* `//properties/item` as context
* `propertytype` to the term reference field you have attached to the content-type

But remember just create vocabulary and don't add any terms. Once you do feeds import you can see the terms under property type vocabulary.
> 3 votes

---
Tags: feeds, importing-exporting
---


# Question
Title: Is it possible for an administrator to delete pending user relationship requests (between users)?
I am using the User Relationships module on Drupal 7. I have a relationship, let's call it "Best friends," which requires the mutual approval of both users involved. However, sometimes users send way too many requests, and I would like to delete these manually from an admin account.

I tried creating a view that shows all pending relationships of type **Best friends** and adding *Status link* as a field-- however, the *Status link* returns empty. I also couldn't find any option to list user relationships on the admin screen.

Is there any way to quickly manually delete pending user relationship requests from an admin account?

# Answer
> 1 votes
Here is a Rules/Views heavy solution without any custom code.

---

**Modules Used**

* Views
* Views Bulk Operations
* Rules
* User Relationships
* User Relationship Rules

---

**What To Do**

The User Relationships module ships with an addon module called User Relationship Rules. This will need to be enabled along with the other modules listed above.

Using the Rules module, create a component that removes a pending user relationship. (See additional resources below.)

Next create a View that lists the pending User Relationships as you have done as noted in your comments.

Next you will need to add the Views Bulk Operations field to your view and configure it to use the rules component you created earlier.

---

**Additional Resources**

Johan Falk has several videos you may find useful in setting up your VBO view.

He has also put together a fantastic introduction to the Rules module.

**Views Resources**

Enable the bundled UR-Views module (User Relationship Views) and enable the view titled `user_relationships_browser` at `admin/structure/views`

This enables an example view that has a relationship added for both the Requester and Requestee accounts. You should be able to use these to populate both user fields for your Rules component.

---

You should end up with a list of pending user relationships with checkboxes. Views Bulk Operations will run each selected item through the Rules component you created allowing an Administrator to delete pending user relationship requests between users.

---

**Exported View - Retrieves Both Requester and Requestee UID's**

```
$view = new view();
$view->name = 'user_relationships_browser';
$view->description = 'Shows someone\'s related users';
$view->tag = '';
$view->base_table = 'user_relationships';
$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'] = 'Relationships';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$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(
  'plural_name' => 'plural_name',
  'name' => 'name',
  'changed' => 'changed',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'plural_name' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'name' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'changed' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Relationship: User relationships: Requestee user */
$handler->display->display_options['relationships']['requestee_id']['id'] = 'requestee_id';
$handler->display->display_options['relationships']['requestee_id']['table'] = 'user_relationships';
$handler->display->display_options['relationships']['requestee_id']['field'] = 'requestee_id';
/* Relationship: User relationships: Requester user */
$handler->display->display_options['relationships']['requester_id']['id'] = 'requester_id';
$handler->display->display_options['relationships']['requester_id']['table'] = 'user_relationships';
$handler->display->display_options['relationships']['requester_id']['field'] = 'requester_id';
/* Relationship: User relationships: RTID */
$handler->display->display_options['relationships']['rtid']['id'] = 'rtid';
$handler->display->display_options['relationships']['rtid']['table'] = 'user_relationships';
$handler->display->display_options['relationships']['rtid']['field'] = 'rtid';
/* Field: User: Uid */
$handler->display->display_options['fields']['uid']['id'] = 'uid';
$handler->display->display_options['fields']['uid']['table'] = 'users';
$handler->display->display_options['fields']['uid']['field'] = 'uid';
$handler->display->display_options['fields']['uid']['relationship'] = 'requestee_id';
$handler->display->display_options['fields']['uid']['label'] = 'Requestee User ID';
/* Field: User: Uid */
$handler->display->display_options['fields']['uid_1']['id'] = 'uid_1';
$handler->display->display_options['fields']['uid_1']['table'] = 'users';
$handler->display->display_options['fields']['uid_1']['field'] = 'uid';
$handler->display->display_options['fields']['uid_1']['relationship'] = 'requester_id';
$handler->display->display_options['fields']['uid_1']['label'] = 'Requester UID';
/* Sort criterion: User relationship types: Plural name */
$handler->display->display_options['sorts']['plural_name']['id'] = 'plural_name';
$handler->display->display_options['sorts']['plural_name']['table'] = 'user_relationship_types';
$handler->display->display_options['sorts']['plural_name']['field'] = 'plural_name';
$handler->display->display_options['sorts']['plural_name']['relationship'] = 'rtid';
/* Contextual filter: User relationships: Requester user */
$handler->display->display_options['arguments']['requester_id']['id'] = 'requester_id';
$handler->display->display_options['arguments']['requester_id']['table'] = 'user_relationships';
$handler->display->display_options['arguments']['requester_id']['field'] = 'requester_id';
$handler->display->display_options['arguments']['requester_id']['default_action'] = 'default';
$handler->display->display_options['arguments']['requester_id']['exception']['title_enable'] = TRUE;
$handler->display->display_options['arguments']['requester_id']['default_argument_type'] = 'user';
$handler->display->display_options['arguments']['requester_id']['default_argument_options']['user'] = FALSE;
$handler->display->display_options['arguments']['requester_id']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['requester_id']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['requester_id']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['requester_id']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['requester_id']['validate']['type'] = 'numeric';
/* Filter criterion: User relationships: Relationship status */
$handler->display->display_options['filters']['approved']['id'] = 'approved';
$handler->display->display_options['filters']['approved']['table'] = 'user_relationships';
$handler->display->display_options['filters']['approved']['field'] = 'approved';
$handler->display->display_options['filters']['approved']['value'] = '1';
$handler->display->display_options['filters']['approved']['group'] = '0';
$handler->display->display_options['filters']['approved']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['path'] = 'admin/manage-relationships/%';
$handler->display->display_options['menu']['type'] = 'normal';
$handler->display->display_options['menu']['title'] = 'All Relationships';
$handler->display->display_options['menu']['weight'] = '0';

```

# Answer
> 2 votes
No, there is no special administrative pages for managing other people's relationships, but this would be a useful feature.

Have a look at user\_relationships\_load in user\_relationships.module. You could use that to create a list of all of the pending relationships site wide by passing in `user_relationships_load(array('approved' => FALSE));`. You can further filter that by passing in additional information such as the relationship type. UR's views integration doesn't really take an administrators needs into account but you could build this list with views as well.

Once you have that list you can generate delete links that call user\_relationships\_delete\_relationship. Calling that function with the proper RID (relationship ID) will delete those pending relationships for you.

If you don't want to build an admin page to come back to, there is nothing wrong with doing a little clean up directly in the database as long as you're careful and back up everything first.

---
Tags: users
---