title: Support Ticket Module

text:
# Question
Title: Support Ticket Module
Okay, I know that there a quite a few modules that the suit the title that seem to be obvious, but none of them seem to do what I really want. I'm using Drupal 6 for my business website and I'm using Ubercart to sell my product (it's actually a software company). I also want to offer a support ticketing system.

I don't really want to expose any email addresses, I want to be able to allow any staff to see all of the support tickets that have been submitted, and the first staff to see a ticket and answer it gets assigned to the ticket, like normal. I really like the support system that is used on real-debrid.com/support, but solutions like osTicket and ZenDesk seem okay - if only they integrated with Drupal 6.

So if anybody has any suggestions as to what I can use as a support ticket, I would appreciate it if you could tell me.

By the way, in case somebody asks I'm using Drupal 6 rather than Drupal 7 because some of the modules that I need to be use are only available for Drupal 6.

**The Modules That I have looked at** include:

* Support - which you have to configure clients for; that makes it not suitable
* Storm - which has too many options when submitting the ticket
* UC Ticket - which I think only works using emails, which I don't want
* Case Tracker - doesn't seem quite like it's meant for the job

# Answer
Okay, so I guess no one else is going to answer this question, so I've devised my own solution now based on schnippy's helpful answers! Basically, I've decided to use osTicket seeing as though it is a complete solution and I don't think I'll ever find a comparable Drupal Module, not for a long time anyway!

I'm actually quite surprised as well. I've managed to make it look completely the same as the Drupal website and it was considerably easy, especially considering I didn't really know the theme coding...

So there you go. If you're ever in the same boat as me I'd fully recommend osTicket - it is free but very extensive and flexible. Perfect for my business!
> 1 votes

---
Tags: 6
---


# Question
Title: Exclude users from users list in issue tracking
I'm trying to implement an issue tracking application with Drupal.

I have 4 clients and I want that each one of them will be able to access the site and add an issue. I filter the project ID so any client see only his project issues.

The only thing I don't get how to do is to assign an issue.

In the "Issue" content type I created a "user Reference" filed called "Assign To" (which cause to Rules to send an email to the assigned user).

I want to be able to assign an issue to any client, but I want a client to be able to assign an issue only to me.

How can I do that? If I can't exclude some users from the list (say-by role) - do you have any idea about different way to achieve the "Assign To" functionality?

# Answer
> 0 votes
Since your needs are so specific, I think the easiest (and maybe most logical) way to do this is not to restrict the users on the list. Instead, hide the field for all users of a certain role and have the value default to you. And for you, just don't hide it.

You can achieve this in a few ways. It would be very simple to write a custom module to do this. Use `hook_form_alter()` to access your issue form. In that function, use the global `$user` object to check the role of the current user, and if it's your clients' role, set the `'#access'` property to `FALSE` and the `'#value'` to your user id. That's all.

You can probably do this without custom code also. Every field already has a default value in Drupal core. Set the default value for that field to you. Then use a module like Field Permissions to hide the field from your clients.

This achieves what you want without actually messing with the user reference list. That is also an option, but seems like a worse option to me. To do that, you would need a custom `hook_form_alter()` that, depending on the current user's role, would loop through the `#options` for that field and remove any users that aren't you.

---
Tags: users
---


# Question
Title: Use AJAX with form button to clear checkboxes in separate forms
I have a case where I need to have a Clear button on a form that not only clears out the form it's on, but also clears out checkboxes in other forms and clears data from ctools\_object\_cache.

The page is a custom search page created by the apachesolr module. In the sidebar I have multiple blocks that are just 'checkboxes' form elements of taxonomy terms (each block is a separate vocabulary). The checkboxes are used to select terms, which are written to ctools\_object\_cache using #ajax in the form when selected. What I need is to have a Clear button (or link) on the search form that does a few things:

* Clears the search field
* Deletes items from ctools\_object\_cache
* Deselects the checkboxes in the sidebar forms
* Selects a specific checkbox in another sidebar block (labeled "All")

Is it possible to do this using a #ajax button with Forms API? Or do I need to just write it as a separate Drupal behavior in jQuery? I know Drupal forms can be handled in jQuery, but I haven't used it before, so I'm not sure where to start.

Thanks.

# Answer
> 0 votes
In talking to Randy Fay, this will not work for a number of reasons, of which security is a big one. Form API was written to avoid one form modifying other forms (among other things), so I re-architected the form elements to be all in one form instead of separate forms.

---
Tags: forms, ajax, javascript
---


# Question
Title: How do I show the latest poll user hasn't voted on, yet?
When an authenticated user has voted on a poll, I would like to show the next poll where the user hasn't voted on.

How should I implement that?

# Answer
> 0 votes
I think I figured it out. I copied the hook\_block\_info and \_view from the poll module to my own module and modified the query a bit. It basically now takes any poll that a user hasn't voted on or hasn't voted on during this session. I don't have voting for anonymous enabled.

```
function mycustom_block_info() {
  $blocks['recent']['info'] = t('Most recent poll not voted on');
  $blocks['recent']['properties']['administrative'] = TRUE;
  return $blocks;
}

function mycustom_block_view($delta = '') {
  if (user_access('access content')) {
    // Retrieve the latest poll.
    $select = db_select('node', 'n');
    $select->join('poll', 'p', 'p.nid = n.nid');
    $select->leftjoin('poll_vote', 'pv', 'pv.nid = n.nid');
    $select->fields('n', array('nid'))
      ->condition('n.status', 1)
      ->condition('p.active', 1)
      ->condition(db_or()->condition('pv.chid', NULL)->condition('pv.timestamp', REQUEST_TIME - $lifetime, '<'))
      ->orderBy('pv.chid', 'ASC')
      ->orderBy('n.created', 'DESC')
      ->range(0, 1)
      ->addTag('node_access');

    $record = $select->execute()->fetchObject();
    if ($record) {
      $poll = node_load($record->nid);
      if ($poll->nid) {
        $poll = poll_block_latest_poll_view($poll);
        $block['subject'] = t('Poll');
        $block['content'] = $poll->content;
        return $block;
      }
    }
  }
}

```

---
Tags: 7, polls
---


# Question
Title: How to restrict access to view node revisions with Organic Groups
Does organic groups restrict access to node revisions as well as the nodes themselves?

I have a node page with a view of the revisions output in a block in the sidebar. OG restricts access to the node itself if the user doesn't belong to that node's group however they can see the revisions in the block.

I have tried creating my own OG permission but the organic groups permissions aren't usable in the view restriction. Not sure what else to try?

# Answer
> 0 votes
Rather than worrying about access to the revisions themselves, you might be able to add relationship to the node itself and then a filter to check it the node is accessible.

I imagine there's a better way to do it, but this might work in the mean time.

---
Tags: 7, organic-groups
---


# Question
Title: Is it possible to assign permission to fields?
The idea is that one can assign permission to fields just as node types. Evidently this gives great flexibility to webmasters to account for unforeseen requirements.

The advantage seems obvious: one can simply change permission of a particular field instead of defining a new node type and suffer the burden of migrating or re-creating old nodes into new ones. For example one can make an image field only visible to premium members.

I appreciate your hints about this.

# Answer
> 5 votes
Yeah, You can make use of Field Permissions

> ### 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.
> * Field permissions overview

---
Tags: nodes, users
---


# Question
Title: Meaning of "Query results" and "Rendered output" in Views cache?
Previously I've set the "Query results" and "Rendered output" cache to 1 hour.

What I need is:

* Cache for 1 hour
* Update the cache immediately when related node updated

But when updating node, it takes exactly 1 hour for the views page to be updated.

I'm quite confuse about what is "Query results" and "Rendered output"?

Is "Query results" the `GET` request?

# Answer
> 6 votes
“Query results” are raw data from DB. After fetching data you often do some additional work (modifications, templates) with data and then render it to HTML in some way — so you get a “Rendered output”. For more flexibility you have two levels for caching here.

As I think (*I can be wrong!*) here is no sense to set “Query results cache” time less than “Rendered output cache”.

Your use case, as I can see, to flush View cache immediately after new content added. You can solve it with additional staff Cache Actions, which requires Rules.
For example, you can create a rule with event `"After saving new content"` or `"After updating existing content"`, condition `"Content is published"` and one of the Cache actions.

Cache will be flushed regardless of cache settings in your view.

---
Tags: 7, views, caching
---


# Question
Title: How to redirect a user to the profile of the user they just created
I have a situation where my users of role 'Operator' are in charge of creating new user accounts. Right now, when they create a new user account it just sends them back to the user/create page and displays a confirmation message.

I would like to have drupal redirect the user to the profile page (user/%) of the user that they just created.

I was looking here (http://drupal.stackexchange.com/questions/14993/how-can-i-do-a-custom-form-redirect-on-the-user-registration-form) but can't figure out how to get the user id of the user that the 'Operator' created and not the user id of the 'Operator' them self.

# Answer
Here is Form API solution for that:

```
/**
 * Implements hook_form_FORM_ID_alter().
 */
function YOUR_MODULE_form_user_register_form_alter(&$form, &$form_state) {
  // Check if user has permission to add new user
  if (user_access('administer users')) {
    $form['#submit'][] = 'YOUR_MODULE_user_register_submit';
  }
}

/**
 * Submit callback
 */
function YOUR_MODULE_user_register_submit(&$form, &$form_state) {
  if (isset($form_state['values']['uid'])) {
    // Redirect to user page
    $form_state['redirect'] = url('user/' . $form_state['values']['uid']);
  }
}

```

And here is Rules solution:

1. Add event `"After saving a new user account"`
2. Add condition `"User has role(s)"``site:current-user` has role "Operator". I really don't know how to check permission in Rules, so it is not the best solution.
3. Add action `"Page redirect"``user/[account:uid]`
> 2 votes

# Answer
How about a rule? Check the Rules Module for this task. With this you can define what happens after a user registered. For example a redirect or many other actions.
> 1 votes

---
Tags: 7, users, redirection
---


title: Unable to connect to smtp server

text:
# Question
Title: Unable to connect to smtp server
I'm having some problems with sending e-mails from my drupal site. It was working just fine before.

Some information:

The site is using webforms so I checked the issues here: http://drupal.org/node/344668 None of them solved the problem.

The server recently upgraded to a new version of litespeed (maybe this is relevant?)

The site is also using the STMP Authentication module. It's using the gmail smtp: smtp.gmail.com Running on port 587 (so with TLS enabled) Authentication is required and correctly filled in.

Both e-mail addresses are filled in (the default server e-mail address and the e-mail address used by SMTP auth.), both of them are correct addresses in the form of info@sitesdomain.com .

The recent logs show 3 messages:

* Sending mail to: my@emailaddress.com
* Error sending e-mail from site e-mail address : SMTP error: Could not connect to SMTP host.
* Error sending mail from site e-mail to my e-mail address.

The drupal version is 6.2, webforms version is 6.x-3.2 and stmp auth version is 6.x-1.0-beta5

I've checked the STMP Authentication Support issue queue but there are no relevant item there that can help me. And if there are, then there are no answers.

I don't know how to take a look in the stmp log. I wouldn't know where to find it.

Any help would be appreciated.

Thanks,

Mike

# Answer
> 0 votes
So I mailed my hosting provider for some addition information about the server, the logs and such. And it turns out that they did not allow any traffic on port 587 except for traffic going to the google ip addresses. However google has recently changed the addresses for their smtp servers and the hosting provider did not.

So if there is anyone with a similar problem, I suggest you contact your hosting provider to see if they allow traffic to the google ip's on port 857 and if those ip's are correct.

---
Tags: emails
---


title: Facebook plugin

text:
# Question
Title: Facebook plugin
I've been struggling to implement a facebook like button with the send option for days now. I desperately need some help.

Recently I added a facebook like button to all the nodes in my site by using the iframe and editing the node.tpl file. And everything was good.

Unfortunately my client now also wants a send button added to every node. And you guessed it! The iframe is not supported when you want a send button.

So I tried adding the code to the page myself and it failed. I tried using the likebutton plugin. That failed too.

So now I'm using http://drupal.org/project/fb\_social the 6.x-2.0-beta4 which works with ctools. And it still does not work! I've been looking for javascript errors but my browser says there are none.

The code does execute however it adds this to the nodes:

```
<div class="fb-like" data-href="http://www.myurl.com" data-colorscheme="dark" data-font="verdana" data-action="like" data-width="350" data-show_faces="false" data-layout="button_count" data-send="true"></div>

```

But there is no button to be found. The div has a width but does not have a height. When I give it one, it is simply empty.

When trying to find solutions to this problem I came across a post that implied that you needed to turn off the HTML corrector in the full HTML filter; this did not work.

So I would like to ask if any of you have ever encountered a problem such as this (and with facebook I'm sure you have) and if you'd be so kind to help me.

# Answer
So the fb social module itself works fairly well.

The problem I had in this case was that there was some leftover javascript SDK code (from previous attempts to get it working) in the page which was conflicting with the new SDK code therefor no buttons showed up.

I ended up using the newer beta version of fb social in stead of the recommended version, it works a lot smoother.
> 2 votes

---
Tags: social-network
---


# Question
Title: Assign field permission to individual users?
Here the idea is to avoid defining dozens of roles to account for delicate permission requirements of users.

Say, on a certain node that has 100 fields, a webmaster may eventually need to define several hundreds of permission sets, many of them are needed for very few users on and ad hoc manner. Being able to define field permissions for particular users gives the webmaster ultimate flexibility and avoids insane proliferation of roles.

I appreciate your hints about this possibility.

# Answer
> 3 votes
You can manage this with `#access` if you're using `hook_form_alter` to make and manage the fields.

> **Description**: Whether the element is accessible or not; when FALSE, the element is not rendered and the user submitted value is not taken into consideration.

Another idea is get help of `access callback` in `hook_menu`

> "**access callback**": A function returning TRUE if the user has access rights to this menu item, and FALSE if not. It can also be a boolean constant instead of a function, and you can also use numeric values (will be cast to boolean). Defaults to user\_access() unless a value is inherited from the parent menu item; only MENU\_DEFAULT\_LOCAL\_TASK items can inherit access callbacks. To use the user\_access() default callback, you must specify the permission to check as 'access arguments'

The idea is to make a function that resolves permissions for individual user for certain pages.

---
Tags: users
---


# Question
Title: how to save taxonomy terms in a custom user registration form in D7?
I've got an Implementation of hook\_form() on a custom page which I use for user registration.

For example I have this field:

```
function popover_form($form, &$form_state){

    // some other fields are left out here to simplify my question

    $form['second']['education'] = array(
      '#type' => 'radios',
      '#title' => 'Afgeronde opleiding',
      '#options' => popover_get_tax_term_options('education'),
      '#default_value' => variable_get('education', NULL),
      '#required' => TRUE,
    );
    return $form;
}

```

Then in form\_submit() I'm trying to do this:

```
function popover_form_submit($form, &$form_state){
  $edit = array(

    // some other fields like username, email etc are also left out here.

    // field_firstname is a simple string and works.
    'field_firstname' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['first']['field_firstname']))),
    // education doesn't work ( because it is a taxonomy term ? )
    'education' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['second']['education']))),
  );
  user_save(drupal_anonymous_user(), $edit);
}

```

so either I need to change my submit handler because taxonomy terms are saved differently or I need to update the standard user edit 'view' ( $sitename/user/1/edit ) so the taxonomy terms become visible? Or I'm doing something else wrong?

**EDIT:** I also found out that it is needed to connect taxonomy terms with the user on the `admin/config/people/accounts/fields` page before you can get this to work.

# Answer
> 3 votes
The column name for a taxonomy term reference is `'tid'` rather than `'value'`, if you just change that your code should work:

```
$edit = array(
  'field_firstname' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['first']['field_firstname']))),
  'education' => array(LANGUAGE_NONE => array(array('tid' => $form_state['values']['second']['education']))),
);

user_save(drupal_anonymous_user(), $edit);

```

---
Tags: 7, users, forms
---


title: CSRF on module forms for anon users

text:
# Question
Title: CSRF on module forms for anon users
My module has 2 small forms which allow visitors to submit certain information.

Problem is when I am not logged in, no CSRF token is being added to the forms - so anonomous users/everyone are bypassing the CSRF. Can't find any documentation on this issue, could anyone point me in the right direction so i can get my CSRF tokens?

It is a requirement of my security testing that all forms include CSRF.

# Answer
If you look at `drupal_prepare_form()` it says

> since tokens are session-bound and forms displayed to anonymous users are very likely cached, we cannot assign a token for them.

If you do want to go ahead with this, the following works when quickly tested with the default search and comment forms.

```
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if (!isset($form['#token'])) {
    $form['#token'] = $form_id;
    $form['form_token'] = array(
      '#id' => drupal_html_id('edit-' . $form_id . '-form-token'),
      '#type' => 'token',
      '#default_value' => drupal_get_token($form['#token']),
    );
  }
}

```

Be careful about page caching however (and a reverse proxy if you use one) if you do go down this road.
> 2 votes

---
Tags: tokens
---


# Question
Title: How to use a view as a search result page with facets?
I've created a pretty nice view with faceted filters following this guy's tutorial. It's basically a cheap way of doing getting the faceted feature without having to set up Solr.

The problem I have is that I would actually like to pre-query the index with some search terms from the homepage with a search form...basically:

1. search for a term and get redirected to the view with the facets.
2. use the facets to further filter my nodes.

How would something like this be possible?

Currently I have configured (in the Search API configurations) one server that uses database search as service class, and one Index hooked to that server, which indexes different fields (Content type and three different taxonomy terms) which are exposed as search facets in the view.

Number 2 is basically covered: I have a view page where all the nodes are listed and can be filtered through the facets... what I want is for the users to get to the front page, enter their search query (could have autocomplete or not, I'll figure later) hit "submit" and find all their search results in a page similar to the one I have with the facets... so they can further narrow their search. Kind of like when you look for something in linkedin.

# Answer
For #1 You could try using Rules to catch the term and do a redirect. You could also use hook\_form\_FORM\_ID\_alter to catch it

**Edit:**

You can use "Drupal is initializing" for the event, and add a condition that examines the args coming in. For instance, search/some%20search%query would be:

arg(0) = search arg(1) = some search query

So here are the steps:

Event -\> Drupal is initializing Condition -\> Execute Custom PHP

```
$arg0 = arg(0);
$arg1 = arg(1);
if ($arg0 == 'search' && $arg1 == 'some search query') {
  drupal_goto('search/my-predetermined-facet');
}

```

That should do it.
> 2 votes

# Answer
I wanted to chime in here as I found an alternative way of using Rules to do this.

Plus I feel what I have spent the past 3 days trying to figure out is similar and Johnathan's edited answer led me in the right direction to solve my issue.

> How to redirect to a custom search page with facets ( a custom panel in my case ) from the default search block when using Search API w/ Solr and pre-fill the exposed filter with the term searched for by the user.

Install the Custom Search module. Use the Custom Search module to do turn on a custom search path to something unique like "mysearch/\[key\]" the \[key\] will extract the search term used in the default search box.

Next Use Rules to catch the custom path used by Custom Search, extract the search term(s), redirect where you want to end up, and, most importantly, pre-fill any facets or exposed filters with the "?filter\_name=variable" appended to the path.

**EDIT:** Go to Rules -\> Add New Rule -\> React on event -\> Drupal is initializing -\> Add Condition -\> Execute custom PHP code:

```
$arg0 = arg(0);
if ($arg0 == 'mysearch') {
  return true;
}

```

-- This is to catch the custom search path created with the custom search module above so we only apply the action to someone searching in the default search box.

Add Action -\> Page redirect:

```
search/products?search_api_views_fulltext=<?php $arg1 = arg(1); print_r($arg1); ?>

```

-- You can fill in the query string variables with your facet names or search box ( like I did ) and use the PHP code to extract the incoming arguments you want to pass on to the search page so the facet/search box will be filled in correctly. -- "search\_api\_views\_fulltext" is the name of the exposed filter ( the search box in this case )

The issue I ran into was when I had a facet field that was referenced through the main node. These show up in the Facets Tab like "Product Reference » Status" after adding an additional field to the index on the Fields Tab.

The URL for the Facet was returning { facet\_field\_name=%253ASelected\_facet }. What should be a " : " that is URL encoded as " %3A " is being displayed as " %253A " but only for those fields that are referenced through, not the facets connected directly to the main node. The redirect part fails here and you are unable to pre-select the facet. You can create a manual link in the menu system with the " %253A " and everything works, its just the redirect. I have no answer for this one, so I moved all my facets to the main node and it works just fine.

I hope this helps.
> 1 votes

---
Tags: forms, search
---


# Question
Title: views slideshow jquery interfering with nice menus
Building a site for my friend who is a lawyer. Every time views slideshow changes slides, it resets the hover state for views slideshow. I tried calling the nice menu javascript at the bottom of the page but that did not help.

http://www.tripodi.devserver2012.com/

# Answer
I think it's `z-index` and it's a CSS issue, not a Javascript issue.

Put the following in your CSS sheet (any one of them that's included in your homepage):

```
#views_slideshow_singleframe_teaser_section_slideshow-block_1 {
  z-index: 1;
}

ul.nice-menu li {
  z-index: 10;
}

```
> 1 votes

---
Tags: 6
---


# Question
Title: How do I use a newer version of jQuery with Ubercart shipping quote (Ajax)?
If I use any version of jQuery with drupal/ubercart other than jquery 1.2.6, the ajax comes back from (UPS,Fedex,etc), but never updates the objects on the screen.

How do I use a more current version of jQuery with ubercart?

# Answer
> 1 votes
As it turns out, Ubercart will NOT work with jQuery after 1.2.6 unless you make a small change to an Ubercart module

ubercart/shipping/uc\_quote/uc\_quote.pages.inc

Go to around line 70 which should be the end of the uc\_quote\_request\_quotes function

comment out or replace the broken drupal\_json($return\_quotes);

replace it with the standard PHP json encoder print( json\_encode($return\_quotes) );

# Answer
> 0 votes
The standard way to update jQuery on Drupal is with the jQuery Update module:

> Upgrades the version of jQuery in Drupal core to a newer version of jQuery.
>
> Updates...
>
> * Drupal 5 to jQuery 1.2.6
> * Drupal 6 to jQuery 1.3.2
> * Drupal 7 to jQuery 1.5.2 and jQuery UI 1.8.11

I've got a few old sites using Drupal 6 + Ubercart that work fine with the jQuery update module installed.

---
Tags: ajax, javascript, ubercart
---


# Question
Title: How to get all term descriptions from a specific taxonomy vocabulary?
I have a block that displays an imagemap, and each map area represents a taxonomy term. All terms are in the same vocabulary.

For each map area, I know the term name and want to pull the term description using a Drupal function. I know I can do something like this:

```
<?php $myTerm = taxonomy_get_term_by_name('1'); ?>
<area shape="poly" title="<?php echo $myTerm[0]->description; ?>" coords="1,2,3" href="link2" />

```

But it's quite clunky and means making a function call for every map area.

Is there an API function that gets every term in a vocabulary (like taxonomy\_node\_get\_terms\_by\_vocabulary() but without referencing a node?)...

Or should I make a module for this..?

# Answer
I think you could use taxonomy\_get\_tree or just write your own query\_function with the following query: `db_query('SELECT description FROM {term_data} where vid = %s',$vid)`.
> 0 votes

# Answer
Unfortunately there isn't an API function for that. You can get the terms with an EntityFieldQuery, and you can wrap it in a function for convenience:

```
function taxonomy_term_get_by_vid($vid) {
  $query = new EntityFieldQuery();
  $result = $query
  ->entityCondition('entity_type', 'taxonomy_term')
  ->propertyCondition('vid', (int) $vid, '=')
  ->execute();
  return $result['taxonomy_term'];
}

```
> 1 votes

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


title: How to pass parameters to frontpage?

text:
# Question
Title: How to pass parameters to frontpage?
I have created a frontpage with views. Also I have added the content field called **Volume**. The frontpage is arranged with 10 views and it shows the Volume by descending order, so the latest volume should be displayed in the front page. There is a page that shows the all released volumes, what I want to do that is when we clicking the volume number, then the frontpage will display all contents belongs to that volume number.

e.g. **example.com** will shows the default front page and **example.com/volume/1** will have to show the volume number 1 and so on, but when we take the page example.com/volume/1 it displays the "Page not found " error

# Answer
Have you tried Views Arguments? Parts of your URL (eg. volume/1) can be passed to the View as arguments to control the content displayed (eg. arg '1' tells View to display volume num 1).

Here's a solid tutorial video: http://mustardseedmedia.com/podcast/episode39

And a more detailed explanation on Drupal.org: "Arguments are parts of the URL of a view that can be used to reduce the result-set. A classic example of an argument would be in the case of taxonomy/term/TID or tracker/UID. In the former case, the view is restricted to posts tagged with the associated taxonomy ID; in the latter case, the view becomes restricted to posts by the specified user.

There is also a special case where arguments can be embedded into a View's URL. For example, the URL /user/$arg/track would be valid on any /user/WHATEVER/track URL, and the WHATEVER would be passed into the view as the first argument.

A given view can have multiple arguments. For example, you might have blogs as a view, and provide UID, Year, Month, and Day as arguments in that order. Thus the URL might look like blogs/1/2006/3/15 which would display all blog posts written by user id #1 on March 15th, 2006. Arguments can also be specified as *, which will be interpreted as 'all values'; so in this case, blogs/*/2006/3/15 would show blog posts by ALL users on that date."

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

---
Tags: views
---


# Question
Title: Colorbox + jCarousel + slideshow + compact mode?
I'm looking for a good solution (preferably as one integrated module) that would allow to display images in a multi-value image field in any kind of a lightbox, have a compact mode so that only the first image is shown, display a carousel beneath, and provide slideshow.

I've tried: Colorbox, Field Slideshow, jCarousel, Shadowbox.

Colorbox was nicely integrated with Field Slideshow and provided a pager, but it had a strange bug which causes certain images on the main page beneath to be cloned upon every click within the Colorbox layer. Shadows wins over it even though is paid. Colorbox does not have a compact mode - if I set explicitly number of images to show to 1, all remaining images become unavailable and the slideshow is automatically disabled, otherwise, all of them appear on the node.

A while ago I gave also a try to Lightbox2, but I gave up on it, being unsuccessful at enabling its compact mode.

# Answer
You basically want to output the images inside an HTML list, using, say views, and then install a jQuery plugin to do the slideshow for you.

You *can* use an existing module, however we often find it's easier to just install the jQuery plugin, and initialise your slideshow yourself.

Assuming your view outputs an HTML list, which is pretty easy to get set up, the rest isn't so much a Drupal question as it is a case of following the instructions for the exact slideshow plugin you're using.

We quite like http://jquery.malsup.com/cycle/ which has all the usual options, good documentation, and works well in a lot of different ways.
> 1 votes

---
Tags: javascript
---


# Question
Title: in teaser view, truncated body is displayed instead of summary
My content type has the following settings for body field in "Manage display" tab, for "Teaser" display mode: Label: Hidden; Format: Summary or Trimmed, Trim length: 2000

However, the summary is never actually displayed in Teaser mode, only trimmed body.

For example, in node edit form, after clicking Preview, the Teaser preview clearly displays an automatically truncated beginning of the body. The summary was entered, but is not displayed in preview.

The same in a View, the format is set to show Content, Teaser. Again, the summary is not taken into account, only the body field.

What to check, how to fix this??

# Answer
> 0 votes
In the Manage Display settings for the content type, choose 'Summary or Trimmed' this way if a summary is provided it will display that. Otherwise it will display a trimmed version of the body.

You can download other formatters, i.e one that will strip tags and trim on a word boundary. By default the trimmed function will always split on a paragraph.

---
Tags: 7, nodes
---


# Question
Title: call_user_func_array() expects parameter 1 to be a valid callback, function 'access_denied_node_form' not found
I am unable to edit a page content on my site even with the admin account.I have a page with the profile informations of the committee, I can see that page on the site but when i click the edit button it shows nothing.

I have seen the log and it is showing a error message as:

> call\_user\_func\_array() expects parameter 1 to be a valid callback, function 'access\_denied\_node\_form' not found or invalid function name in /var/www/includes/form.inc on line 377.

# Answer
> 2 votes
We have had this problem before in Drupal 6. It can happen if a content type is deleted, but, for whatever reason, nodes of that type still exist.

In this case, it would suggest that you have (or had) a content type called "access\_denied" and this is no longer there.

First, note down the node ID of the node you're trying to edit. Then, find the node ID in the {node} table in the database, and find what node type it is.

Then, look in {node\_type} in the database to see if your node type is listed there.

If you're missing a node type, you will need to restore the node type before you can edit that node. For example, if you uninstalled a contrib module that provided a particular content type, and that module didn't uninstall cleanly, you might have this issue, so you'd need to reinstall that module to fix things up.

There isn't any way that I know of to find the base module associated with a particular node type, unless it's obvious (the book module provides a node type of book, or similar), but if you are really stuck, you can always delete the node by visiting /node/123/delete - after all, if the base module is no longer present, the node itself probably isn't very useful to you.

---
Tags: nodes, 6, forms
---


# Question
Title: 'hook_field_widget_form_alter' but for markup
I have content type with a term reference field. I want to add some HTML attributes to each option in the select field on the form when creating a new node of that content type.

`hook_field_widget_form_alter()` is the right place for custom code, but not for HTML markup. How I can change display of this field?

# Answer
Attributes on the option tags aren't themeable unfortunately, many of the standard form elements in Drupal are this way. You can theme the wrappers to your hearts content, but the elements themselves are quite locked down.

If it is absolutely necessary to do this you may need to find a way of doing it outside the form API.

You could use the #post\_render on the FAPI options for it to do some manual rewriting of the output markup using regex and whatnot. Not very efficient but probably quicker than writing something from scratch!

The function that handles this is in the includes/form.inc file form\_select\_options. I really wouldn't condone editing it, but it is handy for reference.
> 1 votes

---
Tags: theming, entities
---


title: Drupal 7 IE8 Crashes on website load

text:
# Question
Title: Drupal 7 IE8 Crashes on website load
I just setup a new website, and when I test it in IE8 the browser totally crashes. I tried to scale the site back to almost nothing and it still crashes. It is using the Zen starter kit theme. When I load the main Zen theme it is fine.

http://vento.websitewelcome.com/~getgggco/

# Answer
> 2 votes
I've had similar issues with this, but unfortunately there can be a number of causes. Here are some things to check:

1. **Do you have any modules that utilise flash installed?** There are some issues with certain versions of Flash player that show up on 64-bit versions of Windows with IE8. If uninstalling modules that use Flash fixes the issue, then at least you know more about the problem.
2. **Do you have CSS optimisation/aggregation turned on?** If yes, try turning it off, then see if IE8 still crashes. There is a bug of some sort in the Drupal CSS optimiser, that means that if a CSS page the site is requesting returns a 404 error, then turning aggregation on will crash IE8. If you can, load up the site in another browser and use developer tools (like Firebug, etc.) to see if any of the CSS files are not being loaded. It is probably a good idea to check this regardless of whether you have turned on CSS optimisation.
3. **Do you have JavaScript optimisation/aggregation turned on?** If yes, try the same steps above, but for your JS files. Sometimes complicated JavaScript files cause IE8 to crash too.

Since you say it's a new site, I'm guessing the problem might be related to #2. Best of luck.

# Answer
> 1 votes
It was a background image on the body tag that did it! Once I removed that the site loads.

I moved it to the HTML tag and away it went!

Any ideas why this happened?

---
Tags: theming
---


# Question
Title: Where do I find default value for contextual view filters?
I'm finding the views in 7 to be much more confusing than in 6! I'm trying to create a block that will filter by the node ID of the page the block is embedded in. When I look at the help for Contextual Filters in the block display, it says this:

> Block displays have no source of contextual filters at all; they cannot pull contextual filters from the URL, and often require use of PHP code as a default contextual filter. Various default values can be applied against contextual filters to use filters in a block view. See "Provide default value," under "When the filter value is NOT in the URL" below.
>
> When the filter value is NOT in the URL
>
> Display all results for the specified field If this option is selected, the contextual filter is removed from the view as though it weren't there and all results will be displayed.

My question is, where do I find these choices for default values? When I click on the Add button next to Contextual Filters, I get a dropdown list of all content fields, not a list of options like "Display all results for the specified field".

**Edited to add**

> The Default contextual filter selection is available only if the action to take is "Provide default value" under "When the filter value is NOT in the URL." When that option is selected, a new fieldset will appear that will allow you to choose default contextual filters. Views provides the following default selectors by default

So where is the "When the filter value is NOT in the URL" choice?

# Answer
> 2 votes
You choose a field from that drop down, and the settings you are talking about come up for that field.

These settings are tied to each field, so you can set different fields to come from different sources with different responses if they're not there.

---
Tags: 7, views
---


# Question
Title: Best way to show another site's page via Drupal?
I have a somewhat odd request and, while I hate asking vague questions, I just don't know where to start with this one.

I am developing a website (Drupal 6) for a user that also has a seperate website with some very particular server side apps that allow their staff to do data entry.

The request is that they would like to show a certain data entry form from within the new site. The data entry form can span several pages but once done shows a very definitive End of Form marker. I am thinking that to simply show the form can be done using iFrames, perhaps. But this requested level of integration of having the current site recognize the end of form marker puzzles me.

Any advice on how to:

1. Show the data entry form from the other site.
2. Have Drupal recognize the "End of Form" marker (just some text that says Done, basically) would be very much appreciated.

Googling things like "Drupal show another page" and such doesn't yield much.

# Answer
This is a complex problem that doesn't have any one good solution. The best I have found is a module which is still under development called Wrapper. http://drupal.org/sandbox/dman/1140564 I recommend anyone with this problem start off with that module as it may do exactly what you want.
> 0 votes

# Answer
You should be able to use this. Enable PHP code mode and paste it into a page:

```
<?php
  $curl_handle = curl_init();
  curl_setopt($curl_handle,CURLOPT_URL,"http://www.google.com");
  curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
  curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
  $html = curl_exec($curl_handle);
  curl_close($curl_handle);
  print $html;
?>

```
> 0 votes

---
Tags: 6, forms
---


# Question
Title: Fetching client time using JavaScript and comparing them with values stored in the database
I am developing a module, where:

1. The administrator enters time in (0-23) format.These values gets saved in database.
2. In the front end (for the website users) I need to fetch the current client time (not the server time), maybe using JavaScript, and then comparing it with the stored time (in PHP variables with current time fetched using JavaScript).

I want to do something like the following.

```
// $time_one: from the database.
// $time_two: from the database.
// $currentTime:  client current time.

if (currentTime > $time_one && currentTime < $time_two) {
  // Display some message.
}

```

How can this be done? Can PHP and JavaScript be mixed in the module file?

# Answer
> 0 votes
You can pass values from PHP to JavaScript using code similar to the following one.

```
drupal_add_js(
  array('myModule' => array('time_one' => $time_one, 'time_two' => $time_two)),
  'setting'
);

```

`$time_one` and `$time_two` are the PHP variables that contain the values you fetch from the database.

JavaScript would access those values using the following code.

```
time_one = Drupal.settings.myModule.time_one;
time_two = Drupal.settings.myModule.time_two;

```

# Answer
> 0 votes
Send server time to the client side via js variables: drupal\_add\_js, see example.

---
Tags: 7, blocks, javascript
---


# Question
Title: How to include the comment page number in views "rewrite results"?
I built a custom "new comments" notification system that doesn't rely on the history module (and the super slow queries when viewing nodes with new comments).

When I show nodes with new comments I need to rewrite the link to jump to the first new comment. "node/\[nid\]#new" does that. However, when I have a lot of comments and the first new comment is on the 2nd page (or higher) the link doesn't work. It would need to be "node/\[nid\]?page=1#new", etc.

I don't think the "page" value is available in views. Any tricks I can use?

# Answer
> 0 votes
I used a "Global PHP" field and added this code:

```
<?php
$new = $row->comment_count - $row->nc_count;
$page = floor($new / 50);
$link =  '<a href=node/' . $row->nid;
if ($page > 0){
  $link = $link . '?page=' . $page;
}
$link = $link . '#new>' . $row->nc_count . ' new</a>' ;
print $link;
?>

```

I don't like to use PHP in a view since it prevents caching. This view won't be cached, so it's not a problem this time. The other issue is that it doesn't generate the "pathauto" urls and requires an additional 301 redirect. I tried to use a "node link" variable but they don't seem to get changed to a pathauto link before the PHP field runs.

Any idea how I can render the /node/123 link to a pathauto link?

---
Tags: 7, views
---


title: Twitter follow Drupal

text:
# Question
Title: Twitter follow Drupal
I want to show a list of Twitter users who is following a post, with a button that allows the users to follow them. The list should appear as in the following screenshot.

I have tried using the Twitter, and oAuth modules but I had no luck, so far.

# Answer
It looks like from the output image above you are trying to create a widget that would show a select number of twitter users from either your own followers or from a specific list, etc. I would suggest that this is not a Drupal issue or at least you shouldn't try and treat it as one. You could do this by creating a content type and outputting it as a view using a view template, etc. but thats a lot of database overhead for data that will likely be changing frequently.

The better way to do this is to use a jQuery / javascript plugin that will pull the data as a json file from your source (either a followers feed or your list feed from twitter) and output it directly. You can use any number of existing plugins and widgets available online for this, ex. this one:

http://twittercounter.com/pages/buttons

or roll your own, but further details would be out of scope for this site.

Finally, I'd recommend that you take a look at the site you got that image from first and see if you can figure out what widget it is using, I'd bet that they are using an open widget / plugin that you can then just copy for your own site.
> 1 votes

---
Tags: views, blocks
---


title: Displaying user related content

text:
# Question
Title: Displaying user related content
Im trying to figure out what contextual filters to use but im getting no where, im trying to display content related to that user through an attachment on a page listing all users. So for example if I had user 1 it would display content from user 1 and if the user is user 2 and the attachment would display the content under user 2 and so on.

In the image below, I have the filters and relationships I am using on my attachment. on the page itself I have no contextual filters or relationships on it. I think that is fine since I am displaying just the users themselves, however I could be wrong.

as you can see I have no contextual filters added on to the attachment because I am not sure which one is the correct one, I have tried different combinations with User: Uid and Content: Author Uid but have had no luck.

Any help is appreciated.

# Answer
I was able to achieve what I wanted in views by creating a user type view adding the relationship User: Content authored and going under Format and settings and grouping the fields that I wanted to display, I then went back to those fields under "Fields" and excluded them from displaying so it does not show duplicate fields on the page. No attachment was needed.
> 1 votes

# Answer
You're over-complicating this with the extra relationships.

Drop everything under relationships and make sure your drop your relationship references on your fields as well.

Then just add a contextual filter for Content:Author uid and you should be all set as long as that uid is correctly getting passed to the attachment. You will want to end up with something that looks more like the attached screenshot.
> 1 votes

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


# Question
Title: How do I add social bookmarking icons to my site that only load or look for javascript only when executed?
I have taken a look at the Sharethis and Addthis modules. I have also looked at putting the embed codes directly from twitter and facebook in my site. With each option, my site needs to load the external javasript libraries/images from the third parties on every page load. This doubles(and in some cases, triples) my load times. It can also go sideways if the external site is under a heavy load or offline. It appears there is no way to provide a local copy of the js files/images with these approaches. Can someone suggest a module or a way to add social bookmarking icons to my site that only load or look for javascript only when executed?

# Answer
> 1 votes
Had this same issue on a site when using the Addthis widget and its probably similar for most sharing situations. We tried the addthis module but were also concerned about the overhead involved with loading the module and adding this on every page. We only wanted this to appear on blog posts so we wrote a simple preprocess\_node hook to our module, ex:

```
if ($vars['type'] == 'blog_post') {

    drupal_add_js('http://addthis.com/<script-link-here>.js', 'external');

}

```

And then added our specific call to AddThis in our blog post template. You could also add the script tag in your template as well but its not best practice and wouldn't get cached as well as if its done through drupal\_add\_js.

We considered caching the addthis file locally (which is allowed for by addthis) but resolved that it would be better performance-wise to shift the external load to their servers rather than adding another file hit to ours. This page may also be helpful for addressing performance concerns (for AddThis).

---
Tags: 7
---


title: Node id inside views template?

text:
# Question
Title: Node id inside views template?
How to get the $node-\>nid inside a views template where i'm printing cck fields? $node variable is availabli only in node.tpl.php.

# Answer
> 2 votes
If using **fields** as the display type the data will not be readily available in the display or style output, **but can easily be gotten in the field tpl's by accessing the `$row` object** which has all of the original raw data from the database.

Click on `Theme: Information` when in Views (editing the view in question) and you'll see all of the template recommendations to use. You'll probably want to use a tpl file that involves both the view and field name, e.g. `view-view-field--[view_name]--field-[field_name].tpl.php`.

Once you've created this tpl file you can access the following variables:

* `$view`: The view object
* `$field`: The field handler object that can process the input
* `$row`: The raw SQL result that can be used
* `$output`: The processed output that will normally be used.

You could do something special in `<?php ?>` and then print it like normal. For example, this would print out a specific field from a node that's referenced in a node\_reference field:

`Contents of view-view-field--blog--field-blog-parent.tpl.php:`

```
<?php
$a_referenced_node = node_load($row->{$field->field_alias});
if ($a_referenced_node) {
  print $a_referenced_node->field_some_other_field[0]['value'];
}
?>

```

# Answer
> 1 votes
How is you view configured? With a normal **Node** view, you can just add **Node: Nid** as one of the fields and then it will be available in your fields template.

---
Tags: nodes
---


title: drupal_get_messages always blank

text:
# Question
Title: drupal_get_messages always blank
the drupal\_get\_messages() function is returning nothing when run from `page--front.tpl` in my custom theme. Do I have to add something to page.tpl.php to build this?

I have a print\_r set up and it's always entirely empty even though in the admin panel I've got all types of messages

# Answer
> 5 votes
By the time your page template is built, `drupal_get_messages()` has already been called (by way of `theme_status_message()`, which is called from `template_preprocess_page()`).

Since `drupal_get_messages()` clears the message cache unless the second argument to the function is explicitly set to `FALSE`, and `theme_status_message()` doesn't provide that second argument, the next time it's called the `$_SESSION['messages']` var has already been cleared.

You already have access to `$messages` in your page template file, but if you're looking to get hold of each individual message you'll probably have to do this in a preprocess function:

```
function MYTHEME_preprocess_page(&$vars){
  $messages = drupal_get_messages(NULL, TRUE);
  $vars['message_list'] = $messages;
}

```

# Answer
> 1 votes
if you have a message (error or successful) and it does not appear in your tpl may be you don't print messages in page--front.tpl

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

```

---
Tags: 7, theming
---


# Question
Title: Related Terms Block Based on Terms Fields
I am not sure where to begin except experimenting with contextual filters which is not getting me very far. I am trying to display taxonomy terms in a block based on if a certain field has the same info that is on the same taxonomy page.

For example

```
Current term page = Radioshack
Radioshack has the fields:
Term Field City: San diego
Term Field Type: Electronic

And the terms I want to list would be
Term: Frys Electronics
Term Field City: San Diego
Term Field Type: Electronics Store

Term: Best Buy
Term Field City: La Jolla
Term Field Type: Electronics Store

```

So if you notice they all have the same type which is electronic store so it would display those 2 terms on the current page which is radioshack and any other terms with the same type electronics

# Answer
I was able to get this done by adding my code in into my contextual filter which would be Taxonomy Term:\[You term field name\].

This is the code I used.

```
$path = drupal_get_path_alias($_GET['q']);
$path = explode('/', $path);
$termname = array_pop($path);
$termname = str_replace("-", " ", $termname);
$terms = taxonomy_get_term_by_name($termname );
$term = reset($terms);
$term->tid;
$term_list = taxonomy_term_load($term->tid);
return $term_list->field_companies_industry['und']['0']['value'];

```
> 1 votes

---
Tags: 7, views
---


# Question
Title: Drupal 7 contexual filter display block based on node reference
I have been going around in circles with this for a few hours now... Time to ask for help!!

I have two Content Types:

1: Book

2: Reader

The `Book` Content Type has a `node reference` field which is a select list of readers create with the `Reader` Content Type.

This is all set up and working fine.

Now the issue with my views:

I have a view with is a block containing the `Reader` fields. What I want to do is have it when the `Book` node is loaded my block shows underneath with the referenced `reader` details. Also if no reader is referenced then no block shows up.

I have spent some time in `Relationship` and `Contextual Filters` but can't get it to work.

The book URL is formatted like this:

books/\[book-title\]

I tired using 'raw value from url' in `Contextual Filters` as setting it to the 2nd argument but that didn't work either.

If anyone can help me out here I would be very much appreciative.

Thanks C

# Answer
> 1 votes
Another way is to 'Provide default value' and set to 'PHP Code'. Then use the following to return a specific portion of the URL. The url argument starts from 0 ($theurl\[0\]).

```
$theurl = drupal_get_path_alias($_GET["q"]);
$theurl = explode("/", $theurl);
return $theurl[1];

```

# Answer
> 1 votes
Create a simple content view of readers add fields and add a contextual filter of field\_book or whatever is the name of reference field and choose option "When the filter value is NOT in the URL" -\> "Provide default value" -\> "Content ID from URL" and save.

# Answer
> 0 votes
Views blocks will not look at path, you need a module like below to pass argument to views block:

```
function mymodule_block_view($delta){
    $block = array();

    $book_id = arg(1);
    //check $book_id is really a book id
    $nodes = views_get_view_result('xxxx', 'yyyy', $book_id);
    if (count($nodes)):
        $block['subject'] = t('Readers');
        $block['content'] = views_embed_view('xxxx', 'yyyy', $book_id),
    endif;

    return $block; //return empty $block will hide entire block
}

```

---
Tags: views, entities
---


# Question
Title: How can I resolve my CGI error during installation of Drupal 7 on WinXp?
I'm installing a local instance of Drupal 7 on my WinXp machine. PHP 5.4 and MySql 5.5 are installed already.

I've unpacked the downloaded Drupal 7 site files into a virtual directory and used IIS 6 to make this directory a PHP site.

However, the result is not encouraging:

> CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
>
> Could not open input file: Files\PHP\php-win.exe

The web address I'm using is:

```
http://localhost/drupal7/install.php

```

Where "drupal7" is the name of my application in IIS.

Any ideas on what the problem might be?

# Answer
As in my comment above, you should try using WAMP server or Acquia Dev Desktop, which uses Apache (more suitable for PHP development).

To install Drupal on Windows, you could install it with Microsoft web platform installer by following this procedure.
> 1 votes

# Answer
Commenters are right : try to use Apache.

About your error, my guess is a there is a path problem with the "Program Files" folder which contains a space which must not have been escaped correctly.

Did you try to change the place of your installation and/or correct the setting for the path to the php executable ?
> 0 votes

---
Tags: installation
---


# Question
Title: How to print the drupal username -without a link to it- inside the node profile?
So far the only thing that works is `$name` wich prints the username with the link.

I´ve tried `$account->name`, and it won´t print anything at all (I´ve tried `$author` and `$account_name;` too, without any luck).

I want to print the username inside their profile usernode in a Drupal 6 installation, but don´t want to print it with the link to it, just the username.

Thanks for your help!

# Answer
I do not have the exact answer you are looking for. However I'd use `get_defined_vars()` in all template files to list the defined variables.

In case you are not a programmer, here's the code.

```
<pre>
<?php
  print_r(get_defined_vars());
?>
</pre>

```

http://php.net/manual/en/function.get-defined-vars.php
> 1 votes

---
Tags: users
---


title: Commerce add to cart while checkout

text:
# Question
Title: Commerce add to cart while checkout
I would like to add some products to my cart while I am on checkout process. The cart appears to be empty at the time. I want to make a selection of some add-on products on the checkout process.

I created my own custom checkout pane(it's a form). Also a submit function.

There are "commerce\_line\_items" in the order object, but then I get an error that says my entity is missing bundle. There is also 'commerce\_order\_total' that includes the totals? so I can't just edit the object/array?

This is how I create my line item:

```
$line_item = commerce_product_line_item_new($product, 1, $order->order_id);

```

This is how I am trying to add it to my order:

```
$order->commerce_line_items['und'][] = array('line_item_id' => $line_item->line_item_id);

```

# Answer
> 0 votes
You likely need to save the line item before adding it to the order. The order total should be recomputed for you automatically on save.

---
Tags: 7, commerce
---


title: Search result pager

text:
# Question
Title: Search result pager
anyone knows how to print all results at search results page?? (no pager)
The default template, print a pager and i don't know where it came from

thanks

# Answer
> 3 votes
You might want to use Search API alongside any other module or you can control search result by views module using search api.

At the other hand, there is a function in search module:

```
pager_query("$select $sort_parameters", 10, 0, $count_select, $arguments);

```

And you could copy search module in custom directory (sites/all/modules/custom) and modify this line as you wish. So that your modifications will not be erased when you will try to update your core or modules.

---
Tags: 7, search
---


# Question
Title: How do I apply a custom set of blocks to a custom content type
I have a custom content type I call a Listing. It contains a few hundred fields, and it has a custom template, which renders the node indie the main content area.

How do I configure the sidebar and other blocks to appear/not appear for only this content type and not all content?

# Answer
> 1 votes
This depends on the information you would like to show in the sidebar. If you want to show some static information like for example a help text, then you can create a block in admin / structure / blocks. After you added a new block, you can modify the visibility settings of this Block (and many other settings). For example set the block to to show only on a specific path, content type or whatever.

The other way or case you might have, is to show dynamic data which has a relation to the content you're currently looking at. These dynamic blocks can be built for example with Views or you can create them programmatically in an own module.

The placement of the blocks works like on the first case. But there are other ways to place a block (e.g with Context).

---
Tags: theming, nodes
---


# Question
Title: How can I move custom panels content from a panel to a mini panel (using Features)?
I have created a large number of `new custom content` pieces with a rather complicated configuration for `visibility settings`, etc.

However, I now need to re-use this custom content across a large number of panels (originally, I had thought I would only need it for one panel). So, I want to move the custom content to a mini-panel.

Is there a way to move this content from the panel to the mini panel instead of re-creating it manually? I am managing deployment through the Features module, so all of my panels and mini panels are already in code. However, I opened up `myfeature.pages_default.inc` and there is a huge amount of code; I wasn't able to find the positioning information for the panels/mini-panels.

# Answer
I ended up just doing it manually. Though it took some time, I was unable to find a faster solution.
> 0 votes

---
Tags: panels
---


title: Help with event signup module

text:
# Question
Title: Help with event signup module
I'm looking for a module that allows registered users to signup to events with a few options. I found the "Signup Module" but I can't figure out how to make it work, at least to try it out. So two questions:

1. Does the Signup Module allow for getting different input depending on the event type? For example, if an event is a dinner, I would need to get the menu choice and any dietary requirements.
2. If the above is a yes, how can I make it work? I can't find much documentation around and I'm still a Drupal newbie. If the above is no, can you please recommend a more adeguate module?

Thanks in advance for any hints!

# Answer
> 1 votes
I think you can use the Signup Module for this. The Signup form itself can be modified and changed for your needs. Have a look at the file signup\_form.inc in the signup/theme folder. Copy the theme\_signup\_user\_form($variables) function to your template.php in your theme and start modifying the form.

# Answer
> 1 votes
* Install Date module
* Create a content type "event" and add a date field.
* Go to admin/structure/types/manage/your\_content\_type and in the SignUp settings select enabled and for the Date field to use with signup choose the one you have in your content type.
* The options in the menu admin/config/people/signup are pretty straightforward.
* Create some content for your event content type to see the behaviour of signup

That along with signup documentation should be enough to test the module.

---
Tags: 6, users
---


title: How to add icons for Drupal 6 menus?

text:
# Question
Title: How to add icons for Drupal 6 menus?
I have created some menus with menu block module and placed it in my Drupal 6 site's left sidebar, also used menu icons module to put icon for each menu. But the end result is not satisfying. It demands more padding and text resizing to make it attractive. Can anyone suggest some other technique to add icons for menus in Drupal 6.

# Answer
Try the css way

```
li.menu-mlid-600 > a {
    background-image: url('../images/my_icon.png');
    height: 150px;
    width: 200px;
    text-indent: -9999px;
    display: block;
}

```

But there are other ways. Google it. Here is another way:

How to use images for menu items in Drupal with a simple preprocessing function
> 4 votes

# Answer
I have successfully used menu icons to achieve this. It may require some theming to show up the way you want, but provides a UI for uploading images per menu item, and integrates with image cache/styles.
> 3 votes

---
Tags: routes
---


title: FileDepot sql errors

text:
# Question
Title: FileDepot sql errors
I have recently installed drupal6 and filedepot. Things were working ok, but I was getting some errors come through so I patched it with this http://drupal.org/files/issues/filedepot-group-by.patch

But now I am getting these errors

```
warning: pg_query(): Query failed: ERROR: syntax error at or near "REGEXP" LINE 1: ...FROM nextag_items WHERE type='filedepot' AND tags REGEXP '(^... ^ in /usr/share/drupal6/includes/database.pgsql.inc on line 139.
user warning: query: SELECT itemid FROM nextag_items WHERE type='filedepot' AND tags REGEXP '(^|,)1(,|$)' in /etc/drupal/6/sites/default/modules/filedepot/nexcloud.class.php on line 504.

```

Any one know any thing about them. Or know of a better document managment system for drupal 6?

# Answer
> 1 votes
I assume you're using postgres instead of mysql, AFAIK postgres doesn't support REGEXP.

As an alternative you can look at atrium\_folders but it has not as many features as filedepot and it needs open atrium.

---
Tags: 7
---


title: Get user by name

text:
# Question
Title: Get user by name
I have a user\_reference field in a content type. I want to remove all the users from it except from current user and administrators. Only administrator should see the complete users list.

I started by checking id=f current user is ad administrator.

```
function usersfilter_form_alter(&$form, &$form_state, $form_id) {
     global $user;
     if (in_array('administrator', array_values($user)){
        return; //administrator
     }

```

Now I prepare the array that will be the new users list (can I just remove oart of the users instead?) and get the users list:

```
    $newUsers = array();
    $existingUsers = $form['field_users']['und']['#options'];

```

Finally I go over all the users. If this is the current user name, I'll add it. How can I check if this user is an administrator?

```
foreach ($existingUsers as &$existingUser) {
  if ($existingUser = $user->name) {
    $newUsers[] = $existingUser;
    break;
  }

  // If administrator, add to the list.
}

```

# Answer
> 0 votes
In Drupal you should use the `user_access()` function with a specific permission to find out if the user has a certain level of access, not check their roles directly. The result is the same but it's just considered better practice to use the in-built permissions system.

You can use the `user_load_by_name()` function to load the user if you don't have the account id/user object already, e.g.:

```
$account = user_load_by_name($user_name);
if (user_access('access administration pages', $account)) {
  // Do something
}

```

# Answer
> 0 votes
You can check what roles the user have with code similar to the following one:

```
global $user;

if (in_array('administrator', $user->roles)) {
  // The user is an administrator.
}

```

---
Tags: users
---


# Question
Title: How do I add an edit button on each row of a "tableselect" form element?
How do I add an edit button on each row of a "tableselect" form element?

The code I have is the following one.

```
function example_elements_form() {
    $form = array();
    $header = array(
        'title' => array('field' => 'n.title', 'data' => t('Title')),
        'author' => array('field' => 'u.name', 'data' => t('Author')),
    );
    $query = "SELECT n.nid, n.title, u.name FROM {node} n INNER JOIN {users} u ON n.uid = u.uid". tablesort_sql($header);
    $result = pager_query(db_rewrite_sql($query));
    while($partial_node = db_fetch_object($result)) {
        $options[$partial_node->nid] = array(
            'title' => check_plain($partial_node->title),
            'author' => theme('username', $partial_node),
        );
    }
    if (!empty($options)) {
        $form['nodes'] = array(
            '#type' => 'tableselect',
            '#header' => $header,
            '#options' => $options,
        );
        $form['pager'] = array('#value' => theme('pager'));
        $form['submit'] = array(
            '#type' => 'submit',
            '#value' => t('Submit'),
        );
    }
    return $form;
}

```

# Answer
> 2 votes
Check out http://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node\_admin\_nodes/7

In particular, take a look at the lines that contain "operations". You need to set up a new element in $header to contain a column for the "operations", and then add at least one operation inside $options for each row.

You could either manually add a link to the edit with l(), or you could use module\_invoke('node\_operations') - again, an example of that is shown in the API.

---
Tags: forms
---


title: Form isn't sending POST parameters?

text:
# Question
Title: Form isn't sending POST parameters?
I want to have a single email field form on my page to suscribe to a newsletter and when the user submit this form, to redirect to a complete form (with name, surname...)

The complete form is designed with Webforms module and this single field form with the Form API in a custom module.

I'm using Drupal 6.25.

The problem is when I submit this form; I feel it don't send any POST parameters. I get them in Webform by setting a default value for the E-mail field at %post\[newsletter\_mail\] and it doesn't work.

This is my code.

```
function block_contact_newsletter_form() {
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('Suscribe to Newsletter !')
  );

  $form['newsletter_mail'] = array(
    '#type' => 'textfield',
    '#default_value' => t('Your E-mail')
  );

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

  return $form;
}

function theme_block_contact_newsletter_form($form) {
  $output = '';
  $output .= drupal_render($form['description']);
  $output .= drupal_render($form['newsletter_mail']);
  $output .= drupal_render($form['submit']);
  $output .= drupal_render($form);

  return $output;
}

function block_contact_newsletter_form_theme() {
  $themes = array();

  $themes['newsletter_form'] = array(
    'arguments' => array(),
  );

  return $themes;
}

function block_contact_newsletter_form_submit($form, &$form_state) {
  $link_newsletter = drupal_get_path_alias('node/'.variable_get('webform_newsletter_default_nid', ''), $language->language);
  if (strstr($path_newsletter, 'node/') !== FALSE) {
    $link_newsletter = drupal_get_path_alias('node/'.variable_get('webform_newsletter_default_nid', ''), 'fr');
  }

  $form_state['redirect'] = $link_newsletter;
}

function block_contact_default() {
  $content = array();
  $content[] = '<div class="logo">My.<span>Sitwe</span></div>';

  $items[] = array('class' => 'mail', 'data' => l(t("By mail"), 'node/'.variable_get('webform_contact_default_nid', FALSE)));
  $chat = variable_get('default_chat', "");
  if (!empty($chat)) {
    $items[] = array('class' => 'chat', 'data' => l(t("By chat"), variable_get('default_chat', "")));
  }

  $facebook = variable_get('default_facebook', "");
  if (!empty($facebook)) {
    $items[] = array('class' => 'facebook', 'data' => l("Facebook", $facebook));
  }

  $twitter = variable_get('default_twitter', "");
  if (!empty($twitter)) {
    $items[] = array('class' => 'twitter', 'data' => l("Twitter", 'http://twitter.com/'. $twitter));
  }

// The interesting part for this function begins here.
  $items[] = array('class' => 'newsletter_form', 'data' => drupal_get_form('block_contact_newsletter_form'));

  $content[] = theme('item_list', $items);

  return array(
    'subject' => t("Contacts"),
    'content' => implode('', $content),
    'classes' => array('block-ot-contact')
  );
}

```

Do you have any advice?

# Answer
> 1 votes
You're telling the form to submit via POST, and then once it's done submitting, to redirect to the webform. I think what you intended to do was to make the form submit its data straight to the webform, which you could do with the #action key in the $form array. See http://api.drupal.org/api/drupal/developer!topics!forms\_api\_reference.html/6#action

However, this isn't really a very robust approach. A better approach would be to put together your own webform, and then put that webform into a block. If you need to do any custom processing on the webform, the webform module has its own API and hooks that you can use.

---
Tags: 6, forms, webforms
---


# Question
Title: Calculate shipping cost by weight in Drupal commerce
I've set up a commerce website and I'm trying to calculate the shipping rate.

I have 2 shipping rates: a standard rate and a secure rate. Now I need to increment the price of both these rates by 2 euros if the weight of the **total order** is over 2 kg's (or 2000 grams since the weight is shown in grams).

I followed Randy Fay's tutorial: http://vimeo.com/33838479 but he multiplies the cost by an amount and this is not what I need.

Another related question (calculate shipping by weight) is a little closer but I do not need a cost per pound.

I've tried to create rules to achieve this, but I really don't know how to do any of this.

I also added this patch in an attempt to get things working properly.

Right now, I can't figure out how all the pieces fit together, I'm sure I have everything I need but I could use some help putting everything together. Can someone guide me in the right direction?

# Answer
For Commerce shipping 2.x this is actually pretty simple.

1. Create a calculation rule.
2. Set the condition that the weight for the order is above 2 kg (this can be a bit tricky to do in Rules, but there a plenty of guides how to do it. I believe Randy even shows this in the video you linked to.
3. Select the "add amount to unit price" for a line item and select the shipping line item. You can even select which component to use for this and could create an weight fee price component if you wanted to.

That's it.
> 2 votes

---
Tags: commerce
---


title: Flash HTML markup in views = No output

text:
# Question
Title: Flash HTML markup in views = No output
I want to display a Flash file from a view. I have a content type with a file field that I use to create a node and submit a Flash file (.swf).

Then I use a view to create a block showing the content of these content type nodes. I get the Flash files URL and use the code below to print it - but, no Flash is printed!

Why doesnt this work? It's HTML, isn't it? And Views should support it?

```
<embed id="[title]" width="190" height="285" wmode="transparent" loop="true" scale="noscale" allowscriptaccess="sameDomain" quality="high" bgcolor="#FFFFFF" name="[title]" src="[field_ad_flash]" type="application/x-shockwave-flash">

```

# Answer
This is how I resolved this issue:

1. I set up my view to only print the URL of the flash file.
2. THen I created a views template for that specific field.
3. In that template file i added the HTML above and printed the output - which is the flash files path - as src.
4. Done!
> 1 votes

# Answer
I was using Views PHP for this purposes and of course you have to select url (path to file) to show in file field. Here is the code example (field-flash - an url to swf file and flash-image - it\`s an image used when flash is disabled):

```
<?php if(isset($data->field_field_flash[0]['rendered']['#markup'])) {
     $flash= $data->field_field_flash[0]['rendered']['#markup'];
}
if(isset($data->field_field_flash_image[0]['rendered']['#markup'])) {
     $flash_image= $data->field_field_flash_image[0]['rendered']['#markup'];
}
 ?>
<object type="application/x-shockwave-flash" width="240" height="400" id="movie" align="top" data="<?php print $flash; ?>" >
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="<?php print $flash; ?>" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="wmode" value="opaque" />
<img src="<?php print $flash_image; ?>" width="240" height="400" alt="movie" />
</object>

```
> 0 votes

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


title: Use calendar to display anniversary

text:
# Question
Title: Use calendar to display anniversary
I've a site that collects historical events. I would to use calendar to display a block with events of actual the months (that, obviously, could be events in every year, also in XIX century). How should I set the contextual filter to do this?

Generically I need a calendar of anniversary..

Thanks, Sergej

# Answer
> 1 votes
The date module can be used to set up recurring events. An event on a specific date can occur multiple times. There's a basic tutorial at http://www.bentedder.com/recurring-calendar-setup-in-drupal-7/

---
Tags: views, datetime
---


# Question
Title: How can I unset an option provided by the User Relationships module on the user edit page?
I want to remove the 'Receive e-mail notification of relationship activity' option from the user edit page.

The hook is provided in `user_relationship_mailer.module`:

```
/**
 * Implements hook_form_alter().
 */
function user_relationship_mailer_form_alter(&$form, &$form_state, $form_id) {
  if (($form_id == 'user_register_form' || $form_id == 'user_profile_form') && $form['#user_category'] == 'account') {
    $account = $form_state['user'];
    $access = variable_get('user_relationship_mailer_send_mail', FALSE) && user_relationships_user_access('maintain @relationship relationships', NULL, $account);
    $form['user_relationships_ui_settings']['user_relationship_mailer_send_mail'] = array(
      '#type'           => 'checkbox',
      '#title'          => t('Receive e-mail notification of relationship activity'),
      '#default_value'  => isset($form['#user']->data['user_relationship_mailer_send_mail']) ? $form['#user']->data['user_relationship_mailer_send_mail'] : TRUE,
      '#description'    => t("If checked, we will e-mail you when there are changes to your relationship status with other users."),
      '#weight'         => -10,
      '#access' => $access,
    );
  }
}

```

So I tried to use `unset()` like this in my custom module:

```
/**
 * Implements hook_form_alter().
 */
function MY_MODULE_mailer_form_alter(&$form, &$form_state, $form_id) {
  if (($form_id == 'user_register_form' || $form_id == 'user_profile_form') && $form['#user_category'] == 'account') {
    $account = $form_state['user'];
    $access = variable_get('user_relationship_mailer_send_mail', FALSE) && user_relationships_user_access('maintain @relationship relationships', NULL, $account);
    unset($form['user_relationships_ui_settings']['user_relationship_mailer_send_mail']);
  }
}

```

However, the option is still displayed even after clearing the cache twice. My custom module's weight is set to 777 and the weight of the user relationship mailer module is 0. Any idea what I'm doing wrong?

# Answer
You also don't need to redeclare the $access variable, as you are just removing a field from the form array:

```
/**
 * Implements hook_form_alter().
 */
function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  if (($form_id == 'user_register_form' || $form_id == 'user_profile_form') && $form['#user_category'] == 'account') {
    unset($form['user_relationships_ui_settings']['user_relationship_mailer_send_mail']);
  }
}

```

That should be all you need.
> 1 votes

# Answer
I made a silly mistake: I didn't fully replace the module name in the hook ('user\_relationship\_mailer' is the full name of the module).

The correct code is as follows:

```
/**
 * Implements hook_form_alter().
 */
function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  if (($form_id == 'user_register_form' || $form_id == 'user_profile_form') && $form['#user_category'] == 'account') {
    $account = $form_state['user'];
    $access = variable_get('user_relationship_mailer_send_mail', FALSE) && user_relationships_user_access('maintain @relationship relationships', NULL, $account);
    unset($form['user_relationships_ui_settings']['user_relationship_mailer_send_mail']);
  }
}

```
> 0 votes

---
Tags: forms
---


title: Theming search page

text:
# Question
Title: Theming search page
I'm customizing my search results page. I have found the two templates `search-result.tpl` and `search-results.tpl` but in addition to these there is also a collapsible `fieldset` for advanced search. Where is this coming from? How can I theme the page as a whole? Like do it in a `page.tpl` or `node.tpl` file.

Also `Themer` tells me that this whole node (the search page content) is actually a `block.tpl` file! How is that possible?

I'm on D7.

Here is the screenshot:

# Answer
The collapsible fieldset comes from FAPI and is a different thing than the search results.

It's a regular form, so you have to alter it the form way, via hooks. The basics are here.

```
function your_module_name_form_alter (&$form, &$form_state, $form_id)) {
  if ($form_id === 'search_block_form') {  // Double check it's the correct ID
      // Your custom code goes here
      // Starting with a dpm($form) is often a good idea
  }
}

```
> 2 votes

# Answer
You can of course try the default from theme method like Theming forms in Drupal 7

```
$form['#theme'] = 'foo-login-form';

```

with `hook_form_alter`
> 1 votes

# Answer
The field set you are seeing is added from `node_form_search_form_alter()`, a `hook_form_FORM_ID_alter()` implementation, which uses the following code.

```
  if (isset($form['module']) && $form['module']['#value'] == 'node' && user_access('use advanced search')) {
    // Keyword boxes:
    $form['advanced'] = array(
      '#type' => 'fieldset',
      '#title' => t('Advanced search'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#attributes' => array(
        'class' => array(
          'search-advanced',
        ),
      ),
    );
    $form['advanced']['keywords'] = array(
      '#prefix' => '<div class="criterion">',
      '#suffix' => '</div>',
    );
    $form['advanced']['keywords']['or'] = array(
      '#type' => 'textfield',
      '#title' => t('Containing any of the words'),
      '#size' => 30,
      '#maxlength' => 255,
    );
    $form['advanced']['keywords']['phrase'] = array(
      '#type' => 'textfield',
      '#title' => t('Containing the phrase'),
      '#size' => 30,
      '#maxlength' => 255,
    );
    $form['advanced']['keywords']['negative'] = array(
      '#type' => 'textfield',
      '#title' => t('Containing none of the words'),
      '#size' => 30,
      '#maxlength' => 255,
    );

    // Node types:
    $types = array_map('check_plain', node_type_get_names());
    $form['advanced']['type'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Only of the type(s)'),
      '#prefix' => '<div class="criterion">',
      '#suffix' => '</div>',
      '#options' => $types,
    );
    $form['advanced']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Advanced search'),
      '#prefix' => '<div class="action">',
      '#suffix' => '</div>',
      '#weight' => 100,
    );

    // Languages:
    $language_options = array();
    foreach (language_list('language') as $key => $entity) {
      if ($entity->enabled) {
        $language_options[$key] = $entity->name;
      }
    }
    if (count($language_options) > 1) {
      $form['advanced']['language'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Languages'),
        '#prefix' => '<div class="criterion">',
        '#suffix' => '</div>',
        '#options' => $language_options,
      );
    }
    $form['#validate'][] = 'node_search_validate';
  }

```

To theme a form, you just need to add code similar to the following one.

```
function mymodule_form_search_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['module']) && $form['module']['#value'] == 'node') {
    $form['#theme'] = 'mymodule_search_form';
  }
}

```

The theme function could be one using a template file.
The control statement is necessary to add the theme function only to the search form for nodes. If you need to alter all the search pages, then it should be removed; if you need to change another search page, then change the `$form['module']['#value'] == 'node'` part.

Drupal shows the *Advanced search* fieldset only when the logged-in user has the "use advanced search" permission. That should be kept in consideration, as the *Advanced search* fieldset could not be added to the form.
> 1 votes

# Answer
The search module outputs a render array to $page\['content'\] with two parts

```
$page['content']['search_form']
$page['content']['search_results']

```

You can intercept this array in your theme before it gets rendered and make modifications to it.

i.e in your theme\_preprocess\_page you can do

```
$page['content']['search_form']['#suffix'] = 'Hello'

```

To insert hello below the form. You can also modify the contents of the arrays directly if you want to change the way they behave.

You will need some logic in there to make sure it exists before making changes. But this is just an example.

Hope that makes sense, there is no single template that surrounds these that you can access directly.
> 1 votes

---
Tags: 7, blocks, search
---


title: Adding tabbed content in D7

text:
# Question
Title: Adding tabbed content in D7
What module should I use to make a tabbed block bringing views, custom content or forms?

For example I want to have a News | Twitter | Facebook | Feedback

Which would have a list of news (or a news block), twitter updates etc. Feedback would have a form.

Any suggestions?

# Answer
> 2 votes
It sounds like you are looking for something like the Quicktabs module. I have an implementation here: http://gamebah.com/gsqrd/node/24.

You will make a block for each tab (Twitter, Facebook, Feedback, etc.) and then using Quicktabs (under Admin \> Structure \> Quicktabs) you can add the blocks to a new tab set. It is very self explanatory but if you need more help, don't hesitate to ask.

---
Tags: routes
---


# Question
Title: Can't retrieve POST parameters in Webform
This post is the continuation of this question : Form isn't sending POST parameters?

I now have difficulties to retrieve my parameters in a Webform. In Chrome, I can see that my parameter is sent **but the POST header have a "302 Moved Temporarily" status**

In my webform I try to get my parameter with %post\[email\] but it don't works

Here is my code using the Form API in a custom module (see my old post for more informations)

```
function gn_ot_block_contact_newsletter_form()
{
  $form = array();

  $link_newsletter = drupal_get_path_alias('node/'.variable_get('gn_ot_webform_newsletter_default_nid', ''), $language->language);
  if(strstr($path_newsletter, 'node/') !== FALSE){
    $link_newsletter = drupal_get_path_alias('node/'.variable_get('gn_ot_webform_newsletter_default_nid', ''), 'fr');
  }

  $form['#action'] = base_path() . $link_newsletter;
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('INSCRIVEZ-VOUS A LA NEWSLETTER !')
  );
  $form['email'] = array(
    '#type' => 'textfield',
    '#default_value' => t('Votre adresse e-mail')
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('OK'),
  );

  return ($form);
}

```

I'm using Drupal 6.25. Thank you if you have any advice !

# Answer
> 3 votes
You need to use hook\_form\_alter to change value of full form email field. Just take value from table or session where you save one-field email result per user.

---
Tags: forms, webforms
---


title: Add custom field for menu

text:
# Question
Title: Add custom field for menu
I am having menu like this in drupal which i have used superfish to show

I want each main menu to have a sub-title or description like this in below image

I searched alot online. Also tried for modules. Was wondering if there is a way to achieve that.

# Answer
> 4 votes
You could use the 'not often used' description field already available on each link? Then just add it into the menu links yourself on the front end by overriding the menu\_link theme function.

```
function theme_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';
  $description = '<span>' . $element['#localized_options']['#original_link']['description'] . '</span>';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'] . $description, $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

```

---
Tags: 7, entities, routes
---


# Question
Title: Text format dropdown has dissapeared from edit article form
There is something strange it happened at a certain time. I no longer can set the text format from article (node) edit because the Text format input has dissapeared.

I can configure them from Configuration page but no longer can choose them from edit mode.

I have all permissions over them set up ok.

Please if you have any suggestions help me up.

Strangely, this combo dissapeared from admin/structure/types/manage/CONTENT\_TYPE/fields/body as well

I tried to alter the content type filter using a module but no luck:

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

 $form['body']['und']['0']['#format'] = "full_html";

}

```

# Answer
I have experienced this issue when a rich-text editor is enabled. In my experience, the input format box reappears when the rich-text editor is disabled.
> 1 votes

---
Tags: forms, input-formats
---


# Question
Title: #2013 error when starting the dev desktop
My computer (a Mac) froze while I was working on a site, and I had to switch it off by holding onto the on/off button. When I tried restarting the dev desktop, it kept giving the "Process start timeout" error; when I tried accessing the database, I got the following message:

> `#2013` \- Lost connection to MySQL server at 'reading initial communication packet', system error: 61
> phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

Do you have any idea on how I can resolve this?

I've found a solution, but now I keep getting this message:

> The specified file temporary://fileJ75lqi could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.

# Answer
Your first error seems to be related to a problem with port numbers/bind address of the MySQL server; see this post for a bunch of suggestions for a fix.

The second error is a permissions issue; you need to give your web server user write permissions over the "sites/default/files" folder, for example using the following command:

```
chmod -R 755 /path/to/root/sites/default/files

```

If you don't know how to do it I'd really advise getting someone who does to help you, that's messing about with POSIX permissions and you need to know what you're doing or things can go horribly wrong.
> 1 votes

---
Tags: database
---


title: Memory warning message

text:
# Question
Title: Memory warning message
I keep getting this error message:

> Warning: require\_once(): Unable to allocate memory for pool. in Database::loadDriverFile() (line 1742 of /home/site/public\_html/includes/database/database.inc).

I am not sure what the problem might be. It started when I installed Varnish 3.0; I couldn't get it to work, so I reverted back to my previous configuration with only APC. Now, I keep getting the message, and it is also visible to anonymous users. I have disabled the system help block from all themes, and turned off error reporting, but it still appears.

I also have mod-pagespeed enabled.

# Answer
> 4 votes
Seems to definitely be an APC issue, there's a post about it on StackOverflow which links through to a bug report on PHP.net for precisely this issue.

# Answer
> 3 votes
When we've had that same type of warning, increasing the APC memory limit has helped. Try adding

```
; APC Memory limit size
apc.shm_size=64

```

to the php.ini file and restarting apache. And obviously try increasing if that doesn't solve it.

---
Tags: 7
---


title: Adding metadata to content types

text:
# Question
Title: Adding metadata to content types
I'm trying to add more fields to my content types.
I have a content type called *Cars*, and another called *Airplanes*; I want they belong to a category called "Transportation".

If I want to get a list of all transportation content types, it will return *Cars* and *Airplanes*.

# Answer
Use taxonomy but automatically assign the taxonomy. So anytime you create a car, it's automatically assigned to term "transportation." You can do this with the Taxonomy Defaults module.

> Taxonomy Defaults allows you to assign default terms from any vocabulary to any node-type. The default terms will be pre-selected on the /node/add form, but can be edited.
>
> If a vocabulary is marked as "Hidden" for a particular content type, then that vocabulary will not be shown on the /node/add form and the default terms will be assigned automatically and cannot be edited.

The module is a bit tricky to get at first, make sure you select "hidden" so that the user can't change the default taxonomy.
> 1 votes

# Answer
Take a look at the Bundle Inherit module.

> The main target of the Bundle Inherit module is to allow users to inherit bundles of different entity types from any other bundles of the same entity type. Inheritance could be performed while creating new bundle of some entity type (for example new content type). There are two types (modes) of inherit available:
>
> * Soft: All field instances from existing (parent) bundle will be cloned and attached to the newly created bundle. As for the soft mode it is all.
> * Strict: All field instances from existing (parent) bundle will be cloned and attached to the newly created bundle. After that you will not be able to directly edit inherited field instances in the children bundles and they will be always kept synchronized.
> 0 votes

# Answer
I have a similar concept one of my sites that I built where we track different suppliers and customers, I used taxonomies to separate a node as a either a client or supplier simply with taxonomy. then in my view I used an exposed filter so my user could choose whether they wanted to see a list of customers or a list suppliers.

You can also set multiple taxonomies, cause sometimes a supplier can also be a customer...

Hope this helps you out.
> 0 votes

---
Tags: 6, nodes
---


# Question
Title: How to show hidden fields when using Display Suite module to manage display?
I'm an addicted user of the fantastic Display Suite module to manage the displays of content types. But it sometime happens that after changing the layout of a content type (e.g. Two stacked column) some field doesn't show up. This happened with the location node field solved in this issue by its author.

Now, I'm using the Ubercart Auction module which create a content type called 'product'. When you add a product you fill some auction settings. Then when you load the node it shows a form with auction info and links. This one:

So far so good. Now if I go to admin/structure/types/manage/product/display and change the Layout to **Two stacked column** I get no field to show this form. I get all other fields (body, title, images,...) but no one to show that auction form.

I know that the field is a **form** but I don't know how make available as field.

How can I solve this?

**@lance**: Maybe I should show where are the auction setting in the node. Look this picture:

# Answer
You need to enable Extra Fields, which allows Display Suite to manage module-created fields.
> 3 votes

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


# Question
Title: How to resize an image programmatically when creating node?
I have created a content type with an image field. I have to add the content type programmatically. From my form submit function I can get the `fid` like:

```
$product_image = $form_state['values']['announced_product_image'];

```

**I'm wondering how I can programmatically resize an image when creating a node.**

I have tried:

```
$test = file_load($product_image);
$img = image_load($test->uri);
image_resize($img, 200, 200);

```

But the image is not **saving** as 200x200.

# Answer
> 8 votes
Don't forget to use image\_save() after you've resized it!

---
Tags: 7, media
---


title: Teaser trouble with Views block

text:
# Question
Title: Teaser trouble with Views block
I have a content type of blog that I created a view for and added a display of that view. I created a view block and have it displaying on the front page in the main content block. I decided that I would rather display the blog posts as a teaser instead of the full text but I can't seem to get it to work.

I set up the content type as a teaser under manage display. Should I be able to select the blog teaser as a content type separate from the default blog display under filter criteria in views? Essentially how do I go about setting the content type blog, within my views block to display teasers instead of the full content?

# Answer
Set views to output as Show: Content | Teaser

Then in your content type \> manage display, click the teaser display mode tab, then set the body field to 'Summary or Trimmed'.

Hope that helps.
> 0 votes

---
Tags: views, nodes
---