title: corporate intranet portal with drupal 7

text:
# Question
Title: corporate intranet portal with drupal 7
I am new to drupal. I need to develop a **corporate intranet portal** using drupal 7. I have features like,

* Employee profile creation
* Announcement (Internal announcement, internal opportunities, display new joiners with their photo and info)
* Employee birthday celebration
* Awards
* Discussion board
* Survey
* LMS
* Event calendar

and many more.

I would like to know whether corporate portal can be built with drupal. Please let me know if there any modules for the above requirement or any opensource for this .

Thanks.

# Answer
> I would like to know whether corporate portal can be built with drupal.

Yes it is possible.

> Please let me know if there any modules for the above requirement or any opensource for this.

The question cannot be answered properly without knowing the exact requirements and then digging very deep. The result would be mostly writing a book.

To be honest as you are new to drupal and the way your question "sounds" to me" you are likely to fail with the project. Therefore I would recommend you check out how far open atrium (Drupal 6) or other install profiles / distributions meet your requirements and try to sell one of these (plus customization) to your client. Or at least first look how the authors of open atrium, Drupal Commons and others do things and then ask specific questions.
> 2 votes

# Answer
Since this is a very general question, I can give you a general answer only.

Drupal has a lot of solid features built into core which will help you to build this portal. Probably the most important one is fields and its contrib friend views. There's also a good forum with a number of add on modules which are helpfull to you. The calendar and date modules are very powerfull and flexible to do any date related stuff.

Depending on how flexible you are in just doing things the Drupal way vs. customizing things to your specific needs you have to be prepared to just find the right modules and may write some glue code or do serious custom module and theme developement. Hiring a Drupal pro to sort this out can save you a lot of trial and failure in the long run.
> 1 votes

---
Tags: 7
---


title: RSS feed problem

text:
# Question
Title: RSS feed problem
I'm using feed aggregator to receive RSS feeds, but when I click to update the item it gives me these errors:

```
The feed from News seems to be broken, because of error "Mismatched tag" on line 27.

```

and

```
The feed from News seems to be broken, because of error "XML_ERR_NAME_REQUIRED" on line 28.

```

My feed URL is http://www.sakaaltimes.com/RSS.htm

I run the cron.php file.

# Answer
> 0 votes
Even i have encountered the same issue may times. The best way to evade from such a error is to take the feeds one by one. I mean you can take the feed http://www.sakaaltimes.com/RSS/nation.xml from http://www.sakaaltimes.com/RSS.htm and one by one in this fashion. The feed module by itself is a scrapper so when ever a html tag mismatch occurs it will lead to a error. So have a try at the subfeeds in your given URL.

---
Tags: 7, feeds
---


# Question
Title: How can I view a list of pages to link to in the Navigation module?
I am learning Drupal, and currently creating my first navigation menu. When I click 'Add Link' I can see this view:

This allows me to type a value into the path field to link to, however what I am looking for is a list of current Pages or Content nodes within the site to link to. Surely you cannot be expected to remember the list of current paths that exist within the entire site everytime you want to add something to your navigation menu.

As an example of what I mean, if you create a link in the Wordpress backend, you are shown a dialog which shows a list of current site content to link to as below:

**How can I view a list of pages/content to link to in the Navigation module?**

# Answer
Drupal has designed this a bit differently. Instead of creating content and then creating the menu, you can add a menu link when you create or edit content.
> 1 votes

---
Tags: navigation
---


# Question
Title: Strategies for approaching a client requirement to create quizzes
One of my clients requirements seems to stretch Drupal's boundaries, and is forcing me to think differently on how to approach a problem. I am looking at potential alternatives and strategies to the following requirement so that I can get it right:

My client essentially wants to be able to create quizzes. We are unable to use the popular quiz module since it does not have a Drupal 7 version out yet and in any case, does not allow for multiple questions to be inputted in one go. Explored other module alternatives such as Closed question but they aren't exactly user-friendly.

Getting my hands dirty, my strategy around this is built as follows:

Create a new content type and have it powered via Web-form. The editors can now create questions using the web-forms following an instruction manual about the specific form elements to use. The question set essentially includes : - markup for questions Radio buttons for option fields with the selected one denoting the correct field Feedback field The entire question set is put into a fieldset. Subsequent question sets are created by cloning the first fieldset and once done composing, what we have is a node with webform elements that have been structured to appear as a quiz. The problem:

The editors must follow an instruction manual in order to compose these question-sets and essentially the quiz since they are leveraging the webform. This is also in many ways a pseudo quiz, in the sense, I am leveraging web-forms to simulate what a quiz would appear like and not in essence a quiz. The process is tedious because for each question-set composed, the editors need to click each of these elements and have to fill in data making the process time consuming.

My ideal solution would be to have a content type that would allow the editors to specify a total number of questions in a content type and then have it generate the question-set(question markup, answer options as radio buttons, feedback). This would allow editors to quickly bang in the required content and in the process quickly compose quizzes.

Essentially the question is, if anybody knows how to achieve the ideal solution and if it is actually possible. If not, looking at the problem I have described, what alternatives are possible?

# Answer
I am sure that the latest version of the quiz module has a full flow of functionality with Drupal 7 also. I have used the quiz module to develop a site in Drupal 7 and it worked fine. If you have any issue in working with the Quiz module, i am ready to help you out in solving your issue.
> 1 votes

---
Tags: 7, webforms
---


title: Views programmatically limit results

text:
# Question
Title: Views programmatically limit results
I'm trying to programmatically include a view in a module and need to limit the number of results displayed. I tried something like this, but it doesn't work:

```
$view->display[$display_id]->handler->options['items_per_page'] = 2;

```

I also tried, but neither this worked:

```
$view->display[$display_id]->display_options['items_per_page'] = 2;

```

Any ideas? Or at least some links to Views 2 programmatically implementation?

Thanks

# Answer
You are looking for set\_items\_per\_page()(6), set\_items\_per\_page()(7). Essentially the function does what you are already trying to do, but probably you are calling it on the wrong object, so use the function instead, and Views will ensure it's the right object. :)
> 2 votes

---
Tags: views, 6
---


# Question
Title: Template suggestions for page on specific node id
I created 2 nodes of the content type page for which i want to create a custom template file. In the theme\_hook\_suggestions array there is an element with 'node\__821' so i created the file node--821.tpl.php but it doesn't work.

I also tried page--node--821.tpl.php, this works in that it uses the file but this replaces the page.tpl.php and thats not what i need.

According to http://drupal.org/node/1089656 my filenames should work, but since they don't anyone an idea why? Could it have something to do with the page content type?

# Answer
> 4 votes
You need to do two things before this will work:

* Make sure you have a copy of the original node.tpl.php file in your theme folder (the overridden template file will not be picked up otherwise).
* Clear Drupal's cache

Other than that everything you're doing is perfect so that should fix the problem.

---
Tags: 7, theming
---


# Question
Title: What would be the correct way of adding a link to existing path into admin menu?
What is the correct way to add a link to a menu? I am using Drupal 7 and admin menu module. I would like to add a link to the content menu item so it would be Content

> Content
> Add Content
> Comments

I created a custom module and in the menu hook I put:

```
$items['admin/content/add'] = null;

```

Then in the menu\_alter hook I put:

```
$items['admin/content/add'] = $items['node/add'];

```

Now the menu link appears where I want and when I click browser takes me to the admin/content/add but instead of showing the different options for creating node there's a text saying: You have not created any content types yet. Go to the content type creation page to add a new content type.

If I go to node/add I can see the different options to add different nodes.

So my approach seems to be wrong. What would be the correct way of adding a link to existing path into admin menu?

# Answer
I think the easiest way to do this would be to create a fully fledged menu item and simply forward it on to the `node/add` page using `drupal_goto()` as the `page callback`:

```
function MYMODULE_menu() {
  $items['admin/content/add'] = array(
    'title' => 'Add Content',
    'access arguments' => array('administer nodes'),
    'page callback' => 'drupal_goto',
    'page arguments' => array('node/add'),
    'weight' => 10 // Use this property to control where in the menu the item will appear.
  );
  return $items;
}

```
> 2 votes

---
Tags: 7, routes
---


# Question
Title: can't save search box configuration under themes>config
I made a custom theme based on Zen. In my custom theme (and under stock Zen theme as well) there is a problem with enabling my search form. When I tick the checkbox that says "search" box under admin\>theme\>customtheme\>config\>Toggle Box and click save, the page refreshes and I notice that the checkbox at "search box" is unticked again. Obviously this results in me not being able to show the search form.

Here's the code from my page.tpl.php file.

```
<?php if ($search_box || $primary_links || $secondary_links || $navbar): ?>
    <div id="navbar"><div id="navbar-inner" class="clear-block region region-navbar">
        <a name="navigation" id="navigation"></a>
        <?php if ($search_box): ?>
           <div id="search-box">
              <?php print $search_box; ?>
           </div> <!-- /#search-box -->
        <?php endif; ?>

```

# Answer
Have you updated the theme\_settings.php file of your subtheme, along with template.php?

theme\_settings.php is where the search box toggle on the the config page is specified, so my guess is that the error is there.

Another quick check, if you edit the settings on the parent Zen theme, do those save and cascade down into the subtheme?
> 0 votes

# Answer
I had the same problem - answer: Search module is **not** enabled by default! So

* go to admin/build/modules, scroll down to 'Search' and tick the checkbox.
* Then go to admin/user/permissions, scroll down to 'Search module' and set permissions for Anonymous and authenticated user (and any other type of users you might have configured and want to give this permission to).
* Finally, go over to admin/build/themes/settings/\[your-theme-name\] where you will find that the 'Search box' checkbox is now tickable.

You should now see the search box - if you don't , flush caches!
> 1 votes

# Answer
Is it by any chance the same issue as mentioned in:
> 0 votes

---
Tags: 6, search
---


# Question
Title: How do you add a custom search box at code level?
I have a Drupal 6 site that runs Apache Solr. I need to programmatically add a search form to a custom block that is created by code.

Here is what I'm using:

```
  $form = array();

  $form['#action'] = 'sitesearch/';

  // search form
  $form['keys'] = array(
    '#title' => NULL,
    '#type' => 'textfield',
    '#value' => t('Search for questions and answers'),
  );

  // add in the click in erase routine
  $form['keys']['#attributes'] = array(
    'class' => 'NormalTextBox txtSearch',
    'onblur' => "if (this.value == '') {this.value = '" . $form['keys']['#value'] . "';} ;",
    'onfocus' => "if (this.value == '" . $form['keys']['#value'] . "') {this.value = '';} ;"
  );

  $form['submit'] = array(
    '#value' => t('Search'),
    '#type' => 'submit',
    '#attributes' => array('class' => 'filtered-search-form-submit'),
  );

  return $form;

```

When I submit the form I get to the search results page but it's blank, as if nothing was searched. Any ideas or guidance would be great.

# Answer
> 0 votes
I'm pretty brain-dead. I just set up a custom submit handler for a custom form for search to redirect after form submission to the search results page with the right URL, e.g., passing the query and filter in manually.

---
Tags: 6, forms, search
---


# Question
Title: positioning sticky field using hook_form_alter in drupal 7
I'm trying to remove the sticky option from the option bar and adding it to the user form.

```
function vacancies_form_vacature_node_form_alter(&$form, &$form_state, $form_id) {
// remove sticky field from default (option) location
unset($form['options']['sticky']);

//create new sticky field
$form['sticky'] = array (
    '#type' => 'checkbox',
    '#title' => 'Top vacature',
    '#default_value' => $form['#node']->sticky,
    '#weight' => -1,
);

dsm($form);

```

}

Weight of other elements go from `1` to `14` so `-1` should put this form element on top. But with the code above it shows up at the end of the form.

How do I put the sticky button in the middle of my form?

# Answer
> 1 votes
This code:

```
$form['sticky'] = array (
    '#type' => 'checkbox',
    '#title' => 'Top vacature',
    '#default_value' => $form['#node']->sticky,
    '#weight' => -100,
);

```

works for me just fine. I don't know what's happening in your node edit form, but for me title field had #weight equal to -5, so obviously this item with weight -1 wouldn't show up on top.

---
Tags: 7, forms, hooks
---


# Question
Title: Illegal choice detected with Unlimited Image field
I have an image field in a content type that uses the image widget. Whenever I select an image to upload, it gives the error: "An illegal choice has been detected. Please contact the site administrator."

The image thumbnail appears as normal, however, there is no way to submit the form (returns errors) and you can't add more images.

I haven't made any changes to the form (just some CSS stuff for presentation).

How can I fix this?

# Answer
> 2 votes
I had similar issue, fixed it by changing one of my required field from radio buttons to "select list".

---
Tags: nodes
---


# Question
Title: Translate text on the front page with t()
Have a multilingual site with English and French, I have all my static text on my page--front.tpl.php wrapped with a t(), cleaned my cache and refreshed the strings, but still i cant find the strings to translate them. I'm I doing something wrong here? example of code on page--front.tpl.php

```
<div class="class-example">
        <p><a href="node/add/poll" class="create-nav-dim cr-nav-bg mb10"><?php print t('Create New content'); ?></a></p>
        <h2 ><?php print t('OR'); ?></h2>
        <p><a href="#" class="example-class"><?php print t('check our content'); ?></a></p>
      </div>

```

# Answer
You need to activate the locale module.

Under "Admin \>\> Configuration" you find a section regional and language.
Add a new language, and set it as default language; after that, you can use the 'translate interface' to translate the strings wrapped in `t()` for your new language.
> 4 votes

# Answer
After you've activated `locale.module`, you need to **switch to another language and view the page in that language** — until you do that, the strings to translate aren't added to the database.
> 3 votes

---
Tags: i18n-l10n
---


title: Block rendering

text:
# Question
Title: Block rendering
Today I found a working php snippet to load block content into a node:

```
<?php
$block = block_load('block', '1');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;
?>

```

Sadly I am not that good with php, and I could not figure out what to add, to remove the block title from rendering. I have no need for that.

Help would be awesome! Thank you in advance!

# Answer
You need to empty the `subject` of the block which is what Drupal uses to display the title:

```
// Set the block ID
$bid = 1;

// Load the block
$block = block_load('block', $bid);

// Get the output array
$output = _block_get_renderable_array(_block_render_blocks(array($block)));

// Set the block subject to an empty string
$output['block_' . $bid]['#block']->subject = '';

// Output
print render($output);

```
> 0 votes

# Answer
I think you can remove the title, if you go directly in the block config page and in the title section you add `<none>`
> 0 votes

---
Tags: nodes, blocks
---


# Question
Title: the difference between the drupal login "block" and mysite/user/login
I trying to understand the difference between the default Drupal 7 login block and the login provided at mysite/user/login.

From my own understanding, it would appear that the default login block provided by Drupal 7 only logs you into the web interface and the login provided at mysite/user/login is a page provided for you to login through your website.

I have come to this conclusion because if I log out of the web interface and try to login at user/login, nothing happens (I enter my credentials, but nothing happens).

This is my understanding.

If my understanding is wrong, I would appreciate it if someone could please correct me. If I am correct, could someone please provide a good tutorial that teaches one how to use the login page to validate a user and "transfer" the user to a validated state?

Thank you.

# Answer
> 2 votes
There is no such difference. Both forms provide the same input fields and use the same validation and submit handlers. The one is generated by user\_login(), the other is generated by user\_login\_block().

---
Tags: users
---


title: Drupal Mysql SSL Connections

text:
# Question
Title: Drupal Mysql SSL Connections
Cannot seem to find solid literature on using mysql-ssl connections with either Drupal 6 or Drupal 7. Piece of cake with wordpress. Is this a possibility, if not why?

# Answer
> 4 votes
The Drupal 7 database layer uses PDO which prior to PHP 5.3.7 did not support MySQL with SSL.

Assuming you're using PHP 5.3.7 or later there is a patch available for Drupal to allow "arbitrary PDO options" to be used, which would include the ability to specify an SSL option.

See this discussion for a fair bit more information and links to the issues on php.net.

**EDIT**

For Drupal 6 you can change the `mysql_connect()` line in includes/database.mysql.inc to:

```
$connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, MYSQL_CLIENT_SSL);

```

Although you should really turn this into a patch and apply it to the includes/database.mysql.inc file as hacking core is never a good idea.

---
Tags: database, ssl
---


# Question
Title: Issues with regions using the Spaces Dashboard module
I have been facing many issues trying to use the Spaces Dashboard module (part of the Spaces module).

I have setup a site with pressflow, OG, Context, Spaces, and Features; I got everything working well together.

I have been trying to implement the Spaces Dashboard feature, so group managers can manage their own group front page with an easy to use drag'n drop UI.

* Through context, I have been able to create a default dashboard with some enabled blocks.
* I have configured all spaces\_dashboard settings and saved them in my default group space so every new group is shipped with those settings.
* I have done some workaround in my template to get the context working with my **Zen subtheme** (based on #26 at http://drupal.org/node/633778).
* I can now drag and drop blocks from my dashboard edition block to my theme regions.
* I followed this tuto for setting up the UI (not really fully working with zen subtheme) : http://www.leveltendesign.com/answer/adding-customize-dashboard-magic-your-drupal-theme
* I can currently drop blocks in ANY of the theme's regions even the disabled ones. I'm not sure of where does the problem comes from. The region settings are setup in the module config page at both site level and spaces level.
* I cannot drop blocks in empty regions. ("Empty" meaning any region on the page that does not contains any block yet.)
* If I move a block out of a region and there is no block anymore in the region I cannot move it back in the region. I'm not sure if this is a CSS, JS or module issue.
* I found that by adding div for empty regions I can get some empty regions to work, but this is just a html trick and not a solution. `<div class="region region-content-top"><div class="section ui-sortable"><a class="context-block-region" id="context-block-region-content_top">Content top</a></div></div>`
* Finally, the 'save' button from the dashboard block doesn't save any modification to the dashboard in the current space nor in the global settings.

# Answer
In case anyone still cares about this ...

You cannot drop blocks into empty regions, because they are empty. You can tell the dashboard settings to show all regions always, and then use CSS to hide the regions you dont want to be droppable ever via display none in CSS i think. Thats what I did.

The save button issue you would have to debug with Firebug and maybe a php profiler. You need to be sure the zen theme has allllll the html and css needed by the Gingko theme as lined out in that blog post above for the various JS actions to get processed correctly for the dashboard editor.

I followed the same tutorial for a Zen subtheme, spaces, dashboard and spaces\_node and got it all working -- migrating to D7 looks like a pain in the future.
> 2 votes

# Answer
Please check the Homebox module. Homebox is also used on drupal.org to manage user profiles. Here is another good article about implementing dashboards: http://www.lullabot.com/articles/building-drupal-dashboard
> -4 votes

---
Tags: features, 7
---


# Question
Title: Ubercart - different payment gateway settings per product
i want to be able to set one product as UC\_CREDIT\_AUTH\_ONLY, meaning no charge will be made now. in the admin i can only change this setting globally, meaning that all my products will be charged UC\_CREDIT\_AUTH\_ONLY. How can i get this to work only for one?

currently i'm using paypal website pro as gateway, but if i have to, i'll switch to athorize.net.

using drupal 6 + ubercart 2

Thank you.

# Answer
There is a sandbox project for multiple gateways. I attempted to contact the developer a few days ago, but haven't heard back.

http://drupal.org/node/1106004

you select the profile in the product edit. Its not complete but close.
> 1 votes

---
Tags: ubercart, payment-gateways
---


# Question
Title: How can I access the node ID when writing PHP into a block?
I see that when I am creating a block through the drupal admin I can use PHP, in addition to plain text & html. Is there a variable in scope that I can use to access the node id?

```
<?php echo my_custom_function( $node_id, $my_desired_class); ?>

```

# Answer
> 11 votes
You can use the `menu_get_object()` function which will get you the node object for the page, assuming of course your block is being displayed on a node page:

```
$node = menu_get_object();

if (isset($node->nid)) {
  $nid = $node->nid;
  echo my_custom_function($nid, $my_desired_class);
}

```

---
Tags: blocks
---


title: Custom sort criteria for dates in views

text:
# Question
Title: Custom sort criteria for dates in views
I've got a website filled with events. Some events have a start date, others don't. I sort my events by date on the frontpage so the event closest into the future shows up first.

But their are some events with no dates. These kind of events take more than one day/week/month/... so it doesn't make sense to add a (single) date.

How can I make a list, by using views, where the dates with a date show up on top and those without close the list by showing up at the end of the page.

Any suggestions on filters or work-arounds where I can specify this kind of sorting criteria?

# Answer
> 2 votes
I haven't tested this, but I would make two views-- View A includes the events with a start date and View B includes the events with no dates. Then, add View B as the footer to View A. The events will now be shown on the bottom.

# Answer
> 0 votes
I recommend creating your own Views filter handler that checks whether the date is set. You can place this filter above the existing date filter so that results are first sorted by whether the date is set and then filtered by the date, if any.

Creating a Views filter handler isn't for the faint of heart. It involves implementing Views API hooks and writing a custom class that extends views\_handler\_filter.

You can get a better idea of what's involved here, but the article is regarding Views 2, not Views 3. Full Views 3 API documentation is viewable on your site via the Advanced Help module.

---
Tags: 7, views
---


title: Attach JS to tableselect checkboxes?

text:
# Question
Title: Attach JS to tableselect checkboxes?
Using the Drupal 7 tableselect form field, is there a way to attach javascript events to the checkboxes?

I am trying to build a custom pricing table that lets you add different options, which modifies the displayed total. When checking off an option, I need to pass the value through AJAX and return a new total price. Not sure though how to attach events.

# Answer
> 1 votes
The '#ajax' property handling of the tableselect element is broken at the moment. The approach shown by mrryanjohnston *should* work in theory, but I can confirm Kevins observation that it does not do so for checkboxes ('#multiple' = true). It does work for radio buttons, though ('#multiple' = false). The issue is reported as a bug in the meantime.

To me this seems to be just an oversight - looking at `form_process_tableselect()` shows that the line which passes the '#ajax' property on to the created child elements is only present in the 'radios' related `else` part of the if clause, but absent for the default checkbox creation part. Adding the line there fixes the problem on first sight - not sure if it has some negative effects and was left out on purpose, but I doubt that.

As a workaround to avoid patching core, you can register an additional `#process` callback, to be invoked after the default one:

```
$form['some_tableselect'] = array(
  '#type' => 'tableselect',
  '#header' => array('one', 'two'),
  '#options' => your_module_function_creating_options(),
  // Kludge/workaround for broken #ajax handling for checkboxes,
  // register an additional process callback:
  '#process' => array('form_process_tableselect', 'your_module_tableselect_process_callback'),
);

```

Then in your new callback, you add the ajax property to the created checkboxes directly:

```
function your_module_tableselect_process_callback($form_element) {
  foreach (element_children($form_element) as $child_key) {
    if ('checkbox' == $form_element[$child_key]['#type']) {
      // Add ajax behavior as desired
      $form_element[$child_key]['#ajax'] = array(
        'callback' => 'your_module_ajax_callback',
        'wrapper' => 'some-wrapper-id',
      );
    }
  }

  return $form_element;
}

```

Note that this only covers the individual checkboxes per line - the 'select all' checkbox in the header gets added via JavaScript later on, and can not be 'fixed' like this :/

# Answer
> 1 votes
I'm pretty sure this is quite doable with the #ajax key in a renderable array. From http://drupal.org/node/752056:

```
<?php
/**
 * AJAX-enabled select element causes replacement of a set of checkboxes
 * based on the selection.
 */
function ajax_example_autocheckboxes($form, &$form_state) {

  $default = !empty($form_state['values']['howmany']) ? $form_state['values']['howmany'] : 1;

  $form['howmany_select'] = array(
    '#title' => t('How many checkboxes do you want?'),
    '#type' => 'select',
    '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4),
    '#default_value' => $default,
    '#ajax' => array(
      'callback' => 'ajax_example_autocheckboxes_callback',
      'wrapper' => 'checkboxes-div',
      'method' => 'replace',
      'effect' => 'fade',
    ),

  );

  $form['checkboxes_fieldset'] = array(
    '#title' => t("Generated Checkboxes"),
    // The prefix/suffix provide the div that we're replacing, named by
    // #ajax['wrapper'] above.
    '#prefix' => '<div id="checkboxes-div">',
    '#suffix' => '</div>',
    '#type' => 'fieldset',
    '#description' => t('This is where we get automatically generated checkboxes'),
  );

  // Complete example below!

```

Basically, define what function is going to be triggered by what action (in this case, a checkbox toggle). With the above code, define a function such that its signature is `ajax_example_autocheckboxes_callback`. Voila.

# Answer
> 0 votes
@Kevin try this

```
function a_form($form, &$formstate){
  $header = array
  (
    'name' => 'name',
    'surname' => 'surname',
    'citizen_id' => 'citizen id',
  );

  $options['1'] = array(
    'name' => '1name',
    'surname' => '1surname',
    'citizen_id' => '1citi',
  );

  $options['2'] = array(
    'name' => '2name',
    'surname' => '2surname',
    'citizen_id' => '2citi',
  );

  $form['tableselect_field'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#multiple' => FALSE,
    '#ajax' => array(
      'callback' => 'an_example_callback',
      'wrapper' => 'a-div',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );

  $form['ajax_div'] = array(
    '#type' => 'markup',
    '#prefix' => '<div id="a-div">',
    '#markup' => date('y-m-d h:i:s'),
    '#suffix' => '</div>',
  );

  return $form;
}

function an_example_callback($form, $form_state) {
  return $form['ajax_div'];
}

```

# Answer
> 0 votes
There is a new patch for ajax on tableselect checkboxes.

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


title: Expose table in Drupal View

text:
# Question
Title: Expose table in Drupal View
How can I expose a table with out primary key in Drupal view 3 I have table st as uid, gid, percentage.

```
attendance_views_data() {

$data['attendance_percentage']['table']['group'] = t('Attendance');

    $data['attendance_percentage']['percentage'] = array(
        'title' => t('Attendance percentage field'),
    'group' => t('Attendance'),
        'help' => t('Attendance percentage field.'),
        'field' => array(
            'handler' => 'views_handler_field_numeric',
            'click sortable' => TRUE,
            ),
        'filter' => array(
            'handler' => 'views_handler_filter_numeric',
            ),
        'sort' => array(
            'handler' => 'views_handler_sort',
            ),
    );
}

```

The above code does not work as I can not see percentage field in my view feild.

# Answer
> 0 votes
A problem in your code is that you are missing

```
return $data;

```

You also need to define the base for the table:

```
$data['attendance_percentage']['table']['base'] = array(
  'title' => t('Attendance'),
);

```

Should be enough.

Also remember you need to clear cache.

---
Tags: views
---


# Question
Title: Variable scope problems in eval()'d code + included PHP-file
In Ubercart's **Conditional actions**, I can add my own PHP code to an action called "*Execute custom PHP code*". In this PHP code, I can use two variables: `$order` and `$account`.

To test it, I put some codes in the beginning of the textarea:

```
drupal_set_message('before including file....');
drupal_set_message('isset($account): <pre>'.var_export(isset($account), TRUE).'</pre>');
drupal_set_message('isset($order): <pre>'.var_export(isset($order), TRUE).'</pre>');
drupal_set_message('isset($order->products): <pre>'.var_export(isset($order->products), TRUE).'</pre>');

```

OK, it outputs the following:

```
before including file....
isset($account):
true
isset($order):
true
isset($order->products):
true

```

That's correct, so I can use `$account` and `$order` variables without a problem. BUT I would rather like to put my codes into a separate file and include it here - so I would like to use the mentioned `$account` and `$order` variables in the file.
BUT after including the file, these variables don't exist in the file's scope, even if I type the line `global $account, $order;` at the beginning of the file!

So for example there's a module called 'test\_module', and the file is in the module's php directory, its name is '`testPurchase.inc`'. I put the following code into the custom "*Execute custom PHP code*" textarea:

```
drupal_set_message('before including file....');
drupal_set_message('isset($account): <pre>'.var_export(isset($account), TRUE).'</pre>');
drupal_set_message('isset($order): <pre>'.var_export(isset($order), TRUE).'</pre>');
drupal_set_message('isset($order->products): <pre>'.var_export(isset($order->products), TRUE).'</pre>');

$module_name = 'test_module';
$filepath = 'php/testPurchase';
$file_extension = 'inc';

module_load_include($file_extension, $module_name, $filepath);

```

And the content of the `testPurchase.inc`:

```
<?php

// checking the existence of the $account and $order variables in 'testPurchase.inc' file...
drupal_set_message('this is already in the included file....');
drupal_set_message('isset($account): <pre>'.var_export(isset($account), TRUE).'</pre>');
drupal_set_message('isset($order): <pre>'.var_export(isset($order), TRUE).'</pre>');
drupal_set_message('isset($order->products): <pre>'.var_export(isset($order->products), TRUE).'</pre>');

```

OK, the file inclusion is correct, but the result is the following:

```
before including file....
isset($account):
true
isset($order):
true
isset($order->products):
true
this is already in the included file....
isset($account):
false
isset($order):
false
isset($order->products):
false

```

So in the 'testPurchase.inc', the `$account` and `$order` variables don't exist.
But why? Shouldn't the scope be the same?

Is the source of the problem that this code is eval()'d?
**How can I get around this issue, to keep my code in the file, but be able to use the two mentioned variables without the need to define a predicate via my custom module?<br>I'm primarily curious to know the reason why this happens.**

P.S. I've already tried it without using the `module_load_include()` function, with the 'pure' usage of the `require_once()` function, and the result is just the same.

---

**EDIT**: *Let me explain why the occurrance of the mentioned problem of `eval()` in Drupal's to-be-evaluated textbox isn't quite clear to me!*

I don't think this is the way how PHP should work. So I tested it in my own separate files: I created a file with defining some variables in it, and then included another file in the regular way, and after that, I included a file via `eval()` \- in both cases, I checked the existence and value of the earlier defined variables in the included files.
**The result: the scope was the same after including these files - so I could use the earlier defined variables in the included files without any kind of problem!!**

***Let me show you the results of my tests!***

So here comes the first file for testing the variables, where I include the different files via different methods, I think the code is quite clear:

`test_vars_normally_and_eval.php`:

```
<?php

    $variable_1 = 12345;
    $variable_2 = 'Test stuff';

    require_once('test_vars_require_normal.php');

    echo '<hr />';

    $test_eval_1 = '
        $eval_variable_1 = 12;
        $eval_variable_2 = 49;
        echo "<h3><u>eval() - appending var. testing file as a string with file_get_contents():</u></h3>";
        ?>'.file_get_contents('test_vars_require_eval.php');

    eval( $test_eval_1 );

    $test_eval_2 = '
        $eval_variable_1 = 666;
        $eval_variable_2 = 999;
        echo "<h3><u>eval() - including var. testing file with require_once() in eval():</u></h3>";
        require_once("test_vars_require_eval.php");
        ';

    eval( $test_eval_2 );

```

`test_vars_require_normal.php`, the file for a regular inclusion with `require_once()`:

```
<?php

    echo '<h3><u>testing variables after a regular require_once():</u></h3>';
    echo '<b>isset($variable_1):</b><pre>'.var_export( isset($variable_1), TRUE).'</pre>';
    if(isset($variable_1)){
        echo '<b>$variable_1:</b><pre>'.var_export( $variable_1, TRUE).'</pre>';
    }
    echo '<b>isset($variable_2):</b><pre>'.var_export( isset($variable_2), TRUE).'</pre>';
    if(isset($variable_2)){
        echo '<b>$variable_2:</b><pre>'.var_export( $variable_2, TRUE).'</pre>';
    }

```

`test_vars_require_eval.php`, the file which is included via `eval()`:

```
<?php

    echo '<b>isset($eval_variable_1):</b><pre>', var_export(isset($eval_variable_1), TRUE), '</pre>';
    if(isset($eval_variable_1)){
        echo '<b>$eval_variable_1:</b><pre>', var_export($eval_variable_1, TRUE), '</pre>';
    }

    echo '<b>isset($eval_variable_2):</b><pre>', var_export(isset($eval_variable_2), TRUE), '</pre>';
    if(isset($eval_variable_2)){
        echo '<b>$eval_variable_2:</b><pre>', var_export($eval_variable_2, TRUE), '</pre>';
    }

    echo '<hr />';

```

# ***AND THE FINAL OUTPUT IS THE FOLLOWING:***

**testing variables after a regular require\_once():**

**isset($variable\_1):**

```
true

```

**$variable\_1:**

```
12345

```

**isset($variable\_2):**

```
true

```

$variable\_2:

```
'Test stuff'

```

**eval() - appending var. testing file as a string with file\_get\_contents():**

**isset($eval\_variable\_1):**

```
true

```

**$eval\_variable\_1:**

```
12

```

**isset($eval\_variable\_2):**

```
true

```

**$eval\_variable\_2:**

```
49

```

**eval() - including var. testing file with require\_once() in eval():**

**isset($eval\_variable\_1):**

```
true

```

**$eval\_variable\_1:**

```
666

```

**isset($eval\_variable\_2):**

```
true

```

**$eval\_variable\_2:**

```
999

```

# Answer
> 2 votes
This is probably more a PHP than Drupal question.

Anyways the file itself should not be what's executed, instead you should use functions where you can pass variables around.

so your `.inc` should be altered:

```
<?php
function test_purchase($account, $order) {
  // checking the existence of the $account and $order variables in'testPurchase.inc' file...
  drupal_set_message('this is already in the included file....');
  drupal_set_message('isset($account): <pre>'.var_export(isset($account), TRUE).'</pre>');
  drupal_set_message('isset($order): <pre>'.var_export(isset($order), TRUE).'</pre>');
  drupal_set_message('isset($order->products): <pre>'.var_export(isset($order->products), TRUE).'</pre>');
}

```

and after the include you can do

```
 test_purchase($account, $order);

```

This is the general approach in PHP. Use functions instead of including files and running code

---
Tags: ubercart
---


# Question
Title: URL aliases problem when assigning aliases for custom pages
I have created some content type page around 10 pages after that I started creating custom page like **page-node-11.tpl.php**. I want to assign node number 11 to my newly created page but when a assign node/11 it will give me error msg

The path `node/11` is either invalid or you do not have access to it

How to overcome this error ?

# Answer
You are doing it in reverse order. This order is generally followed. Create a page. Note down the node number (ex : 7) Then create a file corresponding to that like page-node-7.tpl.php You should not assign node/11 as alias as these are considered as internal paths. You can give anyother name which mostly suits the page contents.
> 1 votes

---
Tags: path-aliases, 7
---


title: Drag and drop content on user side

text:
# Question
Title: Drag and drop content on user side
I am developing a Drupal 6 site in which I need to allow user to drag and drop blocks of content, but the arrangement of the content for each particular user should be persistent whenever they visit the site. I have completed the drag and drop functionality but after each refresh the content reverts to its original layout.

Here is the example site: http://portal.opera.com/

How can I make the results of D&D functions persistent?

# Answer
Save the arrangement of blocks using some client side storage (e.g. cookies) when it is changed. After the page is loaded, use JavaScript to recreate the arrangement from the stored information.
> 0 votes

---
Tags: nodes, 6
---


# Question
Title: Build a sub theme under acquia Marina in drupal
I used the Acquia Marina theme to built a new sub theme. i had downloaded the fusion theme and Skinr module. now how can i proceed for the next step ? Is there any good tutorial site to help in this issues. I am using now drupal 7.

# Answer
> 1 votes
What do you want to accomplish? Once you decide what changes you want to make to the base theme use Inspect Element in Chrome or Firebug in Firefox to look at how whatever you want to change is styled.

If you have Cache CSS turned off you can usually see the exact file and line number of the CSS file you want to change. From there its just a matter of creating or editing the CSS in the subtheme so it contains the changes you want to make.

Acquia Marina is a subtheme of Fusion, so you should look for help theming Fusion. See Fusion handbook - for Acquia Marina 3.x.

---
Tags: theming
---


# Question
Title: Ask users what menu they want while drupal is being installed
I am working on installation profile. I wanted to give user choice to choose what menu items he wants like home, about us and another. Is this possible ?

# Answer
> 1 votes
Yes it's possible, using `hook_install_tasks()`.

You can use this hook to create a form that is displayed to your users during the installation process; it can be a standard Drupal form and you can add as many items of content/menu links as you want in the submission function.

Bear in mind the hook and forms your implement will need to go in the .profile file, not the .install file, or they won't work.

---
Tags: 7
---


# Question
Title: Jquery popup stops the ajax in the form fields
I have created a .js script that creates a popup box next when a button is clicked. This pop shows a lost of the different content types you can add from that popup. When you click on one of those links it will load the form elements through AJAX. That is all working great but there is a major problem.

The AJAX fields within the form that is loaded onto the the popup does not work itself, I can enter in some text but no AJAX is performed. The field type of the that field is an entity reference field.

Can anyone help me on this one please? Thank you in advance!

# Answer
> 1 votes
I solved the problem by loading the #content-inner div instead of for example the #example-content-type-node-form div. This seemed to allow me to use the ajax and easily theme the popup. Here is the line of code below within the AJAX function:

$('.popup-wrap .popup-form').html($(data).after('#content-inner'));

# Answer
> 1 votes
Maybe not the answer you're looking for, but things would probably work if you load the form page within a iframe. I've used this approach successfully with forms that have AJAX fields. In D7 the admin overlay is also built using iframes.

---
Tags: 7, ajax, javascript
---


# Question
Title: Write a boolean function in template that determines if the logged user is either the node author or admin
How do I write a function to determine if the user is either the node author or admin?

```
if ( logged user is author || admin ) {
  // …
}

```

It is for the node template.

# Answer
> 5 votes
Put this to template.php file of your theme:

```
function YOUR_THEME_NAME_preprocess_node(&$variables) {
  global $user;

  if(in_array('administrator', $user->roles) || $variables['node']->uid == $user->uid) {
    $variables['is_admin_or_author'] = TRUE;
  }
  else {
    $variables['is_admin_or_author'] = FALSE;
  }
}

```

then in your node.tpl.php or node--your-content-type.tpl.php you'll have a variable $is\_admin\_or\_author with either TRUE or FALSE value.

# Answer
> 5 votes
Instead of checking if the user is the author or admin, it is recommended to check for permissions to perform a certain action. That will make your system more flexible and you're fully taking advantage of the permission system already built into Drupal.

For instance, if you want to show/hide something depending on the permission to edit the current node, you can use this (assuming you're working with node.tpl.php):

```
function YOUR_THEME_NAME_preprocess_node(&$variables) {
  if (node_access('update', $variables['node'])) {
    $variables['permission_to_edit'] = TRUE;
  }
  else {
    $variables['permission_to_edit'] = FALSE;
  }
}

```

Now you can use the following in your node.tpl.php:

```
if ($permission_to_edit) {
  print "You may edit this node!";
}

```

# Answer
> 1 votes
```
global $user;

if ($node->uid == $user->uid || $user->uid == 1) {
  return TRUE;
}
else {
  return FALSE;
}

```

You can also check for user roles by adding `in_array('administrator', array_values($user->roles))` to the if statement if you had a seperate role (webmaster for example).

---
Tags: 7, users
---


# Question
Title: drupal 7 restful server VS seperate Restful server to access mysql. Can a restful server be on a subdomain
I am trying to figure out which would be easier to setup and maintain, while keeping the speed average or better.

I have setup a Drupal 7 site on godaddy with their Deluxe 4GH hosting plan. What I am trying to figure out now, would it be easier to setup and maintain a resful server in drupal 7 or setup a seperate restful server. I would also like to know if I can run the seperate restful server on a subdomain. Right now I have the restful server enabled in drugal (nothing setup tho), and I now cannot get past the firewall of the company I work for.

# Answer
It really depends on what part of your Drupal site your REST service will be an interface to. The Services module provide a great and easy solution to expose parts of of Drupal core and some selected contribs data and feature as REST services. IT also provide a framework to build your own services.

By-passing Drupal in a separated service directly accessing the MySQL DB is only an option if you are accessing custom tables. Accessing nodes (ie. content) directly in the MySQL database is a bad idea. The DB schema to store the nodes is dynamically managed by Drupal (the Field API). It could change whenever you add, remove or edit fields or when updating Drupal. But the Field API is not the only one to manage node data, any module can contribute data to a loaded node or add behaviours on node CRUD operations. If you go directly to the database you loose all these added behaviours. The same is true for most data handled by Drupal.
> 3 votes

# Answer
If you set up the server on a separate site as Drupal is concerned (subdomain pointing to a new site) then you will have to deal with accessing data from a different site which would probably be best done with Domain module. The all seems like a lot of overkill. Depending on the types of data you want to expose Services may do everything out of the box and it integrates with Drupal's permission and role system in addition to many modules exposing their data through it.

With services you can setup "endpoints" which have paths associated with them so you can do something like example.com/api/node ... etc. And you can alias build in resources so you can hide things like "node" and replace it with "content" or whatever makes sense in your situation.

Services is also able to version your RESTful API easy through Services tools (historical) so you can have api/1.0/custom, api/1.1/custom if you decide to provide custom resources. Versioning your API is a must if you want to ensure end-users are not interrupted by changes you may make. Services tools makes the process easy which you may end up having to do on your own if you build something from scratch. The services historical is being added to core services as well.
> 1 votes

# Answer
I think it is better build your restful api in rails or nodejs in custom table and export the table in drupal by entity api or views api.
> 0 votes

---
Tags: 8
---


# Question
Title: Views will not use pathauto URL Alias when listing programatically saved nodes
I am programatically saving nodes, and everything is working fine. Pathauto is working correctly as well and generating aliases based on my url alias configurations.

However, when Views creates a list of the new nodes, it uses node/xx instead of the existing url alias. Anyone know why this could be happening? All caches have been cleared, cron ran, etc. Here is the code

```
$node = new stdClass();
    //set other defaults
    node_object_prepare($node);

    $node->type = $page_data['content_type'];
    $node->body[LANGUAGE_NONE][0]['value'] = $page_data['description'];
    $node->body[LANGUAGE_NONE][0]['summary'] = text_summary($page_data['description']);
    $node->body[LANGUAGE_NONE][0]['format']  = 'filtered_html';
    $node->title = $page_data['title'];
    $node->field_product_price[LANGUAGE_NONE][0]['value'] = $page_data['price'];
    $node->field_item_location[LANGUAGE_NONE][0]['postal_code'] = $page_data['zipcode'];
    $node->uid = "1";
    $node->status = 1;
    $node->active = 1;
    $node->pathauto_perform_alias = TRUE;

$node->field_product_images[LANGUAGE_NONE] = $images;
unset($images);

$node->field_baby_clothes_category[LANGUAGE_NONE][0]['tid'] = $page_data['category'];

if($node = node_submit($node)) { // Prepare node for saving
    node_save($node);
}

```

note - when I add the same information through the content type form everthing works fine. It's almost as if my code is missing something that helps connect it to views.

# Answer
> 0 votes
Ah, I found it. you need $node-\>language = LANGUAGE\_NONE;

without it, Drupal does not have a language to assign it too. If you have local enabled, then $node-\>language has to equal 'en' or whatever your langauge is you're creating a link for.

# Answer
> 0 votes
Views doesn't see the alias. When Drupal receives an alias URL, the first thing it does is change the URL to the default. Views does not come into the process until after the URL is changed, so it does not know about the alias.

---
Tags: 7, views, path-aliases
---


title: Trouble making dynamics links

text:
# Question
Title: Trouble making dynamics links
I have two dynamic links that I want to put in a block, e.g. http://example.com/series/bomberman-jetters/node/add/gallery/82 ("series" is the content type, and "bomberman jetters" is the node title), http://example.com/series/bomberman-jetters/node/add/reivew/82 ("82" is the node ID).

I want to change the URL depending on what node is being viewed. Like if it's viewing node 99 then the links in the block should be changed to http://example.com/series/bomberman-jetters/node/add/gallery/99.

So what I did is insert `<?php
print "Add album";
?>` but it doesn't work in Drupal 7. The link is correct but it doesn't lead you to creating the node.

# Answer
> 0 votes
Your link code worked for me when I tried it on a random page so it's hard to tell what could be wrong from the information you provided. Generally a better way for creating links in code would be the l function:

```
<?php print l(t('Add album'), 'node/add/review/' . arg(1)); ?>

```

Drupal will handle the use of admin overlay automatically if it's enabled. Another thing I noticed is that adding `arg(1)` for `nid` at the end of node creation pages serves no purpose generally. If it's used by a module or custom code for something then it's a different story though.

---
Tags: views, routes, blocks
---


# Question
Title: how to create separate contextual filters for pages in views
I have created a view and it has a block and two pages say page1 and page2. If I set the contextual filter it applies for both page1 and page2. I have configured two contextual filters and I want first contextual filter to be applied for page1 and other for page2. Is it possible to do so? If not is there any alternative where I can have separate contextual filters for separate pages.

While filtering a views page it should evaluate only one contextual filter. Is it possible to do that?

# Answer
> 1 votes
After setting everything the way you want it on the first page, switch to the other display and change those settings, but for each one make sure you have the `This page (override)` drop-down selected.

---
Tags: 7, views
---


title: Display custom comment field in admin

text:
# Question
Title: Display custom comment field in admin
I created some custom fields for the comment form for specific content types.

One field for instance is the email fields, it's used to contact posts after they won a contest.

But when I look at the comments in the admin, there is no option to view these custom fields. Is there a way to change this?

So I want to add custom fields to the admin overlay for comments

# Answer
I think you could create a view for that, and select which fields to show.
> 1 votes

---
Tags: 7, entities, comments
---


# Question
Title: Cloning a live/production site to a test/development version
I am administering a drupal 6 high traffic, high user base website and I would like to have it cloned into a development version in order to test modules before deploying on live.

I am unable to find anything related to this, no matter how hard I try.

What are the implications of cloning a live site into a test version on another server?

What aspects should I have in mind when doing this? e.g. avoid user notifications via email from test server

Thanks!

# Answer
For most of our D6 and D7 sites we use drush to clone and sync staging and development environment from the production server.

* Basic setup of the test/staging environment should be done using drush make or cloned from your version control.
* Then you can sync the data using drush sql-sync \[paramenters\] \[source\] \[destination\] and user generated content using drush rsync \[source\] \[destination\].
* Depending on your setup it might be advisable to run a script that truncates your user table or similar.

Both drush and drush make is easily installed using Homebrew or similar.

From now on you can easily resync your database using sql-sync as often as needed.
> 4 votes

---
Tags: migrations
---


# Question
Title: How can I increase memory_limit for batch processes only?
I have a batch process that occasionally exceeds the memory\_limit, which is currently 96M. Of course I know the ways to increase the memory limit for the whole site, but I prefer to increase the memory limit for batch pages only.

One way I could think of, is to implement hook\_init in a custom module and do `ini_set('memory_limit', '200M');` whenever `arg(0) == 'batch'`, but I'm not sure if that is the best solution.

What do you recommend? I guess I could do it in .htaccess, but regex isn't exactly my forte...

\[update\] Meanwhile, more searching tells me (Stack Overflow, Webmasterworld) that it is not possible to add a conditional php\_value directive to .htaccess.

# Answer
I think that @kantu's answer is the proper thing to do, but I am going to offer up an alternate solution that is a little hackish.

If you don't want to do a module, then you could add the setting to `settings.php` wrapped in a conditional. Just note that this is included really early in the bootstrap process, so you don't have access to the vast majority of the API.

You could try adding

```
if (strpos($_SERVER["REQUEST_URI"], "/batch") === 0) {
  ini_set('memory_limit', '200M');
}

```

to the file.

I would also double check the PHP doc about `memory_limit` (or post a question on one of the sister sites). I believe that PHP doesn't allocate this during startup; it is just a safety limit to prevent imploding your server. I am pretty sure you can just bump up this limit globally.

If you are worried about Apache hanging on to this memory, then you can play with the `MaxMemFree` setting for Apache. A while ago, I did a site that would need huge amounts of memory very infrequently. Tweaking this parameter, along with a `MaxRequestsPerChild`, kept my server running happily.
> 7 votes

# Answer
I had similar requirement , but for admin/build/modules pages as it consumed more memory

```
function memory_setup_init() {
 //Check for pages goes here
  if (...) {
    ini_set('memory_limit', $memory_limit .'M');
  }
}

```

My modules pages required 150MB sometimes as it was heavily loaded. I suggest this approach as you can set up a form and you will have ability to turn it on/off or increase on the fly.Hope this gives you some idea to continue.
> 6 votes

---
Tags: .htaccess, batch-operations
---


title: Hide profile picture

text:
# Question
Title: Hide profile picture
This is the profile page http://www.lusciousanime.com/users/ruriko You notice there 2 duplicate profile pictures. I am using panels to layout the profile page. On the left column it uses Author Pane and the right column it uses User Profile token. I am also using Profile2 module. I want to remove the picture in the right column. How can I do this?

# Answer
If you're comfortable with the views module, I would recommend adding a view that displays the user profile the way you want it and using that as the right part of the panel. In the view, just add the fields you want displayed-- if you don't want the user profile picture, simply don't add it.
> 1 votes

---
Tags: views, panels, users
---


# Question
Title: Dynamic Form Elements state with multiple conditions
Can someone please help me figure this one out. I have a form element that is dependent on certain values from another select. It is only visible if certain values are selected. I know i can do multiple conditions using different form elements. However, how can i specify the same form element having multiple values. Right now this only works for the last value.

```
$form['listing_attributes']['sort_by'] = array(
'#type' => 'select',
'#title' => t("Sort By"),
'#description' => t('How you would like the listing to be sorted by.'),
'#options' => array(
    'alphabetical' => t('Alphabetical'),
    'program_type' => t('Program Type'),
    'level' => t('Degree Level'),
    'subject' => t('Subject'),
    'category' => t('Category'),
),
'#states' => array(
  'visible' => array(
    ':input[name="listing_page"]' => array('value' => 'school_page'),
    ),
),
);

$form['listing_attributes']['group_by'] = array(
'#type' => 'select',
'#title' => t("Group By"),
'#description' => t('How you would like the sorted list to be grouped by.'),
'#options' => array(
    'program_type' => t('Program Type'),
    'level' => t('Degree Level'),
    'subject' => t('Subject'),
    'category' => t('Category'),
),
'#states' => array(
  'visible' => array(
    ':input[name="sort_by"]' => array('value' => 'level'),
    ':input[name="sort_by"]' => array('value' => 'category'),
    ':input[name="sort_by"]' => array('value' => 'subject'),
    ),
),
);

```

# Answer
> 3 votes
I found a way to use the "!" in order to specify what element i do not want it to show up for. Its certainly an option and i can definitely use it. Just thought you

```
'#states' => array(
  'visible' => array(
    ':input[name="sort_by"]' => array('!value' => 'alphabetical'),
    ),
),

```

# Answer
> 2 votes
ORs are not supported at the moment, I think its something in the pipeline but may not be included in Drupal 7.

However there is a workaround available, it's a bit hacky but will get you the desired effect.

---
Tags: javascript
---


# Question
Title: Make page accessible to logged in users only
I need to make a basic page available to logged in users only and also need to retrieve information based on their login. I installed the Content Access module but it is not granular enough for me. Where would I modify the page that non-logged in users see?

Also, is there a way to store additional information in the user account such as an ID to our third-party database that we use to store user information? I will be retrieving this information to show in my first sentence above.

# Answer
If it's a specific page on your system, create a `page-----.tpl.php` for it and put in there something like:

```
<?php if ($logged_in): ?>
  // do whatever you want for logged in users
<?php else: ?>
  // do whatever you want for anonymous users
<?php endif; ?>

```

If you are using Drupal 6, the http://drupal.org/project/content\_profile module allows for all sorts of additional profile content fields. In Drupal 7 I am assuming you'd use `profile2` but I am only now learning about D7 (mostly from answering D7 questions with D6 answers ;)
> 1 votes

# Answer
It should be pretty simple to setup permission to allow only users with the authenticated user role access to the node.
> 0 votes

# Answer
If it is granular permissions you need, I usually turn to Taxonomy Access Control (TAC) module. You can restrict which roles can view which nodes *based on what terms are assigned to the node*.
That is the most granular solution I've found.

Without extra modules you can restrict roles based on content type by setting the view permission to nodes of certain content type appropriately for each role.
> 0 votes

---
Tags: users
---


# Question
Title: Suppress certain content types from taxonomy term list display (D6)
I'm trying to suppress certain content types (blogs) from displaying in the taxonomy term list. (taxonomy/term/\*)

I realize that a specific content type can be turned off for a vocabulary but we have hundreds of nodes that have tags defined.

# Answer
use a view for taxonomy/term/\* (it is created by default, you just need to enable it) and set a filter for it to exclude the blog\_post node types
> 2 votes

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


# Question
Title: Set data value of entity reference field with rules
Is there a way that you can "Set data value" of an entity reference field using rules. So I would like to set a newly created node's entity reference field to another node's entity reference field.

Thank you in advance!

# Answer
If you can't work out how to do it with Rules, maybe try a custom module. It's been suggested to me that you could use `hook_node_update()`, or `hook_node_insert()` to populate that field.

Check http://drupal.org/node/1388924.
> 2 votes

# Answer
Using entity references in rules & More rule Links this might be of some help....
> 1 votes

---
Tags: rules
---


# Question
Title: autocomplete field show name pass uid to form
In my module I'd like to allow admin/moderator to add some user specific settings e.g. user steve1 has to work between 8am and 3pm.

To make work easier for the admin I'd lke to use autocomplete field for choosing user.

Suggestions are made via user name, but to form, I need to pass uid instead of a name.

Is this possible via modyfinig my autocomplete code, or should I change provided name to uid during form\_submit operation?

```
$matches = array();
$query = db_select('users', 'u');

$return = $query
  ->fields('u', array(
    'uid',
    'name'
  ))
  ->condition('u.name', '%' . db_like($string) . '%', 'LIKE')
  ->range(0, 10)
  ->execute();

foreach ($return as $row) {
$matches[$row->name] = check_plain($row->name);
}

// return for JS
drupal_json_output($matches);

```

# Answer
In your foreach you can add it

```
foreach ($return as $row) {
   $matches[$row->name . '[uid:' . $row->uid . ']'] = check_plain($row->name);
}

```

And in your submit handler you can find it with a simple `preg_match` like this one :

```
preg_match('/\[uid:(\d+)\]/', $form_state['values']['user_autocomplete'], $matches);
$uid = $matches[1];

```

Note that the $matches variable are not the same from the auto-complete part and the submit handler part.
> 1 votes

# Answer
http://drupal.org/node/1044286#comment-4062056 \- that's much more complicated but also more flexible solution for passing more values with an autocomplete field.
> 0 votes

---
Tags: 7, database, ajax
---


# Question
Title: how to modify the confirmation email in Ubercart?
I'm trying to modify the format and text of the confirmation email in Ubercart and I don't know from where....can anyone give me hint? for example including some images or custom links in some parts of the email, quit the horrible yellow background of the site name , etc, etc... I'm using Drupal 6

Here's what I'm receiving at the moment...

# Answer
You'll want to override the file 'uc\_order-customer.tpl.php' found in the ubercart module. The way you do this is:

You need to copy **two** files from sites/all/modules/ubercart/uc\_order/templates The files to copy are **uc\_order.tpl.php** and **uc\_order-customer.tpl.php**

Then just edit uc\_order-customer.tpl.php to your liking.
> 8 votes

# Answer
Additionally if you want to build multiple templates you can copy the uc\_order.tpl.php to your theme's templates directory and create a new template called something like uc\_order-customer2.tpl.php where customer2 can be any name you choose.

Then implement a hook to identify the new templates:

```
function hook_uc_invoice_templates() {
  return array('customer2');
}

```

Make sure the 'customer2' is the same as that part of the template file name.

This way you can make unlimited e-mail templates and keep the original customer template intact.

Also note that you can choose the template you want sent in the conditional actions predicate.
> 0 votes

---
Tags: emails, theming, ubercart
---


title: Dropdown Menu Dummy Link

text:
# Question
Title: Dropdown Menu Dummy Link
One of my menu items I have, I want to make it so that only the child links are clickable, and the parent is not. Is there a way to make the parent a sort of "Dummy Link" just to set a hierarchy for a menu?

# Answer
> 7 votes
The Special Menu Items module will do exactly that for you:

> Special menu items is a Drupal module that provides placeholder and separator menu items.
>
> A placeholder is a menu item which is not a link. It is useful with dynamic drop down menus where we want to have a parent menu item which is not linking to a page but just acting as a parent grouping some menu items below it.

# Answer
> 1 votes
If you don't want to use another module:

In your custom module you could implement hook\_menu\_alter() (Or if you created the menu using hook\_menu(), you could use this same approach there). You could probably make the parent item a MENU\_CALLBACK that does nothing e.g. it could `return TRUE` or something like that.

# Answer
> 1 votes
http://drupal.org/project/menu\_firstchild Also provides similar functionality with the exception that the main link s given the link of the first child so that you preserve usability.

---
Tags: 7, routes, navigation
---


title: Generating a taxonomy

text:
# Question
Title: Generating a taxonomy
I have a list of items that I need turned into a taxonomy. My list looks something like this:

```
Apple
    Apple 1a
    Apple 1b
    Apple 2a
    Apple 2b
    ...
    Apple 192b
Banana
    Banana 1a
    Banana 1b
    Banana 2a
    Banana 2b
    ...
    Banana 96a
....
More Items
    More Items 1a
    ....
    More Items 300b

```

Anyway you get the idea. Creating new terms for each of these isn't going to work in this case , it'll take days. Is there any way to bulk create from a text file like this?

# Answer
If you can get your terms into CSV format you can use the excellent Taxonomy CSV import/export module:

> This module allows you to import or export taxonomy from or to a CSV (comma-separated values) file or with a copy-and-paste text.

It has support for importing hierarchical trees like yours, and even supports drush.

It also has good documentation to get you started.

**EDIT**

You could also try the Taxonomy import/export via XML module which does the same thing but for XML (if you find it easier to get your data into that format). It's only in dev release at the moment but its worth a try.
> 1 votes

# Answer
Alternatively you can use the Feeds module as it allow syou to both upload a file and create taxonomy terms based on the input. It is a little more configurable and as a result powerful but might be a little more difficult to setup.

If CSV gets the job done easily for you go with it otherwise i KNOW feeds can intelligently do what you need. Espercially if you combine it with feeds\_tamper and a custom parser form contrib.
> 1 votes

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


# Question
Title: Is there a module similar to the Tiered Taxonomy Block module for Drupal 7?
I have two taxonomies (*tags*, and *group*), and one content type (*article*). I want to show tags which have content in page of group/123.

I found Tiered Taxonomy Block which has similar functionality, but it is only for Drupal 6, at the moment.

What is a similar module for Drupal 7?

# Answer
> 0 votes
Not sure if there is a better solution but this can now be done in a round about way with views.

* Create a term view.
* Add a required relationship to its parent term.
* add a required relationship to node.
* add term title for both term and parent term relationship and term count.

You'll have to display the hierarchy at the theme level unless you want to use group headers.

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


# Question
Title: How do modules come up with their green, yellow, and red releases?
As we all know, not every module marked "Recommended Release" on drupal.org is truly stable. In fact some modules are perpetually marked beta, in some sort of permanent limbo state. Even when hundreds of sites use them every day.

I was wondering what kind of standards or best practices do you use, as a maintainer or contributor, in your modules to mark releases 'Recommended' (Green), 'Other' (Yellow), or 'Dev'(Red)? What do you use when marking it beta, alpha, or stable as well?

Thank you in advance for any advice, help, or documentation you can provide.

NOTE: Many of these standards may be general standards for coding or project development. I simply wanted to know what methods or standards are used in Drupal modules specifically, even if they are / can be generalized.

# Answer
> 7 votes
> Many of these standards may be general standards for coding or project development.

In Drupal there is no standard for this. It is left to the best intentions of the module owners.

My personal philosophy is:

* Release beta and/or releasecandidate if tested in a testing environment, or if all testcases pass.
* Release stable only if I, myself, have successfully implemented the (version of the) module in at least three different real-world projects; or if someone whom I know has my standards, did that and reports back.
* A module *can* be *finished*. It needs no additional work ever anymore. Something that is limited and scoped in featureset, is stable and predictable. Such modules need no bugfixes, feature-requests or tasks.

In practice, this means very few releases, yet the releases done will affect hardly anyone. That results in hardly ever releasing anything in practice.

My reasoning behind this is:

* People in issue-queues hardly test appropriately: they apply a feature, fix or patch, hit f5, see it working and say "yes, works for me +1". *"It seems to work"* is not equal to *"it is fixed"*. You need trustworthy testing, or else the rest, those who did not even test the change, will flock in with issues reporting something COMPELETELY BORKEND, need fix NOW!!.
* Only when a module is implemented in different situations and environments will it have some real-world experience. Most often, during the second implementation you find that you need to rewrite some central api's, forgot some usefull parameter, or simply had a wrong idea about the need for some feature. Only after real-world deployment can something be considered stable. Else it is only stable in theory.
* Developers and maintainers of sites, the users of your modules, need to put a huge effort (far more then in any other piece of software I know) in keeping up with new releases, security releases and new versions. any relief for that effort (and budget and time) should be more then welcome.

# Answer
> 2 votes
If there is a module that you use where you found bugs the best thing you can do is file an issue. Even better is if someone writes a patch for that issue, the patch can be written by a developer that needs the feature or it can be written by a developer who got sponsored to write that patch. Contrib maintainers usually maintain a lot of modules and when you create a module you automatically become the maintainer, needless to say that puts a lot of strain into us, so we alway need help by people who write patches, sponsor patches or review them.

When you maintain releases in drupal.org you have a 'Supported' checkbox, enabling that will give you a recommended release (green) and if you also enable the 'Show snapshot release' you will get a dev release (red). If you have more then one major versions of your module (6.1 & 6.2) you can choose which one will be in the the recommended release section (green). Only betas and regular releases will go into the 'recommended' section (green) alphas and lower releases will be displayed in the 'other releases' section (yellow).

# Answer
> 0 votes
Regarding betas, rcs and dev, it depends on the popularity and niche your module fills imo.

If earl rolled out an official version of views that had a data loss issue the internet as a whole might cease to function.

However, if you have a small module that is relatively unpopular (\>1,000 users) and youre just just going through routine bugfixes it is more reasonable to just make new releases and not beta/rc them.

if you know youve made some big chnages or seen alot of churn then test more thouroughly.

I tend to test and roll betas/rc when i am altering the DB or issuing update() hooks because i realize the permanence of data loss. I can reroll and rerelease a small bug fix fast right the world but i can recreate your sites data.

Hope that helps.

---
Tags: community-official-site
---


title: How does upgrade checking work?

text:
# Question
Title: How does upgrade checking work?
I am new to Drupal. I first created my site in Drupal 7, but I had to use Drupal 6 because a lot of the modules I use were not ready yet. Now I'm noticing more and more modules are having development releases for Drupal 7.

If I install a development release, will the upgrade manager notify me of updates once it's listed as the main module or will I need to switch to the main module to keep getting the notification?

# Answer
If you install an official dev version (not a git checkout, but downloaded from the website), it has a date information. If there is a newer stable or dev version, you will be informed.

However, development releases are exactly that. Some work, some work well and others might not work at all.
> 4 votes

# Answer
FWIW Git deploy helps here. Here is a quote about it (from the module's project page):

> Normally drupal.org inserts version information when a project is packaged. Git repositories do not contain this information. Git Deploy hooks into the Drupal update system and attempts to provide the version of modules and themes checked out of git.
> 1 votes

---
Tags: upgrading
---


# Question
Title: Is it better to hard code everything or use the ui?
Is it better to hard code everything or to use the ui? For example, is it better to field and entity with the UI or to add fields/instances programmatically? Does it really matter? What is the 'best practice'?

# Answer
> 1 votes
If you use code you can:

* Version control the field settings.
* Lock the field, so it can't be deleted or altered in the UI.

It's always a good idea to keep as much as possible in code, for when you need to roll out changes etc. This is why i prefer the above method, even though it is more time consuming during development. Depending on your use case, you may save a lot of time doing this however.

# Answer
> 1 votes
The two don't have to be pulling in different directions imho. It's possible (where the modules support it) to use the UI to make the changes, and export to code. For me this is the ideal to aim for. Features is a great step in that direction, but not the only example.

# Answer
> 0 votes
I agree with Andy, using the UI for creating your content types and fields and then exporting that in code with the Features module is the way to go. Features has its own quirks you need to get used to, but IMO it beats the headaches of having to write and maintain your code for doing what you can do with a few clicks in the UI.

---
Tags: 7
---


# Question
Title: Remembering the address of the calling page of a form (Drupal 7)
I have created a little module that implements hook\_menu and when the menu item is selected it displays a form that is defined as so:

```
function documentation_menu_nameform() {

  $form['documentation'] = array(
    '#type' => 'text_format',
    '#title' => t('Documentation'),
    '#default_value' => 'This project has not been documented.',
    '#format' => NULL,
    '#weight' => 0,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit')
  );
  return $form;
}

```

Now when this menu item is selected it brings up a form at the address ?q=documentation\_menu and in my form submission hook I would like to return to the page the user was on before they selected the menu item but I can't figure out how to access and/or store this path.

# Answer
> 1 votes
I would do this like so:

Have your menu item URL generated with destination parameter, for example:

/?q=documentation\_menu&destination=some/path/where/user/had/just/been

add a hidden field to your form and populate it with destination path

```
$form['destination'] = array(
  '#type' => 'hidden',
  '#value' => drupal_get_destination()
);

```

if you for some reasons can't add destination parameter to that URL, then you'll need to extract that URL from $\_SERVER\['HTTP\_REFERRER'\] and populate hidden field with it.

Then in your submit function just do a redirect to the path specified in that hidden field:

```
function documentation_menu_nameform_submit() {
  ...

  drupal_goto($_POST['destination']);
}

```

---
Tags: 7, forms
---


# Question
Title: Getting taxonomy name from entity for computed fields
Im trying to create a computed value field using the the computed\_field module. I trying to do something like http://drupal.org/node/792922 but that example is for drupal 6. Can someone point me in the right direction of how to do this with drupal 7?

# Answer
> 2 votes
If you have taxonomy id, I'd suggest to do this:

```
$term = taxonomy_load_term($tid);
$node->your_field_name[your_language_specifier][your_value_index]['value'] = $term->name;

```

if you don't have taxonomy term id you can get it like so:

```
 $field_name = 'term'; //or what ever your field is named
 $entity_id = 4;//or what ever your entity id is
 $query = db_select("field_data_field_" . $field_name, $field_name);
 $query->addField($field_name, "field_" . $field_name . "_tid", "tid");
 $query->condition("entity_id", $entity_id, "=");
 $result = $query->execute()->fetchAssoc();
 $tid = $result['tid'];

```

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


# Question
Title: Storing the value of a form submission in a hidden field or the database
So I have created a form for user's to store some documentation about a node they have created but I do not want this documentation to be shown on the node's main page. I would like the main page to have a link to either view or edit the form.

Now as far as I can tell there is no way to create a field that doesn't show up directly on the node create or viewing pages (this seems like it would be a misuse of a field anyway). Is there anyway that I could store what the user enters in this documentation form as part of the content without it being displayed on the node page or would I have to create a database table that associates a nid with the documentation string? Also, my form allows for use of filtered html in the form, will this be preserved if I store the filtered html as a string in the database?

# Answer
> 1 votes
if you want a field not to show up on the node page you can either

1. hide it in display options: Structure -\> Manage display (in front of the corresponding content type) -\> Format -\> Hidden
2. Hide it in the template file by calling

```
hide($content['YOUR FIELD NAME']);

```

The first option makes more sense in my opinion.

---
Tags: 7, database
---


# Question
Title: multisite: only changing name of the website
I have a multisite up and running, which has completely different domain names but absolutely the same content (I'm using filters to filter the content by domain).

Everything works splendid with almost no redundancy. However, the only thing keeping me from rejoicing, is that I cannot change the name of the website domain-wise.

So basically, my question is where I can set this up, or rather: Is there a way to override the page's name on drupal load? And if there's not, can anyone tell me which table the site's name is getting stored, so I can domain-prefix it?

# Answer
Do you have a settings.php file per site ?

If yes, you can add inside `$conf['site_title'] = 'My Site name'` this variable his stocked in the table `variable`but you can override it directly with settings.php.
> 2 votes

---
Tags: 7, multi-sites
---


# Question
Title: Change AJAX processing icon and progress bar in Drupal7 using CSS
Can I change the throbber/ajax loading icon and progress bar in Drupal 7 by adding new pictures and overriding CSS system files?

# Answer
You can do it by overriding the CSS in your theme CSS file. Here is the rule that you've to override

```
.ajax-progress .throbber {
  background: transparent url(../../misc/throbber.gif) no-repeat 0px -18px;
  float: left; /* LTR */
  height: 15px;
  margin: 2px;
  width: 15px;
}

```

You can just change the `background` and you will be able to change the processing icon.

Here is the another one that you should override

```
html.js input.form-autocomplete {
  background-image: url(../../misc/throbber.gif);
  background-position: 100% 2px; /* LTR */
  background-repeat: no-repeat;
}

```
> 13 votes

---
Tags: theming
---


# Question
Title: l() is not being called correctly in menu.inc
I had been getting this error message:

> PHP Fatal error: Unsupported operand types in /var/www/www.ruv.is/pressflow/includes/common.inc on line 1588

So I did a backtrace and this is what it returned:

```
    array (
      'file' => 'pressflow/includes/menu.inc',
      'line' => 1614,
      'function' => 'l',
    )

```

It points to this function:

```
/**
 * Get the breadcrumb for the current page, as determined by the active trail.
 */
function menu_get_active_breadcrumb() {
  $breadcrumb = array();

  // No breadcrumb for the front page.
  if (drupal_is_front_page()) {
    return $breadcrumb;
  }

  $item = menu_get_item();
  if ($item && $item['access']) {
    $active_trail = menu_get_active_trail();

    foreach ($active_trail as $parent) {
      $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']);  // line 1614
    }
    $end = end($active_trail);

    // Don't show a link to the current page in the breadcrumb trail.
    if ($item['href'] == $end['href'] || ($item['type'] == MENU_DEFAULT_LOCAL_TASK && $end['href'] != '<front>')) {
      array_pop($breadcrumb);
    }
  }
  return $breadcrumb;
}

```

Or more specifically, this line:

```
$breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']);

```

I'm assuming there is a contributed module that is causing this, but it is happening on several pages that don't use any menu altering module. Do you have any idea on how to troubleshoot this?

I can't reproduce this myself, so my only chance of debugging is on a hight traffic live site.

# Answer
> 3 votes
According to my experience, this happens when the third argument passes to `l()` is not an array and you are using PHP 5.3. See http://api.drupal.org/api/drupal/includes%21common.inc/function/l/6 as to how the third parameter `$options` is being used.

Then it is time dwelve into what is causing your `$parent['localized_options']` not to be an array.

---
Tags: 6, routes, breadcrumbs, debugging
---


# Question
Title: Storage of the images in Commons 6.25: serious troubles acompanied with CHMOD & CHOWN-issues
Where do the image files reside? I have problems with the files, and the permissions. On my site, which runs Drupal-Commons, I cannot upload any image, either to a user or a group.

I was not able to fix it. First of all, regarding the user, my server works with the SETGID-bit enabled, and with the user vhost:vhost.
The bad is that every time I touch the chmod, I lose the setgit-bit; I tried changing it to 2777, and then all gets lost. I lose the style too.

What can I do? Can I upload the images manually, and store them into /home/vhost/WWW/schulcenter.org/sites/default/files?

# Answer
setuid and setgid are for *execution* and not access control.

I can't comment on your exact problem, but when I move a site, I do

```
sudo find /path/to/site/default/files -type d -exec chmod 755 {} \;
sudo find /path/to/site/default/files -type f -exec chmod 644 {} \;
sudo find /path/to/private -type d -exec chmod 755 {} \;
sudo find /path/to/private -type f -exec chmod 644 {} \;
sudo chown -R apache.apache /path/to/docroot/site/default/files
sudo chown -R apache.apache /path/to/private

```

By default, files are in `site/default/files` but this location can vary for a few reasons

* Admin setting for public files
* Admin setting for private files
* Whether the files use public or private
* Whether you use the default location, or a site alias

and probably some others I can't think of. I suspect that your write errors will show up in your Apache `error_log` and you should also see what the status report (`admin/reports/status`) says.

Note that the private paths/settings are for Drupal 7 only, but the rest applies.
> 2 votes

---
Tags: media
---


title: Commerce First Data Module

text:
# Question
Title: Commerce First Data Module
I am working with Drupal Commerce to create an e-Commerce store. However, I am having some trouble with my client's gateway of choice, First Data.

I have everything set up as directed (I believe) but when I try to submit an order the page times out and I am given this error message. (This happens if I am testing a transaction live, test authorized, or test denied)

```
PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away:

INSERT INTO {watchdog} (uid, type, message, variables, severity, link, location,
referer, hostname, timestamp) VALUES (:db_insert_placeholder_0,
:db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3,
:db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6,
:db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9);
Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => php
[:db_insert_placeholder_2] => %type: !message in %function (line %line of %file).
[:db_insert_placeholder_3] => a:6
{s:5:"%type";s:6:"Notice";s:8:"!message";s:27:"Undefined index:
order_num";s:9:"%function";s:33:"firstdata_cc_submit_form_submit()";s:5:"%file";s
87:"/home/betads/public_html/sites/all/modules/commerce_firstdata/commerce_firstd
ta.module";s:5:"%line";i:380;s:14:"severity_level";i:5;}
[:db_insert_placeholder_4] => 5 [:db_insert_placeholder_5] =>
[:db_insert_placeholder_6] => https://beta.designsenseinc.net/checkout/7/review
[:db_insert_placeholder_7] => https://beta.designsenseinc.net/checkout/7/review
[:db_insert_placeholder_8] => 166.147.79.6 [:db_insert_placeholder_9] =>
1330630525 ) in dblog_watchdog() (line 157 of
/home/betads/public_html/modules/dblog/dblog.module).

```

Any idea what could be the issue? To test for yourself, you can visit http://beta.designsenseinc.net/product/853 and add the product to cart.

Any help appreciated.

# Answer
Solved. It was an issue with my server's firewall. First data traffic needs to route out through port 1129. Just needed to open the port on my firewall.
> 0 votes

# Answer
watchdog is trying to save an error log and database fails (probably too many error logs ?). you might try to select showing errors on screen or sending them to syslog - you would probably get rid of the rying database and could diagnose the original problem :).

the original error seems to be undefined index on line 380 of commerce\_firstd ta.module
> 1 votes

---
Tags: 7, commerce, payment-gateways
---


title: Drupal 7 how many blocks in region?

text:
# Question
Title: Drupal 7 how many blocks in region?
I need to know how many blocks in the region! is there any short way to do that ? if more than one block in the region than I want to add custom class to region.

# Answer
I think your best bet would be to use `hook_preprocess_region()` in a module or theme:

```
function MYTHEME_preprocess_region(&$vars) {
  // Make sure it's the right region
  if ($vars['region'] == 'sidebar_first') {
    // Get the count of blocks
    $count = count(element_children($vars['elements']));

    // Add the class if necessary
    if ($count > 1) {
      $vars['classes_array'][] = 'some-class';
    }
  }
}

```
> 4 votes

---
Tags: 7, theming
---


title: Batch Enable alt text for image fields

text:
# Question
Title: Batch Enable alt text for image fields
I'm updating a site in which I need to ensure that the alt (and possibly title) attribute are enabled for any field of time file (widget image).

There are tonnes of content types and I don't want to have to go through every field in every content type to check and enable it each.

I've had a search for modules but have been unsuccessful in my search. Is there a way I can enable them in as a bulk operation in the database?

I've looked but couldn't find exactly where the setting for each field was

For example, the table `content_type_source_homepage` has the following fields

```
field_shp_image_fid     int(11)                         Yes NULL
field_shp_image_list    tinyint(4)                      Yes NULL
field_shp_image_data    text        utf8_general_ci     Yes NULL

```

These obviously store a reference to the image but does not indicate whether or not the user is allowed to edit the alt attribute for that image, and what the default alt attribute might be.

Furthermore, fields which allow multiple images have a separate table such as `content_field_title_image` which again has similar fields without indication as to whether or not the alt attribute is editable.

# Answer
> 1 votes
Each content type will have a form associated with the content type. Using hook\_form\_alter, you can change these items and set them in batch.

Here is a great video that teaches how to do what you are asking, but using the author check box. Using a technique like this you could set everything to 'on' (1).

http://mustardseedmedia.com/podcast/episode53

How many is 'Tonnes' - do you have 50 content types or 500? Remember you would have to write custom code to do this, so you would need to be familiar with PHP and how modules are written. If that is not your forte and there is not a module, it may be best just to dedicate a few hours and a beer to it :)

---
Tags: 6, media
---


# Question
Title: How to display 9 products WITH images on one page
I've managed to add products and even create a "Store" node that gives me a dropdown of my CDs. BUT, I have yet to figure out how to display all 9 products on that "store" node or, at the very least, have each product show a thumbnail image so that it's not just a plain dropdown menu.

In addition, I followed another tutorial that instructed me to create add content using the "Display" content type I created but this still only shows one product. {http://drupal.stackexchange.com/questions/1849/how-do-i-display-my-products

Please help.

…Drupal Newbie…

# Answer
A Node is not a "Store", it's a Product display, meaning that it displays a group of Products that belong together (like t-shirts in different colors/sizes).

To have 9 separate products displayed on a page, you create 9 nodes and assign a product to each of them. Then you can for example build a view that lists them on a single page.
> 1 votes

# Answer
Use the Views module to create a view that displays 9 nodes of type Product. If you search for Views tutorials you should fine tons of examples. The series from nodeOne is probably the best

http://dev.nodeone.se/node/781
> 1 votes

---
Tags: commerce
---


title: get taxonomy term count by vid

text:
# Question
Title: get taxonomy term count by vid
I have this code which gives me the number of terms on a node

```
 $count = count($node->taxonomy)

```

Is there a way i can restrict this to VID. i only want to get the count for a specific vocabulary.

Oh yeah the site is in D5

here is a link to the page http://national.thedelimagazine.com/8947/delis-austin-issue-2012-pdf-version-available

# Answer
> 2 votes
I don't have a D5 system handy, but this would do it in D6:

```
$count=0;
foreach ($node->taxonomy as $t) {
  if ($t->vid==VID_IN_QUESTION) {
    $count++;
  }
}

```

and it "should" be the same in D5, but I've said that a lot about D7 and D6 :) If not,

```
drupal_set_message('<pre>' . print_r($node->taxonomy,true) . '</pre>');

```

should give you the object information you need to modify above to count. If that doesn't work,

```
$foo=taxonomy_node_get_terms_by_vocabulary($nid, $vid);
$count=count($foo);

```

certainly is a roundabout way of getting them if you already have the node loaded.

---
Tags: taxonomy-terms
---


title: Show breadcrumb on forum only

text:
# Question
Title: Show breadcrumb on forum only
I want to show the breadcrumb on the forum only. I am using the advanced forum module. How can I do this in Drupal 7?

# Answer
I recommend you try the Disable Breadcrumbs module.

> Disable breadcrumbs on a per node, per content type, or by path (any path) basis; Omitting the need to write additional code in the theme layer (template.php file etc..) to determine the visibilty of breadcrumbs on specific pages. This can be administered on node edit forms and from the content administration page (node operations) to select/unselect multiple nodes for enabled types.
> 2 votes

# Answer
This page on Drupal.org provides info on customizing the breadcrumbs. I'm sure you could do it with a module, but I think it's probably easier just to look at the examples referenced here and modify your theme template files.
> 0 votes

---
Tags: breadcrumbs
---


title: What controls render order?

text:
# Question
Title: What controls render order?
I have a loop populating multiple render arrays, and my output is not appearing as expected.

```
      $count = 0;
      foreach ($result as $row) {
      //do stuff

      if ($is_a_link_list) {
         //do more stuff

        $id = 'link_list_a' . $count;
        $content[$id] = array(
         //render array - link list
        );

      } else {

        $id = 'promo_list_a' . $count;
        $content[$id] = array(
            //render array - title
        );
        $id = 'promo_list_b' . $count;
        $content[$id] = array(
            //render array - body
        );

      }
      $count++;
    }

```

So in a given result set I'd expect:

```
---promo list title
   promo list body

---link list
   =item1
   =item2
   =item3

(more results)

```

What I'm getting:

```
---promo list title
   promo list body

---link list
   =item1
   =item2
   =item3

   promo list body
---promo list title

---promo list title

---link list
   =item1
   =item2
   =item3

   promo list body

---link list
   =item1
   =item2
   =item3

```

So does the key of the render array matter? (Other than needing to be unique)

Looking at the markup output it's apparent that I need to render my render arrays as list items; I think this means a nested render array?

HTML source:

# Answer
> 6 votes
The order of the output for a render array is determined by the `#weight` attributes of it's contents. To reorder elements in a render array, set the `#weight` attribute of the target elements, using smaller values for elements that should appear earlier. Then set the `#sorted` attribute of the parent element to `FALSE`, this will make Drupal resort the elements of the render array before generating the output HTML. You can see an example of the technique in the Render Example module included in the Drupal Examples module. The relevant code is

```
$page['sidebar_first'] = array_reverse($page['sidebar_first']);
foreach (element_children($page['sidebar_first']) as $element) {
  // Reverse the weights if they exist.
  if (!empty($page['sidebar_first'][$element]['#weight'])) {
    $page['sidebar_first'][$element]['#weight'] *= -1;
  }
}
$page['sidebar_first']['#sorted'] = FALSE;

```

Now when Drupal goes to render the content, it will first be sorted according to `#weight`. Also note that elements which do not specify a `#weight` attribute are assigned a weight of 0 during sorting, so they will appear in the output in the order in which they are defined in the render array.

---
Tags: theming
---


title: SQL Query generated by Drupal Views 3

text:
# Question
Title: SQL Query generated by Drupal Views 3
I have created a view in Drupal 7 using views 3 and it is throwing some sql error in preview and the error message is not complete showing here. How can I check this sql complete error message? Is there any option to see SQL generated by view so that I can test the same on mysql client?

Thanks in advance for your help. Umar

# Answer
Your recent log messages should show the complete error (if you click on the message link).

You can find recent log messages at http://YOURSITE.com/admin/reports/dblog, or by clicking -\> Administration -\> Reports -\> Recent log messages
> 0 votes

---
Tags: views
---